public async Task <IList <SFComment> > GetCaseComments(string caseId) { IList <SFComment> sfCaseComments = new List <SFComment>(); SFPerson creator = new SFPerson { Id = "1", Name = "Alex Smith" }; sfCaseComments.Add(new SFComment() { ID = "2", CommentBody = "I don't know, but one of them Includes Negative Interest and the other one doesn't.", Creator = creator, DtCreated = "2019-01-01" }); sfCaseComments.Add(new SFComment() { ID = "3", CommentBody = "Currently there is a filter by region but would also like to have a filter by PCA. I would like it in all of the tabs for transfers to be sent and instructions sent awaiting transfer. thanks", Creator = creator, DtCreated = "2019-01-01" }); return(await ConnectionHelper.FormTask(sfCaseComments)); }
public async Task <IList <SFComment> > GetCaseComments(string caseId) { IAsyncEnumerable <SfCaseComment> result; string qry = @"Select Id, ParentId, IsPublished, CommentBody, CreatedBy.Id, CreatedBy.Name, CreatedDate FROM CaseComment WHERE ParentId = '" + caseId + "'"; IList <SFComment> sfCaseComments = new List <SFComment>(); try { var client = await(SFConnector.Instance as SFConnector).GetClient(); result = client.QueryAsync <SfCaseComment>(qry); //CaseComments using (IAsyncEnumerator <SfCaseComment> contactsEnumerator = result.GetEnumerator()) { // MoveNext() will execute the query and get the first batch of results. // Once the inital result batch has been exhausted, the remaining batches, if any, will be retrieved. while (await contactsEnumerator.MoveNext()) { SfCaseComment comment = contactsEnumerator.Current; SFPerson creator = new SFPerson { Id = comment.CreatedBy?.Id, Name = comment.CreatedBy?.Name }; sfCaseComments.Add(new SFComment() { ID = comment.Id, CommentBody = comment.CommentBody, Creator = creator, DtCreated = comment.CreatedDate.ToString() }); } } //Status Changes qry = @"Select Id, CreatedBy.Id, CreatedBy.Name, CreatedDate, OldValue, NewValue, Field FROM CaseHistory WHERE Field = 'Status' and CaseId = '" + caseId + "'"; IAsyncEnumerable <SfCaseHistory> result2; result2 = _client.QueryAsync <SfCaseHistory>(qry); using (IAsyncEnumerator <SfCaseHistory> contactsEnumerator = result2.GetEnumerator()) { while (await contactsEnumerator.MoveNext()) { SfCaseHistory statusChange = contactsEnumerator.Current; SFPerson creator = new SFPerson { Id = statusChange.CreatedBy?.Id, Name = statusChange.CreatedBy?.Name }; var text = $"Status Change from {statusChange.OldValue} to {statusChange.NewValue}."; sfCaseComments.Add(new SFComment() { ID = statusChange.Id, CommentBody = text, Creator = creator, DtCreated = statusChange.CreatedDate.ToString() }); } } //Emails IAsyncEnumerable <SfEmailMessage> result3; qry = @"SELECT CreatedBy.Id, CreatedBy.FirstName, CreatedBy.LastName, FromName,Id,ParentId,Status,Subject,TextBody, ToAddress FROM EmailMessage where ParentId = '" + caseId + "'"; result3 = _client.QueryAsync <SfEmailMessage>(qry); using (IAsyncEnumerator <SfEmailMessage> contactsEnumerator = result3.GetEnumerator()) { while (await contactsEnumerator.MoveNext()) { SfEmailMessage email = contactsEnumerator.Current; SFPerson creator = new SFPerson { Id = email.CreatedById, Name = email.CreatedBy.Name }; var text = $"From:{email.FromName} To: {email.ToAddress} Subject: {email.Subject}. Body: {email.TextBody}."; sfCaseComments.Add(new SFComment() { ID = email.Id, CommentBody = text, Creator = creator, DtCreated = email.CreatedDate.ToString() }); } } } catch (Exception) { throw; } return(sfCaseComments); }