-
-
Save furkankaracan/dd3f35964657514f8f2301d63ad6b28e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static List<Entity> GetAccounts() | |
{ | |
string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'> | |
<entity name='account'> | |
<attribute name='accountnumber' /> | |
<attribute name='accountid' /> | |
<attribute name='modifiedon' /> | |
<order attribute='modifiedon' descending='true' /> | |
<order attribute='name' descending='false' /> | |
</entity> | |
</fetch>"; | |
return orgService.RetrieveAll(new FetchExpression(fetchXml)); | |
} | |
public static List<Entity> RetrieveAll(this IOrganizationService service, FetchExpression query) | |
{ | |
var conversionRequest = new FetchXmlToQueryExpressionRequest | |
{ | |
FetchXml = query.Query | |
}; | |
var conversionResponse = | |
(FetchXmlToQueryExpressionResponse)service.Execute(conversionRequest); | |
return RetrieveAll(service, conversionResponse.Query); | |
} | |
public static List<Entity> RetrieveAll(this IOrganizationService service, QueryExpression query) | |
{ | |
var result = new List<Entity>(); | |
var entities = service.RetrieveMultiple(query); | |
result.AddRange(entities.Entities); | |
var page = 2; | |
while (entities.MoreRecords) | |
{ | |
query.PageInfo = new PagingInfo | |
{ | |
PagingCookie = entities.PagingCookie, | |
PageNumber = page | |
}; | |
entities = service.RetrieveMultiple(query); | |
result.AddRange(entities.Entities); | |
page++; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment