3

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?

Developer Guide - InvocableVariable Annotation

3
  • did anyone figure out if there is a way to do this, I'm having the same issue.
    – user26043
    Nov 2, 2015 at 20:57
  • Can you specify exactly how and when do you need your code to be invoked? For e.g. is it required on some DML operation or some scheduled time interval?
    – Anshul
    Nov 2, 2015 at 22:47
  • @Anshul yes it needs to be invoked on Update when certain Opportunity fields are changed
    – Alex S
    Nov 4, 2015 at 9:49

2 Answers 2

1

U can use visual flow to call it. Try to invoke a flow from button and the flow in turn calls the apex.

http://lc169.blogspot.in/2013/08/calling-apex-class-from-visual-flow.html

HTH Prabhan

1
  • Thanks but I'm looking to invoke the Apex without any manual user intervention. I was hoping to find a way to invoke it whenever particular fields were changed by the user.
    – Alex S
    May 17, 2015 at 22:36
0

@Alex: As I understand, you want to invoke a piece of functionality (apex code) when certain fields on Opportunity are updated. If this is correct, then you can use Apex Triggers to achieve the same.

An Apex Triggers is apex code, which is invoked by Force.com whenever any DML operation is being performed on an entity (insert, delete, update etc.). Refer https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_trigger.htm for more information

1
  • Thanks Anshul but when I first asked the question, I wasn't able to write Triggers which is why I mention looking for a way to invoke the Class without using code in the question. That's no longer an issue for me but I'm looking for a point & click solution here, for the benefit of other users like Anna, who I assume, has the same need.
    – Alex S
    Nov 4, 2015 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .