You are here:
Apex Classes for Catalog Messaging Components
Use these example Apex classes to process a Meta product catalog and return catalog data to your WhatsApp messaging component.
Sample Apex Class for Multi-Product Messages
This sample Apex class returns a list of RichMessaging.CatalogSection objects for a multi-product message. For more information on how to create an Apex class, see Create an Apex Class.
public with sharing class GetCatalogSection {
@InvocableMethod
public static List<List<RichMessaging.CatalogSection>> getCatalogSection() {
String title = 'Wallpapers';
List<String> productIds = new List<String>();
productIds.add('ymrgtcg9co');
RichMessaging.CatalogSection catalogSection = new RichMessaging.CatalogSection();
catalogSection.titleValue = title;
catalogSection.productIdsValue = productIds;
List<RichMessaging.CatalogSection> x = new List<RichMessaging.CatalogSection>();
x.add(catalogSection);
List<List<RichMessaging.CatalogSection>> y = new List<List<RichMessaging.CatalogSection>>();
y.add(x);
return y;
}
}Sample Class Implementation for Single-Product and Catalog Messages
Use this sample class implementation for both single-product and catalog messages. The class implements the RichMessaging.ProcessCatalogOrderHandler interface.
global class MyProcessCatalogOrderHandler implements RichMessaging.ProcessCatalogOrderHandler {
global RichMessaging.ProcessCatalogOrderResult processCatalogOrderRequest(
RichMessaging.ProcessCatalogOrderRequest catalogOrderRequest) {
return new RichMessaging.ProcessCatalogOrderResult(
RichMessaging.ProcessCatalogOrderResultStatus.SUCCESS, null, 'order-ref-123');
}
}
