Skip to content

Conversation

@fehays
Copy link
Contributor

@fehays fehays commented May 4, 2020

Reference:
TYPEOF SOQL Reference

Polymorphic Relationships (TYPEOF)

String query = new Q(Event.SObjectType)
    .selectFields(Q.typeOf('What')
        .when('Account').then(new Set<String> {'Phone', 'NumberOfEmployees'})   
        .when('Opportunity').then(new Set<String> {'Amount', 'CloseDate'})                 
        .otherwise(new Set<String> {'Name', 'Email'})
    );
    
System.debug(query.build());
/*
SELECT
    TYPEOF What
    WHEN Account THEN Phone,NumberOfEmployees
    WHEN Opportunity THEN Amount,CloseDate
    ELSE Name,Email
    END
FROM Event
*/

@fehays fehays marked this pull request as ready for review May 4, 2020 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant