Created
August 4, 2021 17:00
-
-
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
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
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