Editar

Compartilhar via


Sample: Use aggregation in FetchXML

This sample shows how to retrieve aggregate record data using FetchXML.

What this sample does

The FetchXML query is intended to be used in a scenario where it creates queries to get the data.

How this sample works

In order to simulate the scenario described in What this sample does, the sample will do the following:

Setup

  1. Checks for the current version of the org.
  2. The CreateRequiredRecords class creates 3 opportunity records and account record.

Demonstrate

  1. The estimatedvalue_avg fetches the average of estimatedvalue for all the opportunities. The EntityCollection method returns the results of the RetrieveMultiple request.
  2. The opportunity_count fetches the count of all opportunites.
  3. The estimatedvalue_max fetches the maximum estimatedvalue of all opportunites.
  4. The estimatedvalue_min fetches the minimum estimatedvalue of all opportunities.
  5. The estimatedvalue_sum fetches the sum of estimatedvalue for all opportunities.
  6. The estimatedvalue_avg2 fetches the multiple aggregate values within a single query.
  7. The groupby1 fetches a list of users with a count of all the opportunites they own using the groupby.
  8. The byyear fetches the aggregate information about all the opportunites that have been won by year.
  9. The byquarter fetches the aggregate information about the opportunities that have been won by quarter.
  10. The bymonth fetches the aggregate information about the opportunities that have been won by month.
  11. The byweek fetches the aggregate information about the opportunities that have been won by week.
  12. The byday fetches the aggregate information about the opportunities that have been won by day.
  13. The byyrqtr fetches the aggregate information about the opportunities that have been won by year and quarter.
  14. The byyrqtr2 specifies the result order.

Clean up

Displays an option to delete all the data created in the sample. The deletion is optional in case you want to examine the data created by the sample. You can manually delete the data to achieve same results.