Last active
May 23, 2018 14:23
-
-
Save pchittum/afbef488741caf3b137e229d730e805b to your computer and use it in GitHub Desktop.
SObject switch and polymorphic SObject fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<User> notifyUsers = new List<User>(); | |
List<Group> notifyGroups = new List<Group>(); | |
List<Property__c> properties = [SELECT | |
TYPEOF Owner | |
WHEN User THEN Id, Name, Username, Email | |
WHEN Group THEN Id, Name, Email, DoesSendEmailToMembers | |
END | |
FROM Property__c | |
WHERE ID in Trigger.new]; | |
for (Property__c prop: properties) { | |
switch on prop.Owner { | |
when User u { | |
notifyUsers.add(u); | |
} | |
when Group g { | |
notifyGroups.add(g); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<User> notifyUsers = new List<User>(); | |
List<Group> notifyGroups = new List<Group>(); | |
List<Property__c> properties = [SELECT | |
TYPEOF Owner | |
WHEN User THEN Id, Name, Username, Email | |
WHEN Group THEN Id, Name, Email, DoesSendEmailToMembers | |
END | |
FROM Property__c | |
WHERE ID in Trigger.new]; | |
for (Property__c prop: properties) { | |
switch on (SObject) prop.Owner { | |
when User u { | |
notifyUsers.add(u); | |
} | |
when Group g { | |
notifyGroups.add(g); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment