To empty recycle bin data in Salesforce using external
application, emptyRecycleBin () method is
used.
application, emptyRecycleBin () method is
used.
emptyRecycleBin ()
Delete
records from the recycle bin immediately. The recycle bin lets you view and
restore recently deleted records for 15 days before they are permanently
deleted. Your Organization can have up to 5,000 records per license in the
Recycle Bin at any one time. For example, if your organization has five user
licenses, 25,000 records can be stored in the Recycle Bin. If your organization
reaches its Recycle Bin limit, Salesforce automatically removes the oldest
records, as long as they have been in the recycle bin for at least two hours. If
you know you will be adding a great number of records to the Recycle Bin and
you know you won’t need to undelete () them, you may wish to remove them before
the Salesforce process deletes records. For example, you can use this call if
you are loading a large number of records for testing, or if you are doing a
large number of create ()calls followed by delete() calls.
records from the recycle bin immediately. The recycle bin lets you view and
restore recently deleted records for 15 days before they are permanently
deleted. Your Organization can have up to 5,000 records per license in the
Recycle Bin at any one time. For example, if your organization has five user
licenses, 25,000 records can be stored in the Recycle Bin. If your organization
reaches its Recycle Bin limit, Salesforce automatically removes the oldest
records, as long as they have been in the recycle bin for at least two hours. If
you know you will be adding a great number of records to the Recycle Bin and
you know you won’t need to undelete () them, you may wish to remove them before
the Salesforce process deletes records. For example, you can use this call if
you are loading a large number of records for testing, or if you are doing a
large number of create ()calls followed by delete() calls.
Syntax
EmptyRecycleBinResult[]
= connection.emptyRecycleBin(ID[] ids);
= connection.emptyRecycleBin(ID[] ids);
where connection is an object of EnterpriseConnection.
Sample JAVA Program to
empty recycle bin data in Salesforce
empty recycle bin data in Salesforce
package wsc;
import
java.io.BufferedReader;
java.io.BufferedReader;
import
java.io.FileNotFoundException;
java.io.FileNotFoundException;
import java.io.IOException;
import
java.io.InputStreamReader;
java.io.InputStreamReader;
import
com.sforce.soap.enterprise.EmptyRecycleBinResult;
com.sforce.soap.enterprise.EmptyRecycleBinResult;
import
com.sforce.soap.enterprise.EnterpriseConnection;
com.sforce.soap.enterprise.EnterpriseConnection;
import
com.sforce.soap.enterprise.GetUserInfoResult;
com.sforce.soap.enterprise.GetUserInfoResult;
import
com.sforce.soap.enterprise.QueryResult;
com.sforce.soap.enterprise.QueryResult;
import
com.sforce.soap.enterprise.sobject.Account;
com.sforce.soap.enterprise.sobject.Account;
import
com.sforce.soap.enterprise.sobject.SObject;
com.sforce.soap.enterprise.sobject.SObject;
import
com.sforce.soap.enterprise.Error;
com.sforce.soap.enterprise.Error;
import
com.sforce.ws.ConnectionException;
com.sforce.ws.ConnectionException;
import
com.sforce.ws.ConnectorConfig;
com.sforce.ws.ConnectorConfig;
public class EmptyRecyleBin
{
public String authEndPoint = “”;
EnterpriseConnection
con;
con;
private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args)
{
EmptyRecyleBin
sample = new
EmptyRecyleBin(“https://login.salesforce.com/services/Soap/c/24.0/0DF90000000PX8r”);
sample = new
EmptyRecyleBin(“https://login.salesforce.com/services/Soap/c/24.0/0DF90000000PX8r”);
if ( sample.login() )
{
sample.emptyRecycle ();
}
}
public EmptyRecyleBin(String
authEndPoint)
authEndPoint)
{
this.authEndPoint = authEndPoint;
}
public String
getUserInput(String prompt)
getUserInput(String prompt)
{
String
result = “”;
result = “”;
try
{
System.out.print(prompt);
result
= reader.readLine();
= reader.readLine();
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
return result;
}
public boolean login()
{
boolean success = false;
String
userId = getUserInput(“UserID: “);
userId = getUserInput(“UserID: “);
String
passwd = getUserInput(“Password + Security Token:
“);
passwd = getUserInput(“Password + Security Token:
“);
try
{
/* Setting up Username and Password */
ConnectorConfig
config = new
ConnectorConfig();
config = new
ConnectorConfig();
config.setAuthEndpoint(authEndPoint);
config.setUsername(userId);
config.setPassword(passwd);
config.setCompression(true);
//config.setProxy(“Your Proxy”, 80);
System.out.println(“nAuthEndPoint: “ + authEndPoint + “n”);
config.setTraceFile(“deleteLogs.txt”);
config.setTraceMessage(true);
config.setPrettyPrintXml(true);
System.out.println(“nLogging in …n”);
/* Setting up connection to Salesforce */
con = new EnterpriseConnection(config);
GetUserInfoResult
userInfo = con.getUserInfo();
userInfo = con.getUserInfo();
System.out.println(“UserID: “ +
userInfo.getUserId());
userInfo.getUserId());
System.out.println(“nLogged in Successfullyn”);
success
= true;
= true;
}
catch (ConnectionException
ce)
ce)
{
ce.printStackTrace();
}
catch
(FileNotFoundException fnfe)
(FileNotFoundException fnfe)
{
fnfe.printStackTrace();
}
return success;
}
public void emptyRecycle ()
{
try
{
/* Getting Account details */
String
acctName = getUserInput(“Enter Account
name to search:”);
acctName = getUserInput(“Enter Account
name to search:”);
String
id = “”;
id = “”;
String sql = “SELECT Name,Id FROM Account WHERE Name Like ‘%” + acctName + “%'”;
QueryResult result = con.query(sql);
SObject[]
records = result.getRecords();
records = result.getRecords();
System.out.println(“nAccount Name Id Billing City n”);
for ( int i = 0; i < records.length; ++i )
{
Account
accnt = (Account) records[i];
accnt = (Account) records[i];
String
sfdcId = accnt.getId();
sfdcId = accnt.getId();
String
actName = accnt.getName();
actName = accnt.getName();
String
billingCity = accnt.getBillingCity();
billingCity = accnt.getBillingCity();
System.out.println(“n” + actName + “ “ + sfdcId + “ “ + billingCity
+ “n”);
+ “n”);
}
id
= getUserInput(“Enter the Account Id to
delete:”);
= getUserInput(“Enter the Account Id to
delete:”);
System.out.println(“nDeleting…n”);
/* Deleting account records */
String[]
ids = {id};
ids = {id};
con.delete(ids);
EmptyRecycleBinResult[]
emptyRecycleBinResults =
emptyRecycleBinResults =
con.emptyRecycleBin(ids);
/* Checking whether any error has been reported
* while emptying the recycle bin*/
for (int i = 0; i <
emptyRecycleBinResults.length; i++)
emptyRecycleBinResults.length; i++)
{
EmptyRecycleBinResult
emptyRecycleBinResult =
emptyRecycleBinResult =
emptyRecycleBinResults[i];
if (emptyRecycleBinResult.isSuccess())
{
System.out.println(“Recycled ID: “ +
emptyRecycleBinResult.getId());
}
else
{
Error[]
errors = emptyRecycleBinResult.getErrors();
errors = emptyRecycleBinResult.getErrors();
if (errors.length > 0)
{
System.out.println(“Error code: “ +
errors[0].getStatusCode());
System.out.println(“Error message: “ +
errors[0].getMessage());
}
}
}
System.out.println(“nAccount has been deleted successfully.nn”);
System.out.println(“nAfter Deletingnn”);
sql = “SELECT
Name,Id FROM Account WHERE Name Like ‘%” + acctName + “%'”;
Name,Id FROM Account WHERE Name Like ‘%” + acctName + “%'”;
result = con.query(sql);
records
= result.getRecords();
= result.getRecords();
System.out.println(“nAccount Name Id Billing City n”);
for ( int i = 0; i < records.length; ++i )
{
Account
accnt = (Account) records[i];
accnt = (Account) records[i];
String
sfdcId = accnt.getId();
sfdcId = accnt.getId();
String
actName = accnt.getName();
actName = accnt.getName();
String
billingCity = accnt.getBillingCity();
billingCity = accnt.getBillingCity();
System.out.println(“n” + actName + “ “ + sfdcId + “ “ + billingCity
+ “n”);
+ “n”);
}
}
catch (ConnectionException
ce)
ce)
{
ce.printStackTrace();
}
}
}
Output:
UserID: [email protected]
Password + Security Token: fgfuserfgfgnhHUwB1kFNW9kEw
AuthEndPoint:
https://login.salesforce.com/services/Soap/c/24.0/0DF900fgsfgPX8r
[WSC][EmptyRecyleBin.login:65]Log
file already exists, appending to deleteLogs.txt
Logging in …
UserID: 00590sfgf0qXHsAAM
Logged in Successfully
Enter Account name to
search:test
Account Name Id Billing City
Test_Acct3 0019000000Ad2tJAAR null
Test Acct3 0019000000AcfBFAAZ null
Test Acct 0019000000AceoOAAR null
Test Acct1 0019000000AcevzAAB null
Test Acct2 0019000000Acew0AAB null
test poc 0019000000BOP0SAAX null
Test SFDC POC 0019000000BOPWmAAP null
test_accccc 0019000000BOLBJAA5 null
Test 0019000000BOOFMAA5 null
Enter the Account Id to
delete:0019000000BOLBJAA5
Deleting…
Recycled ID: 0019000000BOLBJAA5
Account has been deleted
successfully.
After Deleting
Account Name Id Billing City
Test_Acct3 0019000000Ad2tJAAR null
Test Acct3 0019000000AcfBFAAZ null
Test Acct 0019000000AceoOAAR null
Test Acct1 0019000000AcevzAAB null
Test Acct2 0019000000Acew0AAB null
test poc 0019000000BOP0SAAX null
Test SFDC POC 0019000000BOPWmAAP null
Test 0019000000BOOFMAA5 null
|