You need to sign in to do that
Don't have an account?
FrankF
Error Updating a custom field in the Lead object (C#)
I need to set a Lookup field's value in Salesforce.com's Lead object and am using the code below.
The Qualifying_Campaign__c field is a custom lookup field related to the Campaign object and the value I'm setting is the correct Campaign Id for the campaign which we want to set. A describesObject call to look at the Lead object reveals that the Qualifying_Campaign__c is indeed updateable.
The code snippet comes from a function called by an Outbound Message from SFDC on Lead creation for certain types of Leads.
The Exception I get when I call the update function is as follows and I can't quite understand why it's happening...
Error message from catch (Exception ex)
A duplicate value was specified for field 'Id' in object 'Lead', duplicate value '00Q7000000OXbm5EAD' prior value '00Q7000000OXbm5EAD'
heh?!
The Qualifying_Campaign__c field is a custom lookup field related to the Campaign object and the value I'm setting is the correct Campaign Id for the campaign which we want to set. A describesObject call to look at the Lead object reveals that the Qualifying_Campaign__c is indeed updateable.
The code snippet comes from a function called by an Outbound Message from SFDC on Lead creation for certain types of Leads.
The Exception I get when I call the update function is as follows and I can't quite understand why it's happening...
Error message from catch (Exception ex)
A duplicate value was specified for field 'Id' in object 'Lead', duplicate value '00Q7000000OXbm5EAD' prior value '00Q7000000OXbm5EAD'
heh?!
Other troubleshooting showed that my code works when updating the OwnerID in the same way. The error only occurs when updating the Qualifying_Campaign__c field.
Thanks in advance,
Frank.
Code Snippet
QueryResult qrLead = RunQuery("select Id, Qualifying_Campaign__c from Lead where Id='" + leadid + "'"); sObject lead = null; if (qrLead != null && qrLead.size > 0) { lead = qrLead.records[0]; //Update to new username //ld.Id = leadid; //lead.Any[1].InnerText = uid; lead.Any[1].InnerText = "70170000000KheRAAS"; SaveResult[] saveResult = null; ; try { saveResult = _sfdcService.update(new sObject[] { lead }); } catch (Exception ex) { } if (saveResult[0].success) res = 1; else { _log.Error(String.Format("Failure in UpdateLead: {0}", saveResult[0].errors[0].message)); _log.Error("Lead ID : " + leadid + " RSM : " + rsm); } } else res= 0; |
In fact in your case, the query is a waste of time, you can skip it altogether and just construct the sobject, set the Id field to the lead Id, and set a single element in the Any array for the lookup field.
Thanks very much for your response. I've resolved the problem using your advice.
I'm just curious, even though it is a round trip, why it would have worked for OwnerId but not for Qualifying_Campaign__c.
Thanks again,
Frank.