0

I have a function that does API callouts. It takes a string as a parameter, which is the record ID.

I need a way to make an InvocableMethod so I can call that method with the current record ID from the page. This InvocableMethod is going to go into a flow where this method will be called.

For example:

@InvocableMethod
public static void endOpportunity(){
    //Need a way to get current record ID here
    methodCall(recordID);
}

So basically what this does is a user clicks an action on the opportunity which ends the opportunity status through a flow. In order for the methodCall to work it needs the record ID of the page the action was clicked on. From here it does an API callout and ends the opportunity on our website as well. However I can not seem to find a valid way to pull in the record ID simply. Any help would be appreciated.

0

Your @InvocableMethod should take a List parameter as shown below. Then, you need pass a list of ID's from your process to the @InvocableMethod.

@InvocableMethod
public static void endOpportunity(List<Id> oppids){
    //Need a way to get current record ID here
    system.debug(oppids); // you 'll get list with 1 Item of record id
    methodCall(recordID);
}
  • I guess what I don't understand is the list part. Users are only going to click the button and end One opportunity. So why would I pass a list of Ids down when I only need the one single Id? – chaseter15 Dec 19 '19 at 18:03
  • Apex @InvocalbleMethods had some considerations you have to follow them, i would recommend to go through developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… – sdandamud1 Dec 19 '19 at 18:06
  • Okay So I made the list<Id> oppIds and then added the apex action to my flow. It had a set input variable section, so I set it to a recordId variable I already had created. So now what I am getting from this is in the method if I set recordId = oppIds[0]; it should be the record Id and the method should work correct? – chaseter15 Dec 19 '19 at 18:24
  • exactly, you are in track – sdandamud1 Dec 19 '19 at 18:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.