0

I am brand new to Apex, this is my first attempt - I adapted some code from here which is working, but ideally, I'd like to pass the urlencoded variable back to the flow, however, I can't work out how to get it to work. I know I have to change the void out so I can return a value, but changing it throws up more issues. I can see I am passing values from my FlowInputs class into my Invocable Method - do I somehow have to set a variable in that method and then create a list?

    public class FormAssemblyEncrypt {
    public class FlowInputs {
            @InvocableVariable public String urlOppId;
            @InvocableVariable public String url;
            @InvocableVariable public String key;
            @InvocableVariable public String OppId;
        }
    
        @InvocableMethod
        public static void updateOpp (List<FlowInputs> request) {
    
            String data = request[0].urlOppId.remove('=');
            String key = request[0].key;
            String url = request[0].url + request[0].urlOppId;
            String OppId = request[0].OppId;
            
            Blob mac = Crypto.generateMac('HMacSHA256', Blob.valueOf(data), Blob.valueOf(key));
            String sig = EncodingUtil.urlEncode(EncodingUtil.base64Encode(mac), 'UTF-8');
            String urlencoded = url + '&signature=' + sig;
            
            outfunds__Funding_Request__c opp = [SELECT Id, FormAssemblyURL__c from outfunds__Funding_Request__c WHERE Id = : OppId];
            opp.FormAssemblyURL__c = urlencoded;
            database.update(opp);
        } 
    
    }
1

1 Answer 1

1

Here you can find how to do it.

This is the specific code snippet.

public with sharing class GetFirstFromCollection {
  @InvocableMethod
  public static List <Results> execute (List<Requests> requestList) {
    List<SObject> inputCollection = requestList[0].inputCollection;
    SObject outputMember = inputCollection[0];

    //Create a Results object to hold the return values
    Results response = new Results();

    //Add the return values to the Results object
    response.outputMember = outputMember;

    //Wrap the Results object in a List container 
    //(an extra step added to allow this interface to also support bulkification)
    List<Results> responseWrapper= new List<Results>();
    responseWrapper.add(response);
    return responseWrapper;    
  }
}

public class Requests {
  @InvocableVariable(label='Records for Input' description='yourDescription' required=true)
  public List<SObject> inputCollection;
  }

public class Results {
  @InvocableVariable(label='Records for Output' description='yourDescription' required=true)
  public SObject outputMember;
  }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .