Skip to content

Instantly share code, notes, and snippets.

@lukethacoder
Last active January 17, 2024 20:48
Show Gist options
  • Save lukethacoder/7ec68c8cae6319a84ba03aa1869f1f3b to your computer and use it in GitHub Desktop.
Save lukethacoder/7ec68c8cae6319a84ba03aa1869f1f3b to your computer and use it in GitHub Desktop.
APEX: Get a Set<Id> of Id's from a List<SObject> of Objects
// Query list of Accounts
List<Account> accounts = [
SELECT
Id, Name
FROM
Account
];
// get Set of Ids of the Object
Set<Id> ids = new Set<Id>(new Map<Id, Account>(accounts).keySet());
System.debug('Account Ids as Set<Id>: ' + ids);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment