You are here:
Create the MediaAdSalesCustomRadioHandler Apex Class
The MediaAdSalesCustomRadioHandler Apex class fetches the units for a particular quote line item, and assigns custom properties, such as info, stausCode, and customClass, to the line item, according to the convertSplitsToRecords method in the Apex class.
Required Editions
This is an Advertising Sales Management on Managed Package feature. For Advertising Sales
Management on Salesforce Platform, see Advertising
Sales Management on Salesforce Platform.
| Available in: All Editions |
| User Permissions Needed | |
|---|---|
| To edit profiles: | Manage Profiles and Permission Sets |
- From the Developer Console, create the MediaAdSalesCustomRadioHandler Apex class.Here's sample Apex class content. In this example, we use the custom classes spot-calendar-red and spot-calendar-blue.
public class MediaAdSalesCustomRadioHandlerDoc { global class MediaAdSalesCustomRadioHandler implements vlocity_cmt.VlocityOpenInterface, Callable { private String KEY_AD_QUOTE_ID = 'AdQuoteId'; public Boolean call(String action, Map<String, Object> args) { Map<String, Object> input = (Map<String, Object>) args.get('input'); Map<String, Object> output = (Map<String, Object>) args.get('output'); Map<String, Object> options = (Map<String, Object>) args.get('options'); return invokeMethod(action, input, output, options); } public Boolean invokeMethod(String methodName, Map<String, Object> input, Map<String, Object> output, Map<String, Object> options) { switch on methodName { when 'checkAvailability' { output.putAll(checkAvailability(input)); return true; } } return false; } private List<Object> convertSplitsToRecords(List<SObject> splits) { List<Object> records = new List<Object>(); List<String> fields = new List<String>{ 'Id', 'Name', 'SplitQuantity', 'StartDate', 'EndDate', 'AdQuoteLineId' }; for (SObject split: splits) { Map<String, Object> record = new Map<String, Object>(); for (String field: fields) { record.put(field, split.get(field)); } Integer randomNum = Integer.valueOf(Math.random() * 10); if(randomNum !=8){ record.put('info', 'Some Info Message for ' + ((String) record.get('AdQuoteLineId'))); if (randomNum < 2) { record.put('statusCode', 'Available'); } else if (randomNum < 3) { record.put('statusCode', 'Not Available'); } else if (randomNum < 5) { record.put('statusCode', 'Partially Available'); } else if (randomNum < 7) { record.put('customClass', 'spot-calendar-red'); } else { record.put('customClass', 'spot-calendar-blue'); } } records.add(record); } return records; } public Map<String, Object> checkAvailability(Map<String, Object> input) { String adQuoteId = (String) input.get(KEY_AD_QUOTE_ID); List<SObject> splits = [ SELECT Id, Name, SplitQuantity, StartDate, EndDate, AdQuoteLineId FROM AdQuoteLineUnitsSplit WHERE AdQuoteLine.AdQuoteId = :adQuoteId ]; Map<String, Object> result = new Map<String, Object>(); result.put('response', convertSplitsToRecords(splits)); return result; } } } - Save your changes.
Did this article solve your issue?
Let us know so we can improve!
