• IT AccuAir
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I have a List Button on a Contact List View which I've set to execute Javascript. I am trying to update a custom field on the Account associated with the selected Contact when the button is pressed. Right now I can't get the Account ID which relates the selected Contact(s). I will post my Javascript code below.

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
// Get list of selected Contact IDs
var records = {!GETRECORDIDS($ObjectType.Contact)};

if (records[0] == null) {
   alert("Please select at least one record to update.");
}

// Loop through Contact IDs
for(var i=0; i < records.length; i++) {
   // Create Account object to update field on
   var account = new sforce.SObject("Account");
   account.id = records[i]; // won't work because Account.Id != Contact.Id

   // Update custom field value
   account.My_Custom_Field__c = "value";
   sforce.connection.update([account]);
}
window.location.reload();

As you can see, I have most of the code ready to use. The only problem is that the Contact's id does not match the Account id. Is it possbile I could get the Contact.AccountId field value and use it to set account.id?
I have a List Button on a Contact List View which I've set to execute Javascript. I am trying to update a custom field on the Account associated with the selected Contact when the button is pressed. Right now I can't get the Account ID which relates the selected Contact(s). I will post my Javascript code below.

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
// Get list of selected Contact IDs
var records = {!GETRECORDIDS($ObjectType.Contact)};

if (records[0] == null) {
   alert("Please select at least one record to update.");
}

// Loop through Contact IDs
for(var i=0; i < records.length; i++) {
   // Create Account object to update field on
   var account = new sforce.SObject("Account");
   account.id = records[i]; // won't work because Account.Id != Contact.Id

   // Update custom field value
   account.My_Custom_Field__c = "value";
   sforce.connection.update([account]);
}
window.location.reload();

As you can see, I have most of the code ready to use. The only problem is that the Contact's id does not match the Account id. Is it possbile I could get the Contact.AccountId field value and use it to set account.id?