0

I have created a DLL project in C# which is used to add a lead to a Salesforce account via the Partner WSDL/SOAP API.

This DLL is called from an external .NET web application, and the idea is to send the data submitted in that web form to Salesforce.

Currently I am able to create new leads using binding.create(...) however I need to extend the functionality to handle updates to existing records in Salesforce

Example:

  • I add a lead with FirstName=John, Surname=Doe, this data is added to Salesforce

  • Edit the above row and change surname to Smith, update the existing record in Salesforce and change LastName to Smith.

My research tells me that I need to specify a field name in the first parameter of binding.upsert(...) but which field should I use?

This is on the Lead object so perhaps I can use Email? The docs say

The idLookup field property is usually on a field that is the object's ID field or name field, but there are exceptions, so check for the presence of the property in the object you wish to upsert().

However I do not know the ID of the lead I am editing.

Please advise which field I can use in the first parameter, and/or how to see which fields in the Lead object has the [idLookup] property.

-1

A few months ago, I created a similar project in C# via the Partner WSDL/SOAP API.

You can create a custom External Id field on the Lead object.Use it you can upsert the Lead correctly.

  • I ended up using the Email address in Lead object as it's idLookup is set to True. – andrewb Nov 18 '16 at 5:52
  • Using the Email address, I think you can not update the existing records.The records are inserted, not updated. – s.Lee Nov 22 '16 at 2:05
-1

The easiest they you could do would be to keep the ID that is returned by the initial create in the SaveResult. With that you will have the primary key that you could then using in a direct update call.

With an upsert the field indicated by the externalIdFieldName parameter is used if the sObject doesn't have the ID defined. Basically Salesforce will look for an existing record that has the same value as the parameter sObject in that field. If the values match, the existing record in Salesforce will be updated. If there are no matches, the sObject will be inserted instead.

The field you sepecify in externalIdFieldName must have the corresponding external Id attribute set or be a standard field with the idLookup attribute set.

For each object that can have custom fields, you can set up to seven custom auto-number, email, number, or text fields as external IDs. An external ID field contains record identifiers from a system outside of Salesforce.

You can use an external ID field to update or upsert records using the API.

From Upserting Records:

Using the upsert operation, you can either insert or update an existing record in one call. To determine whether a record already exists, the upsert statement or Database method uses the record’s ID as the key to match records, a custom external ID field, or a standard field with the idLookup attribute set to true.

  • If the key is not matched, then a new object record is created.
  • If the key is matched once, then the existing object record is updated.
  • If the key is matched multiple times, then an error is generated and the object record is neither inserted or updated.

Since the Lead.Email address is a standard field with the idlookup attribute set to true in can be used as the upsert key.

  • Turns out I can use the Email field as it has the idLookup property on that field (found that by using describeSObject(). – andrewb Nov 18 '16 at 5:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.