function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tony ParfittTony Parfitt 

Why doesn't my invocablemethod appear in Apex in Visual Workflow?

I've created an invocablemethod to perform some business logic processing and was going to use visual workflow to habdle the UI side of things as the method requires some inputs from the user. The method runs through test cases with 100% coverage and no errors, and I;ve checked using debug messaages that it is actually doing what it is supposed to do.
However, when I create a visual workflow for the UI, I don't get an "Apex" section in the pallette, nor of course the class that should appear there. Are there any gotchas that might mean my class or the section is not displaying? I have been looking high and low for the sulution on the web and several hours later am about to give up and use a VF page instead.
Lokesh KumarLokesh Kumar
Hi Tony,

could you please check you apex class format it should follow the basics. 
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_InvocableMethod.htm
and FYI Apex class being displayed in Flow like.
User-added image

Let me know if this helped you.

Thanks
Lokesh
 
Tony ParfittTony Parfitt
Thanks Lokesh, I jave been using that and other pages to try to fix this but just cant see the reason the class does not display in Flow...

global class IncrementContracts{
    global class IncrementContractsRequest{
        //Input value(s)
        @InvocableVariable(label='CPI' required=true)
        public Decimal CPI;
        @InvocableVariable(label='Division' required=true)
        global String division;
 @InvocableVariable(label='Region' required=true)
        global String region;
    }   
   
    @InvocableMethod(label='Increment Contracts' description='Increment active annually renewable contracts by input CPI or the fixed percentage in the contract')
    public static List<Boolean> incrementContracts(List<IncrementContractsRequest> requests){
       
        List<Boolean> results = new List<Boolean>();
       
        for (IncrementContractsRequest request : requests) {
     // Execute the change
     contractsHandler.processIncrements(request.division, request.region, request.CPI);
            results.add(TRUE);
        }
           
        return results;
    }
}
Lokesh KumarLokesh Kumar
Tony - Could you please try checking in Process builder see if it's possible to use in PB if Yes then it should display in Flow.
 
Tony ParfittTony Parfitt
No Apex classes avaialble there either... hmm that is suspicious, is there a setting somewhere in SF that says you can't use Apex in Flow or PB? As I know there are other packages installed that have Apex...
Lokesh KumarLokesh Kumar
HI Tony,

Please create a dummy apex class with the below code and see if this is available for use in flow or not.
 
public class AccountQueryAction {
  @InvocableMethod(label='Get Account Names' description='Returns the list of account names corresponding to the specified account IDs.')
  public static List<String> getAccountNames(List<ID> ids) {
    List<String> accountNames = new List<String>();
    List<Account> accounts = [SELECT Name FROM Account WHERE Id in :ids];
    for (Account account : accounts) {
      accountNames.add(account.Name);
    }
    return accountNames;
  }
}

Thanks
Lokesh
Tony ParfittTony Parfitt
Thanks Lokesh. Interesting... that appears. I was thinking maybe mine doesn't because I had not run a test with good coverage on my classes since recent tweaks but your class appeared with no tests at all.

I might try remaking the class, perhaps there's something up with it that I can't see. Will update this thread when I find the problem in case it helps anyone else in future... couldn't find any existing threads like this one.
Tony ParfittTony Parfitt
Just a heads up... for whatever reason copying the code from the class somewhere safe, deleting the class and recreating it, pasting the class code back in seemed to do the trick. Exactly the same code.