You need to sign in to do that
Don't have an account?
Raghu Sharma 6
list button: logic to allow button to be conditionally performing action
I need to create a list button on 'contact related list' under Account object. I want to write a java script to check whether the account billing state is 'CA'. I want to execute further logic (apex page/apex class) only if the condition matches. But when I tried this below logic, it didnt work.and I see that Account id is not being displyed when I tried to display it. What is missing here? how to get the account id on this button logic?
{!REQUIRESCRIPT("/soap/ajax/24.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} var AcctId = '{!Contact.Account}'; var Bill_State = sforce.connection.query("Select State__c From Account WHERE Id = '{!Contact.Account}'"); var rec = Bill_State.getArray("records"); if(rec[0].State__c == 'CA') { alert("This is CA."); //will replace later with logic to call vf page/apex class } else { alert("This is not CA"); }
Related fields are not supported in Javascript button in Salesforce as of now.
To solve the problem create a formula field called "Accountid" on Contact.
Formula for Accountid = Account.Id
and then use following code.
Above code is working fine in developer org. Hope it will work for you.
Please let me know if you have any question.
Thanx.