Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ranveer5289/d0346574fe272ac1956355d2947885fe to your computer and use it in GitHub Desktop.
Save ranveer5289/d0346574fe272ac1956355d2947885fe to your computer and use it in GitHub Desktop.
Commerce_Endpoint_Search_ProductSearch
public with sharing class CommerceEndpointSearchProductSearch extends ConnectApi.BaseEndpointExtension {
public override ConnectApi.EndpointExtensionRequest beforePost(ConnectApi.EndpointExtensionRequest request) {
System.debug('We are in the beforePost entry method of Commerce_Endpoint_Search_ProductSearch extension');
return request;
}
public override ConnectApi.EndpointExtensionResponse afterPost(ConnectApi.EndpointExtensionResponse response, ConnectApi.EndpointExtensionRequest request) {
System.debug('We are in the afterPost entry method of Commerce_Endpoint_Search_ProductSearch extension');
System.debug('response.getResponseObject()-----' + response.getResponseObject());
ConnectApi.ProductSearchResults results = (ConnectApi.ProductSearchResults)response.getResponseObject();
List<ConnectApi.SearchFacet> originalFacets = (List<ConnectApi.SearchFacet>)results.facets;
for (ConnectApi.SearchFacet facet : originalFacets) {
String id = facet.nameOrId;
System.debug('nameOrId----' + id);
if (id == 'OrderSeasonYear__c') { // just an example
ConnectApi.DistinctValueSearchFacet myFacet = (ConnectApi.DistinctValueSearchFacet)facet;
List<ConnectApi.DistinctFacetValue> faceValues = myFacet.values;
// apply custom sorting on cloned facet values and set it back again. How to sort ConnectAPI results?
// myFacet.values = faceValues; - throws an EXCEPTION System.UnsupportedOperationException: Output properties may only be written in objects built for tests
System.debug('facetValues----' + faceValues);
}
}
return response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment