Skip to content

Instantly share code, notes, and snippets.

@furkankaracan
Created January 3, 2023 12:44
Embed
What would you like to do?
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