AgileApps Support Wiki Pre Release

SearchContext Class

From AgileApps Support Wiki

This class is designed for large, complex queries. Using it, you can formulate a search query one part at a time, and have each part validated independently, rather than putting the entire query in one long string and having it validated all at once.

Creating a SearchContext Object

Use the setters and getters in the SearchContext class to set up the query. (The syntax for each part is identical to that used with the REST APIs to create a Dynamic Search. The only difference is that you don't have to concatenate them all into a single string.)

Using the SearchContext Object

These APIs take a SearchContext object:

  • Functions.searchRecords(SearchContext searchContext)
  • Functions.searchGlobalPicklists(SearchContext searchContext)
  • Functions.searchPackages(SearchContext searchContext)
  • Functions.searchSocialFeeds(SearchContext searchContext)
  • Functions.searchSocialGroups(SearchContext searchContext)

Learn more: Uses recorded in the Javadocs

Example

SearchContext searchContext = new SearchContext();

searchContext.setFieldList("*"); 
searchContext.setObjectId("");    // For a record search: objectName or ID
searchContext.setPage(0);
searchContext.setPageSize(5000);
searchContext.setFilter("title contains 'Order' ");  // Criteria
searchContext.setSortBy("date_created");
searchContext.setSortBy2("title");
searchContext.setSortOrder("DESC");
searchContext.setSortOrder2("ASC");

List<GlobalPicklistBean> results;
results = Functions.searchGlobalPicklists(searchContext);