Salesforce Integration with SOAP API – Part 10 – Delete operation using Java program

by Sudipta Deb | Mar 2, 2015 | 501, Apex, dev 501, integration, Salesforce, SOAP | 2 comments

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.


Written by

Related Posts

Salesforce Cancels the “Permissions in Profiles” Retirement: What It Means for Admins and Architects

Salesforce Cancels the “Permissions in Profiles” Retirement: What It Means for Admins and Architects

For the last few years, Salesforce administrators, architects, and security teams have been preparing for a major platform change: the retirement of permissions managed directly through Profiles. Salesforce had previously announced plans to move organizations toward a Permission Set–led security model, with enforcement expected to begin around the Spring ’26 timeframe.

read more...

2 Comments

  1. Unknown

    With cloud computing, you eliminate those headaches because you’re not managing hardware and software—that’s the responsibility of an experienced vendor like salesforce.com. The shared infrastructure means it works like a utility: You only pay for what you need, upgrades are automatic, and scaling up or down is easy. Thanks for sharing this in here.

    Salesforce course in chennai
    Salesforce developer training in chennai

    Reply

Leave a Reply