Very new to the Apex developer game here and I'm having trouble figuring out how to create invocable variables that can be called from process builder.

The use case here is we are using the docusign apex toolkit and I've created a class that I would like to call from a process builder that would grab the recipient and source record ids. Below is what I have so far but I'm getting the error "InvocableVariable is not allowed on locals." I've tried restructing the code a dozen times and can't seem to figure out what I'm doing wrong. I've tried looking up a solution but I'm just not understanding what I'm supposed to do.

Any help is appreciated, Thank you!

public class ApexToolkit {
    public static void sendEnvelopeMethod(){
        // The ID of the initiating Salesforce object and recipient
        @invocablevariable  Id mySourceId;
        @invocablevariable  Id myContactId;

        // Create an empty envelope.
        dfsle.Envelope myEnvelope = dfsle.EnvelopeService.getEmptyEnvelope(
            new dfsle.Entity(mySourceId));
        //Salesforce contact record as a Recipient here
        Contact myContact = [SELECT Id, Name, Email FROM Contact where id =: myContactId];
        //use the Recipient.fromSource method to create the Recipient
        dfsle.Recipient myRecipient = dfsle.Recipient.fromSource(
            myContact.Name, // Recipient name
            myContact.Email, // Recipient email
            null, //Optional phone number
            'Signer 1', //Role Name. Specify the exact role name from template
            new dfsle.Entity(myContact.Id)); //source object for the Recipient
        //add Recipient to the Envelope
        myEnvelope = myEnvelope.withRecipients(new List<dfsle.Recipient> { myRecipient });
        //myTemplateId contains the DocuSign Id of the DocuSign Template
        dfsle.UUID myTemplateId = dfsle.UUID.parse('0afb9e85-aa02-4fc8-8ad6-ec354c27d7a9');
        //create a new document for the Envelope
        dfsle.Document myDocument = dfsle.Document.fromTemplate(
            myTemplateId, // templateId in dfsle.UUID format
            'myTemplate'); // name of the template
        //add document to the Envelope
        myEnvelope = myEnvelope.withDocuments(new List<dfsle.Document> { myDocument });
        // Send the envelope.
        myEnvelope = dfsle.EnvelopeService.sendEnvelope(
            myEnvelope, // The envelope to send
            true); // Send now?
        // Retrieve the five most recent envelope statuses from the Salesforce source object.
        // The status results are sorted oldest to newest.
        List<dfsle.Envelope.Status> myStatus = dfsle.StatusService.getStatus(
            new Set<Id> { // IDs of the Salesforce objects with associated status.
            5); // Maximum number of records to return.

If you create your own custom class(inner class) to use as the input or output to an invocable method, you can annotate individual class member variables to make them available to the method.

Refer this for more details.

  • I've looked through that documentation but I'm not familiar with using an inner class for input/output. It seems like I need one class for input, one class for results. But I'm not sure how to work that into the existing framework I have above.
    – Jas
    May 14 '21 at 16:23

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.