1

I have an Apex class containing an Invocable Method and no Invocable Variables that does not show up in Process Builder but does show up as an Action in Flow Builder. Normally this wouldn't be a problem, but my code is using a generic sObject collection and Flow Builder requires you to choose a specific object for the variable assignment, so using a Flow here is not an option.

The class itself has passed all tests with 97% code coverage and I've already tried the "Compile All Classes" button as well. It's using API version 48.0 and is already deployed to production after development in a sandbox.

I'm a bit at a loss on how to figure out the issue here and can't find any relevant bug reports. I've also already seen the two most relevant questions on here to this issue and nothing suggested in either has worked for me (Apex class is not visible in Process builder and Apex InvocableMethod not showing up in Flow).

Here is the relevant code snippet:

public class RegionCheck {
    private static Map<String, List<String>> regionMap;

    public static Map<String, List<String>> getRegionMap() {
        return regionMap;
    }

    @InvocableMethod(label='Update Region')
    public static void initializeObjects(List<SObject> objsToUpdate) {
        String billingstring = 'BillingCountry, BillingCountryCode, BillingStateCode';
        String mailingstring = 'MailingCountry, MailingCountryCode, MailingStateCode';
        String addressstring = 'Country, CountryCode, StateCode';

        Map<Schema.SObjectType, String> querymap = new Map<Schema.SObjectType, String>{Account.getSObjectType() => billingstring, Contact.getSObjectType() => mailingstring, Lead.getSObjectType() => addressstring};

        List<SObject> nonReadOnlyObjs = new List<SObject>();

        for (SObject o : objsToUpdate) {
            Schema.SObjectType type = o.getSObjectType();
            Id objId = o.Id;

            SObject nonReadOnlyObj = Database.query(
                'SELECT ' + querymap.get(type) + ', Region__c ' +
                'FROM ' + type + ' ' +
                'WHERE Id = :objId');

            nonReadOnlyObjs.add(nonReadOnlyObj);
        }

        // call function using writeable list that does the region checking
        updateRegion(nonReadOnlyObjs, querymap);
    }

    // more code follows after this, omitted for brevity and relevance...
}

I'm beginning to suspect this is an issue with the fact that I am trying to use the generic sObject class for the collection, but the Spring '20 release notes say that this is now possible.

Edit: Here is a link to the relevant section of the Spring '20 release notes as requested.

  • Can you please add link to release notes to this section here? – Mariia Illarionova Mar 17 at 8:10
  • I assume, you know that you can pass only ids of objects and there will be almost no difference for your code, except of Schema.SObjectType type = objId.getSObjectType(); system.debug(type); – Mariia Illarionova Mar 17 at 8:19
  • 1
    I have added the link to the section in the release notes. – James Mar 17 at 18:54

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.