You need to sign in to do that
Don't have an account?
Brenzo
Execute Javascript Button to Create Contact Record from Related List (on Account Record)
I am trying to create a onclick, executable javascript list button that will appear from the account record and enable the following when clicked:
So a couple problems...
First, I'm getting an error that 'Account' doesn't exist on the contact object, which obviously is not the case. What am I messing up here? I know it's something small.
Second, I don't how to get it so that upon successfully creating the contact record, to also update the custom check box field on the account page. Idealy I'd like this to happen in the background and refresh the page so that the user isn't taken to the contact record page.
Thanks in advance for any help!
- Create a new contact record, using values that appear in custom fields on the Account record where the button appears
- Update a check box field on the Account record
- Display a confirmation message
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")}
var ContactObj = new sforce.SObject("Contact");
ContactObj.Account='{!Account.Id}';
ContactObj.FirstName='{!Account.AP_First_Name__c}';
ContactObj.LastName='{!Account.AP_Last_Name__c}';
ContactObj.Phone='{!Account.Accounts_Payable_Phone__c}';
ContactObj.Responsible_for_A_P__c='1';
var result = sforce.connection.create([ContactObj]);
if(result[0].getBoolean("success")){
window.location = "/" + result[0].id + "/e";
}else{
alert('Could not create record '+result);
}
{!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")}
var ContactObj = new sforce.SObject("Contact");
ContactObj.Account='{!Account.Id}';
ContactObj.FirstName='{!Account.AP_First_Name__c}';
ContactObj.LastName='{!Account.AP_Last_Name__c}';
ContactObj.Phone='{!Account.Accounts_Payable_Phone__c}';
ContactObj.Responsible_for_A_P__c='1';
var result = sforce.connection.create([ContactObj]);
if(result[0].getBoolean("success")){
window.location = "/" + result[0].id + "/e";
}else{
alert('Could not create record '+result);
}
So a couple problems...
First, I'm getting an error that 'Account' doesn't exist on the contact object, which obviously is not the case. What am I messing up here? I know it's something small.
Second, I don't how to get it so that upon successfully creating the contact record, to also update the custom check box field on the account page. Idealy I'd like this to happen in the background and refresh the page so that the user isn't taken to the contact record page.
Thanks in advance for any help!
Use Accountid instead of Account on contact object it will work.
To update check box field on account .first you need to query it for the field and update it .
Thanks
Anil.B
Quick follow up @anilbathula...
I'm stuck trying to do two things with a modified version of this javascript button.
-
I want to make it so that if a field on the account record is blank, clicking the button will take the user to a contact creation screen with certain values pre-populated. If this account field is not blank, then automatically create the contact record in the background and refresh the page (updating the account check box field in the process.)
-
I've got the query set up (see below) to update the check box on the account page, but it isn't working as intended. If I had to guess, I have something out of order....
Updated code:Still having trouble figuring out how to get to the contact creation screen should the initial criteria be met (APContact == "")