0

I have an invocable method that works just fine when I pass a Contact record Id to it via Process Builder.

I'd like to use Flow to do this rather than PB, but get this error message:

Error Occurred: An Apex error occurred: System.NullPointerException: Argument cannot be null.

In the Flow debugger I can see this:

CODE (APEX) Generate_Code Inputs: ContactIds = {!varContact} (Contact (003m000001AWsQNAA1))

It seems like perhaps Flow is passing a variable that's formatted incorrectly to Apex (?), but I'm not sure how to get around that. The only variable type the Apex Action will accept in Flow Builder is a single Contact record variable.

What do I need to change in Flow in order to get the correct value to Apex? I'm pretty certain my code is good because it works when called from Process Builder...

Edit: Here's the code:

Public class Mcode{
    // Pass in the email address to be encrypted
    // It needs to be done in a List
    @InvocableMethod(label='Create App Code')
    public static void appCode(List<Contact> ContactIds)
    {
        List<Contact> toUpdate = new List<Contact>();
        for(Contact con : ContactIds){
            //get a 'list' of Seasonal Dates with a single value, convert that into one record, and turn Year into a string
            Seasonal_Date__mdt[] years = [SELECT Year__c FROM Seasonal_Date__mdt WHERE qualifiedApiName = 'App_Code_Year'];
            Seasonal_Date__mdt cmtYear = years.get(0);
            string year = cmtYear.Year__c;
            //create the secrete key for the year referenced in CMT
            string key = 'test-mobile-app-' + year;
            // Encrypt the email address with hmacSHA1.
            Blob encryptedData = Crypto.generateMac('hmacSHA1', Blob.valueOf(con.Email), Blob.valueOf(key));
            // Turn the encrypted data into a string and truncate to the first 8 characters
            String fullCode = EncodingUtil.convertToHex(encryptedData);
            String code = fullCode.right(8);
            // Update the Contact with a new app code and app code year
            toUpdate.add(new Contact(
                Id=con.Id,
                App_Code__c = code,
                App_Code_Year__c = year
        ));
            }    
        update toUpdate;                    
    }
}
  • 1
    The problem is in your Apex code. We really do need to see your code. It may be that your Apex isn't processing the input correctly. – sfdcfox Apr 16 at 19:33
  • @sfdcfox just added the code I'm working with. – duncanm Apr 18 at 17:43
  • @sfdcfox I see you edited the code but looks like just some formatting tweaks? Issue remains. – duncanm Apr 22 at 20:41

Your Answer

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

Browse other questions tagged or ask your own question.