Skip to content

Instantly share code, notes, and snippets.

@forcethesales
Created August 4, 2021 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forcethesales/175a73a51d2559290e78c49bbf11f17b to your computer and use it in GitHub Desktop.
Save forcethesales/175a73a51d2559290e78c49bbf11f17b to your computer and use it in GitHub Desktop.
This invocable method gets one contact id from the Flow and returns all associated Opps as a collection variable
public class contactsListAction {
//this invocable method takes a single contact from Flow from a text variable
//and returns a list of lists of opportunities associated with that contact.
//the list of lists is stored as a collection variable in the Flow.
@InvocableMethod (label = 'SendContactsGet Opps' description = 'returns opps for this contact.')
//the method will return a List of Lists of Opportunities, and receive a List of Salesforce ids
public static List<List<Opportunity>> getContactIds (List<ID> ids) {
//declare a new list of Opps
List <Opportunity> oppIds = new List <Opportunity> ();
//declare a new list of lists of opps
List<List<Opportunity>> itemListList = new List<List<Opportunity>>();
//look up the opportunities
List<Opportunity> opps = [SELECT id,CloseDate,Amount
FROM Opportunity
WHERE npsp__Primary_Contact__c in :ids AND StageName = 'Closed Won'
AND CloseDate = THIS_YEAR];
//add each opp to the List
for (Opportunity opp : opps){
oppIds.add(opp);
}
//add the list to the list of lists
itemListList.add(oppIds);
// send list of lists to the Flow
return itemListList;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment