Friday, June 1, 2012

Web service method call from Custom Button


Technical Requirement:
We have enhancement request in our project and requirements are select number of records in View and change the owner of the selected record.
Description:
As above technical requirement we want to create action from Button and update the records.
Steps to solve above requirement:
1. Create Custom button or Link Named Assign and behavior execute JavaScript.
Code on button:
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")} // declare the Js connection
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")} // declare the Js apex
{!REQUIRESCRIPT("/js/dojo/0.4.1/dojo.js")} // declare the Js dojo
var ids='';
for(j=0;j< document.forms.length;j++)
{
for (i = 0;i
{
if((document.forms[j].elements[i].name=='ids') && document.forms[j].elements[i].checked)
{
ids+=document.forms[j].elements[i].value+',';
}
}
}// end of loop
if(ids==''){
alert('No requests selected !!!');
}else{
var returnFlag = '';
returnFlag = sforce.apex.execute("CheckClass" , "methode ", {ids:ids} );
if(returnFlag== ‘true’){
window.location = '/apex/PageName;
}else if(returnFlag== ‘false){
alert('You do not have permission to do this!')
}
--------------End of Code--------------------
2. Apex class:
global class CheckClass{
WebService static Boolean methode(){
Write the Logic
Return Boolean value
}
}

No comments:

Post a Comment