protected void CreateResearchProfileInternal(string employeeId) { if (_service == null) { throw new Exception("Service is null. You need to login first!"); } if (string.IsNullOrEmpty(employeeId)) { throw new Exception("Invalid argument!"); } Salesforce.User user = GetUser(employeeId); Salesforce.Research_Profile__c profile = new Salesforce.Research_Profile__c { Name = user.FirstName + " " + user.LastName + " Research Profile", OwnerId = _userId, User__c = user.Id }; Salesforce.SaveResult[] results = _service.create(new Salesforce.sObject[] { profile }); foreach (Salesforce.SaveResult result in results) { if (!result.success) { throw new Exception("Cannot create ResearchProfile for employee id=" + employeeId + ", with error:\n" + result.errors.Select(it => it.statusCode + ":" + it.message).Aggregate((s1, s2) => s1 + "\n" + s2)); } } }
public void CreateProfileActivity(string employeeId, string url, string code, string message, DateTime timestamp) { if (string.IsNullOrEmpty(message)) { throw new Exception("Invalid argument!"); } Salesforce.Research_Profile__c profile = GetOrCreateResearchProfile(employeeId); DateTime utc = timestamp.ToUniversalTime(); String apex = "FeedItem post = new FeedItem(); \n" + " post.Type = " + (url != null ? "'LinkPost'; \n post.LinkUrl = '" + EncodeString(url) + "'" : "'TextPost'") + "; \n" + " post.ParentId = '" + profile.Id + "'; \n" + " post.Title = '" + EncodeString(code) + "'; \n" + " post.Body = '" + EncodeString(message) + "'; \n" + " post.CreatedById = '" + profile.Owner.Id + "'; \n" + " post.CreatedDate = Datetime.newInstanceGmt(" + utc.Year + "," + utc.Month + "," + utc.Day + "," + utc.Hour + "," + utc.Minute + "," + utc.Second + "); \n" + " insert post;"; ExecuteApex(apex); }