I'm trying to create a button to execute an Apex Class with the Javascript attached. I'm getting the syntax error: Field object.id does not exist. Check spelling. What am I missing? What is window.location.href= looking for?
Global class InvoiceAccounts_Button {
Webservice static void createInvoiceAccounts() {
// Create a list of InvoiceAccounts
List<InvoiceAccount__c> InvA_List = new List<InvoiceAccount__c> {
new InvoiceAccount__c(Name='Kim_Button',Account_Owner_Name__c='Shain',Account_Owner_Title__c='Sir')};
// Bulk insert all InvoiceAccount__cs with one DML call
insert InvA_List;
}
}
Best Answer
You have a few problems with your code. Take a closer look at the example for
sforce.apex.execute
. The first parameter is the class name, which in your case should beInvoiceAccounts_Button
. The second value is the method name, which in your case should becreateInvoiceAccounts
. The third value is the arguments map, which in your case should be empty.What you have:
What you should have:
Your second problem is in your merge field. You have
{!Object.Id}
, but where you haveObject
, you should instead have the API Name of your specific object.What you have:
What you should have:
Even better: