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
vgorgolvgorgol 

calling a function from a Button

We have a situation where we are requiring to call a function from custom button OnClick Javascript.  The function is located in utility class we created.

 

 

Whenever the button is pressed, we get a message stating that 'SysUtil is not defined'. SysUtil is the class we created.

 

I am assuming either I am just not using the proper sytax (very likely as I am very new to this langauge, and to Java as well) or its just not possible.  Any help is greatly appreciated.

 

 

 

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}

var recordsId = {!GETRECORDIDS( $ObjectType.Address__c )};
var GetUserInfoResult=sforce.connection.getUserInfo();


if(recordsId[0] == null)
{
    if (GetUserInfoResult.userLanguage == 'fr') {
        alert('SVP faites une sélection');
    }
    else
    {
        alert("Please select at least one address record to create a new pickup request.")
    }
}

else if(recordsId.length > 1){
    if (GetUserInfoResult.userLanguage == 'fr')
    {
        alert('Pour cloner une adresse, SVP faites seulement une sélection.');
    }
    else
    {
        alert("Please select only one address record to create a new pickup request.")
    }
}


else if(SysUtil.isAddressScheduledForDeletion(recordsId[0]))
{
alert('This address cannot be used to create a pickup request as it is marked for deletion. Please choose another.');
}


else
{
parent.window.location.href = '/apex/vf_pickupRequest?addressid='+recordsId;
}

Best Answer chosen by Admin (Salesforce Developers) 
NOTSOFASTNOTSOFAST

If I understand the question correctly it is possible to call an Apex (webservice) method from a custom button that executes javascript. The instuctions are in the Developer's Guide: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content%2Fapex_and_ajax.htm|SkinName=webhelp

 

Hope that helps.

All Answers

jbroquistjbroquist
You cannot call Apex methods from a custom button. Where is your custom button being called from? (Detail Page, List View, Related List, etc.,) What exactly does your isAddressScheduledForDeletion method do? Perhaps then I could give you some possible workaround solutions.
NOTSOFASTNOTSOFAST

If I understand the question correctly it is possible to call an Apex (webservice) method from a custom button that executes javascript. The instuctions are in the Developer's Guide: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content%2Fapex_and_ajax.htm|SkinName=webhelp

 

Hope that helps.

This was selected as the best answer