+ Start a Discussion
SFDC New learnerSFDC New learner 

How to pass current record id from process builder to apex?

Hi Everyone,

I am trying to pass the current record Id from process builder to apex and then to visual force which embeds lightning component.

public class MyInvocableVariable {
    @InvocableVariable(label='Id' required=true)
    public Id recId;

    }  

<apex:page showHeader="false" sidebar="false">
    <apex:includeLightning />
    
    <div id="lightning" />
    <script>
        $Lightning.use("c:lightningApp", function(){
            $Lightning.createComponent("c:lightningComponent",
                "recId":?, ---> need to pass the Id
                "lightning",
                function(cmp){}
            );
        }            
       );
    </script>

</apex:page>

Anyone, please help with this.

Thanks,
Sirisha
ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

I don't think you need to use @invocableVariable annotation to get the variable from the Process builder.You can simply use the @invocableMethod and pass the variable to the method directly as mentioned in the example given in the below thread:

https://salesforce.stackexchange.com/questions/245716/is-it-possible-to-pass-the-id-of-the-current-record-when-calling-apex-from-proce

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
SFDC New learnerSFDC New learner
Hi Shirisha,

Thanks for the reply, but I tried to use Invocable Method too but not able to pass URL parameter to lighting component.

<apex:page showHeader="false" sidebar="false">
    <apex:includeLightning />
    
    <div id="lightning" />
    <script>
        $Lightning.use("c:lightningApp", function(){
            $Lightning.createComponent("c:lightningComponent",
                "recId":"{!recid}", ---> need to pass the Id
                "lightning",
                function(cmp){}
            );
        }            
       );
    </script>

</apex:page>
public Id recid{get;set;}
    Public CustomObject vhid{get;set;}
    
    
    @InvocableMethod
    public static void recAssign(List<Id> recids)
    {
       CustomObject vid = [select id from CustomObject where id in:recids] ;
        getId(vid);
        
        
    } 
    
    public static Id getId(CustomObject gvv){
     CustomObject vhid = new CustomObject ();
      vhid = gvv;
      Id recid = vhid.Id;        
        return recid;
    }

getting following errorThis page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'Name' of undefined] Callback failed: apex://SignInOutForm/ACTION$checkAlreadyFilled Failing descriptor: {markup://c:lightningComponent}

Can you help me to fix the issue?

Thanks,
Sirisha