Skip to content

Instantly share code, notes, and snippets.

@sjurgis
Created July 15, 2022 12:10
Show Gist options
  • Save sjurgis/b926f5ce03ae118ba04b8da40193ab87 to your computer and use it in GitHub Desktop.
Save sjurgis/b926f5ce03ae118ba04b8da40193ab87 to your computer and use it in GitHub Desktop.
import getByNames from '@salesforce/apex/OpportunitiesSelector.getByNames';
export default class Operatunity extends LightningElement {
async connectedCallback() {
const [contacts, accounts, opportunities] = await getByNames({names: ['foo', 'bar', 'qux']})
}
}
public with sharing class OpportunitiesSelector {
@AuraEnabled public static Object[] getByNames(String[] names) {
Contact[] contacts = [SELECT Id FROM Contact WHERE Name = :names];
Account[] accounts = [SELECT Id FROM Account WHERE Id IN (SELECT AccountId FROM Contact WHERE Id = :contacts)];
Opportunity[] opportunities = [SELECT Id FROM Opportunity WHERE AccountId = :accounts];
return new Object[]{
contacts,
accounts,
opportunities
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment