+ Start a Discussion
HasanJafferHasanJaffer 

Custom Button Using Apex

Hi Everybody,

I want a custom button(next to: Request Update in contact page). 

When the button is pressed(by the admin) it should send mail to particular person(Let the contact person name be : XX)

XX receives a mail and XX should fill the custom fields sent along with the mail (this is to update the contact info).

When XX fill up the fields and hits the submit button it should be updated in Admin DB.

Is it possible?

 

Thanks

Haan

SennahSennah

Hi Hasan,

 

I would really question your use case, but here's how you can invoke APEX from a Cutom Button:

 

First, create an Apex Class with at least one method:

 

 

global class MySuperCoolClass{
Webservice static void DoThis(String objectId) {
// Here goes your logic
}
}

 

 

And this is what you put in your Button of type "Execute Javascript":

 

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

sforce.apex.execute(
'MySuperCoolClass',
'DoThis',
{objectId:'{!Contact.Id}'}); 

 

 

Good Luck and have fun :)

 

//Hannes

forecast_is_cloudyforecast_is_cloudy

As an FYI, there is another option for invoking Apex code from a custom button. Create a new VF page and an associated custom controller. Bind the 'action' attibute of the top level <apex:page> tag to a method in the custom controller. Include the custom Apex logic that you want performed in this method. You can now associate the new custom button with the VF page and your custom Apex logic will be triggered when the user clicks on the button.

Hope this helps.