Salesforce Integration with SOAP API – Part 9 – Upsert operation using Java program
Preface – This post is part of “Salesforce Integration with SOAP API” series.In today’s post, I will explain how you can do Upsert operation using SOAP API and Java Program. Before that we should know what is so special about Upsert? Upsert will allow you to create a new record or update the existing record. Now I am sure you have this question is mind – “How Salesforce will know that the record is already there in the system?”, right!!!! Good. The answer is that you can pass the custom field which will be used to determine the presence of the existing record. So easy!!!It is always recommended to use upsert() rather that create() because of the obvious reason i.e. upsert() will eliminate the chance of creating duplicate record in the system.Syntax -UpsertResult[] = connection.upsert(String externalIdFieldName, sObject[] sObjects);Important point – Note: I have written a helper class ConnectionHelper.java which I am using to connect to Salesforce using Enterprise WSDL. To know more about that, please refer my previous post @ Salesforce Integration with SOAP API – Part 4 – Java program for connecting to Salesforce using SOAP API and Enterprise WSDLBelow is the Java program – UpsertOperation.javaimport com.sforce.soap.enterprise.EnterpriseConnection;import com.sforce.soap.enterprise.Error;import com.sforce.soap.enterprise.UpsertResult;import com.sforce.soap.enterprise.sobject.Account;import com.sforce.soap.enterprise.sobject.SObject;import com.sforce.ws.ConnectionException;public class UpsertOperation { private EnterpriseConnection enterpriseConnection; private UpsertOperation(){ setEnterpriseConnection(ConnectionHelper.doConnect()); } public static void main(String[] args) { UpsertOperation upsertOperation = new UpsertOperation(); upsertOperation.doUpsertOperation(); } private void doUpsertOperation(){ SObject[] allUpserts = new Account[2]; //Create an Account...
Read More