You need to sign in to do that
Don't have an account?

Error Updating the lookup field in Account object
I am trying to update the custom lookup field 'Primary_Distributor_c' in Account object and first of all my '_id' is null but when I run the query I have always 1 record back with Id
If you will see my problem here please support.
Here is my code:
==============================================
function pd_update(_name){
alert("Got Here '"+_name+"'");
alert("Got Here '"+_name+"'");
var qrdr = sforce.connection.query("select Id from Account where RecordTypeId='012600000004w6TAAQ' and Name = '"+_name + "'");
var records = qrdr.getArray("records");
alert("Found " + records.length + " Records...");
alert("Found " + records.length + " Records...");
if (records.length > 0){
_id=qrdr.records[0].Id;
}
if (_id) {
var _IsMatch = new sforce.SObject("Account");
_IsMatch.Id = _id;
_IsMatch.Primary_Distributor__c = _name;
var updateIsMatch = sforce.connection.update([_IsMatch]); //actually perform update
if (updateIsMatch[0].getBoolean("success")) { //if successful update of existing record
alert("PD Successfully updated!"); //indicate that the update was successful
} else {
alert("Error:\n"+updateIsMatch[0]); //display the error
}
}
_id=qrdr.records[0].Id;
}
if (_id) {
var _IsMatch = new sforce.SObject("Account");
_IsMatch.Id = _id;
_IsMatch.Primary_Distributor__c = _name;
var updateIsMatch = sforce.connection.update([_IsMatch]); //actually perform update
if (updateIsMatch[0].getBoolean("success")) { //if successful update of existing record
alert("PD Successfully updated!"); //indicate that the update was successful
} else {
alert("Error:\n"+updateIsMatch[0]); //display the error
}
}
}
Thanks.
Using the '_id' instead of '_name' did the job.
The old code would probably have worked fine if you would have replaced
Code:
with
Code: