开发者

How to delete more than one record at a time in salesforce?

开发者 https://www.devze.com 2023-02-08 14:33 出处:网络
How do I delete more than one record at 开发者_JS百科a time in salesforce?Delete all Salesforce Account objects (up to the artificially imposed limitations per SF query on whatever the object happens

How do I delete more than one record at 开发者_JS百科a time in salesforce?


Delete all Salesforce Account objects (up to the artificially imposed limitations per SF query on whatever the object happens to be):

delete new List<Account>([select Id from Account]);

Where "Account" is any Salesforce object (or custom object you've created). You can fine-tune the delete by adding the "WHERE" clause:

delete new List<Account>([select Id from Account where ... ])

Or the "LIKE" clause:

delete new List<Account>([select Id from Account where LastName like 'Jon%']);


Is this what you want?

Salesforce CRM -delete()


Here is a method in Java that would delete one row in salesforce.

Salesforce ID's are 18 character case sensitive keys. Every table has an id that is unique across the entire database. So you can delete by an id, and salesforce will know what table you are referring to.

public static boolean salesforceDevDeleteById(String id){
    SalesforceConnector sf;

    boolean deletesuccess = false;
    try{
        sf = new SalesforceConnector();
        sf.login("youruser@yourhost.com",
            "keyasdf", "keyasdf", "dev");

        if (!id.equals("")){
           DeleteResult[] deleteResults = sf.delete(new String[]{id});
           for(DeleteResult r : deleteResults){
                deletesuccess = r.isSuccess();
                break;
           }
        }
        else{
            System.out.println("Failed to delete");
        }
        System.out.println("delete success: " + deletesuccess);
    }
    catch(Exception e){
        e.printStackTrace();
        System.out.println("error");
    }
    return deletesuccess;
}

Notice where it invokes the delete method. You can load a set of id's there.


psuedo: List _list = new List(); _list.add(a); _list.add(b); delete(_list);

0

精彩评论

暂无评论...
验证码 换一张
取 消