You need to sign in to do that
Don't have an account?
pleclech
How to call APEX code in a custom button
Hi,
here is the case :
I want to include a new custom button which call an APEX method that will create maybe more than 100 objects linked to the object we currently seeing.
As you can see I have some difficulties to do it with an APEX trigger because governor limits.
So the solution should be to create this objects by the user with a simple button on the layout.
Can you help ?
Hi
To call a Apex class method from a button you need to define the method as "webservice".
You can call the method by using Ajax toolkit.
Below is the sample code.
Apex code:
global class class1{
WebService static Integer method1(String iTitle){
Your logic here
}
}
Custom button code:
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
var result = sforce.apex.execute("class1", "method1",{iTitle : noteTitle});
Hope it helps.
-AJ
All Answers
Hi
To call a Apex class method from a button you need to define the method as "webservice".
You can call the method by using Ajax toolkit.
Below is the sample code.
Apex code:
global class class1{
WebService static Integer method1(String iTitle){
Your logic here
}
}
Custom button code:
{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
var result = sforce.apex.execute("class1", "method1",{iTitle : noteTitle});
Hope it helps.
-AJ
it sounds really good !
I wonder this kind of solution but now you confirm it's definitely the 1st solution that come in mind.
Thanks !
Do you have any good references for documentation on this? I could set this up using a trigger, but I would prefer not to if possible. I assume just look for 'webservice' references, but if there is a specific source that talks on this, please post.....
Thanks,