Preface – This post is part of “Salesforce Integration with SOAP API” series.

In this blog post, I will go through an example where I will use Java program to perform delete operation using Salesforce’s SOAP API. The Syntax is given below –

DeleteResult[] = connection.delete(ID[] ids);


You should consider the below points before using the delete operation. 


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 @ 

Below is the Java program – DeleteAccount.java where I am deleting an Account record with ID: 0019000000tvEQo.
import com.sforce.soap.enterprise.DeleteResult;
import com.sforce.soap.enterprise.EnterpriseConnection;
import com.sforce.soap.enterprise.Error;
import com.sforce.ws.ConnectionException;


public class DeleteAccount {
private EnterpriseConnection enterpriseConnection;

private DeleteAccount(){
setEnterpriseConnection(ConnectionHelper.doConnect());
}

public static void main(String[] args) {
DeleteAccount deleteAccount = new DeleteAccount();
deleteAccount.doDeleteAccount(new String[]{"0019000000tvEQo"});
}

private void doDeleteAccount(String ids[]){
try{
DeleteResult[] deleteResults = getEnterpriseConnection().delete(ids);

for(DeleteResult eachDeleteResult : deleteResults){
if(eachDeleteResult.isSuccess()){
System.out.println("Deleted record id: " + eachDeleteResult.getId());
}else{
for(Error eachError: eachDeleteResult.getErrors()){
System.out.println("Error occurred with message: " + eachError.getMessage());
}
}
}
}catch(ConnectionException e){
e.printStackTrace();
}
}


public EnterpriseConnection getEnterpriseConnection() {
return enterpriseConnection;
}


public void setEnterpriseConnection(EnterpriseConnection enterpriseConnection) {
this.enterpriseConnection = enterpriseConnection;
}

}


It’s super easy!!!. Please provide your feedback. Thanks.