4

I need some help.

I have created the following button Button & Code, however when i click on the button i get the following Error Message.

This is the class, which i want the button to call. Anyone have any ideas why this is not working ?

 global class initiateapproval {

  public String mysw {get; set;}

  Webservice static String initiateswapproval(String mysw) {
    //change Campaign__c to your sObject
   Campaign sw = new Campaign(Id=mysw);

//make sure you add the custom field Submitted for Approval on your object as this is what you
//will use as your approval process entry criteria.
//This is the approval process entry I used: Entry Criteria  (Campaign: Approved Date EQUALS null) AND (campaign: Submitted for Approval EQUALS TODAY)

sw.Submitted_for_Approval__c = System.Now();

update sw;


 // Create an approval request for the record

    Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();

    req1.setComments('Submitting request for approval automatically');

    req1.setObjectId(mysw);

    Approval.ProcessResult result = Approval.process(req1);

  return null;


  }
}
4
  • Does the user have access to the class? – Francis Jun 17 '14 at 14:34
  • Hi Francis, I am logged in as myself and i am a system administrator. Do i need to install any packages for ajax ? I would also like to mention that my code coverage for the class is on 0%. Unfortunately , I don’t have any tests class for the above class – user8746 Jun 17 '14 at 14:40
  • I would try just returning a string from the method with no other code and alert the response out. This will eliminate any issues with your code and check the method is being fired correctly. Dont worry about test coverage for now. – Francis Jun 17 '14 at 16:45
  • @ Francis, I'm new to this. I only put this code together from hours of researching and meddling . I have no idea what I'm doing ha. – Masond3 Jun 17 '14 at 16:50
2

Try the following.

Change the APEX version in the REQUIRESCRIPT statements to the the version of your APEX class.(14.0 to 29.0 or whatever).

Also check if you are missing a namespace prefix when invoking your class.

2
  • Oh yes blimey version 14 didnt see that. The troubles of copying code :) – Francis Jun 19 '14 at 7:41
  • Did this fix your issue? If so please mark this as the answer. – Richard N Jun 19 '14 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.