How do I evaluate DSP expressions from Apex?

You can compile and evaluate DSP expressions directly in Apex:

  • Compile a single expression:

pushtopics.Expression expr = pushtopics.Expression.compile('TO_UPPER_CASE(LastName)'); Object value = expr.evaluate(myContact); // Example: returns 'SMITH' if myContact.LastName = 'Smith'
  • Compile a list of expressions:

pushtopics.Expression[] exprs = pushtopics.Expression.compile( new String[]{ 'TO_UPPER_CASE(LastName)', 'IS_BLANK(Email)' } );
  • Handle bulkification (for expressions with VLOOKUP or AGG functions):

pushtopics.Expression.setContextRecords(externalObjectList); pushtopics.Expression expr = pushtopics.Expression.compile( 'VLOOKUP("Account", "Parent.Type", "AccountExternalID__c", AccountExternalID__c)' ); Object value = expr.evaluate(myExternalObject); pushtopics.Expression.clearContextRecords();

Use setContextRecords and clearContextRecords when evaluating bulk expressions to ensure query optimization and bulkified execution.