I'm looking for a way to fire an Apex Class without using code or a button click. My Apex Class does not have an invocable method so I can't fire it using the standard Process Builder. But I do have a button set up which fires the class at the moment, with the following code:
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
if ( '{!Opportunity.Record_Type_Name__c}' == 'CP_Disbursement' ) {
var result = sforce.apex.execute(
"CP_MonthlyRevenueForecastDisbursement",
"createMonthlyForecastRecordsDisbursement",
{opportunityId:'{!Opportunity.Id}'}
);
if ( result == 'Success' ) {
window.location.href=window.location.href;
} else {
alert(result);
}
} else {
var result = sforce.apex.execute(
"CP_MonthlyRevenueForecastController",
"createMonthlyForecastRecords",
{opportunityId:'{!Opportunity.Id}'}
);
if ( result == 'Success' ) {
window.location.href=window.location.href;
} else {
alert(result);
}
}
Is it possible to imitate a button click using a workflow rule or the process builder? Is there another way to invoke the Apex Class without code?
Or, as a last resort, is the process of making the method invocable as simple as adding @InvocableMethod(label='xyz')
to the code - as long as the method already complies with the rules listed in the developer guide?