You need to sign in to do that
Don't have an account?
Jemill
Trying to Make an Apex Class Invocable so it can be used in skuid or list views
public without sharing class trac_SetFieldsOnLockedOppExt { private final Opportunity lockedOpp; // The extension constructor initializes the private member // variable mysObject by using the getRecord method from the standard // controller. public trac_SetFieldsOnLockedOppExt(ApexPages.StandardController stdController) { this.lockedOpp = (Opportunity) stdController.getRecord(); if( this.lockedOpp.IsClosed ) { ApexPages.addMessage( new ApexPages.Message(ApexPages.Severity.ERROR, 'The current opportunity has been closed and cannot be modified.') ); } } public PageReference saveLockedRecord() { PageReference pr = null; if( !lockedOpp.IsClosed ) { update new Opportunity( Id = lockedOpp.Id, CloseDate = lockedOpp.CloseDate, Gate__c = lockedOpp.Gate__c, Annual_Web_SalesOpp__c = lockedOpp.Annual_Web_SalesOpp__c, Estimated_Signature_Date__c = lockedOpp.Estimated_Signature_Date__c, Stage_Qualifier__c = lockedOpp.Stage_Qualifier__c, Current_Affiliate_Annual_Sales_Revenue__c = lockedOpp.Current_Affiliate_Annual_Sales_Revenue__c, Percent_to_CJ__c = lockedOpp.Percent_to_CJ__c, Think_Big_Number__c = lockedOpp.Think_Big_Number__c ); pr = new PageReference( '/' + lockedOpp.Id ); pr.setRedirect( true ); } return pr; } }I was told I needed to make the above class invocable so that the button/visualforce/field set it is associated with can be used within Skuid, or standard salesforce list view. The class updates fields on a locked opp.
Classes cannot be made invocable, however we can make methods Invocable.
Like This: Howevere there are many considerations for Invocable methods:
Only one method in a class can have the InvocableMethod annotation.
Triggers can’t use invocable methods.
The invocable method must be static and public or global, and its class must be an outer class.
Other annotations can’t be used with the InvocableMethod annotation.
There can be at most one input parameter and its data type must be one of the following:
A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
A list of an sObject type or a list of lists of an sObject type – the generic sObject type is not supported.
A list of a user-defined type, containing variables of the supported types and with the InvocableVariableannotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation.
If the return type is not Null, the data type returned by the method must be one of the following:
A list of a primitive data type or a list of lists of a primitive data type – the generic Object type is not supported.
A list of an sObject type or a list of lists of an sObject type – the generic sObject type is not supported.
A list of a user-defined type, containing variables of the supported types and with the InvocableVariableannotation. Create a custom global or public Apex class to implement your data type, and make sure your class contains at least one member variable with the invocable variable annotation.
You can use invocable methods in packages, but once you add an invocable method you can’t remove it from later versions of the package.
An invocable method can be public in a managed package, but it won’t appear as an action in the Cloud Flow Designer’s list of available actions while building or editing a flow. These invocable actions can still be referred to by flows within the same managed package. Global invocable methods in a managed package can be used in flows outside the managed package, anywhere in the organization, and appear in the Cloud Flow Designer’s list of available actions to add to a flow.
Also, in your case, you are trying to make a controller mathod Invocable, I wonder that would work as You will not get Id of the Opportunity record in the method (No Parameter in method). You are getting the Opp Id using Page URL, however same would not be the case when you will invoke the method from somewhere else.
Hope this was Useful:)
Veenesh
How to call apex class from SKUID (http://www.salesforceadda.com/2017/08/how-to-call-apex-class-from-skuid.html)