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
Daniel MasonDaniel Mason 

Problem with onClick JavaScript For button was encountered

Hey all

I hope all is well, i really need some help wit the following below.


I have created the following button ( which sits on the campaign object)

User-added image
However when i click on the button i get the following error message

User-added image

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

i would like to point out i dont have a test class, and the code coverage is at 0%

This is the apex class which is called from the button 

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;


  }
}
This is my approval process. I know that the entry criteria is correct, however i am not sure about the approval steps

User-added image

Boom B OpFocusBoom B OpFocus
add another var for campaignId

var cId = "{!campaing.Id}";

// call paex webservice
var result=sforce.apex.execute(
"Initiateapproval",
"initiateswapproval",
{mysw: cId});
Daniel MasonDaniel Mason
Hi thank you for your response, Where should your selection of code go ?