Skip to main content
Hi All,

I have a scenario where i am adding some records to a set <Id> and that Set<Id> we have to add into a List using Addall but that is not possible.I need this list to be passed for Database.delete(List,False).Can i get soem ideas how to pass the set<Id> into a List<Sobject>

Example code:

Set<Id> parSet = new Set<Id>();

List<Account> DelAccLst= new List<Account>();

In this parSet i have some records and then after the forloop we need to add it to the list DelAccLst and this list i have to pass fro Deletion

DelAccLst.addAll(parSet );

Database.delete(DelAccLst,false);

How can i get this done please give me some ideas.

Thanks in advance,
3 respostas
  1. 24 de set. de 2018, 09:59
    Hi 

    Try this:

     

    Set<Id> parSet = new Set<Id>();

    List<Account> DelAccLst= [select id from account where id in : parSet];

    Database.DeleteResult[] drList = Database.delete(DelAccLst, false);

    // Iterate through each returned result

    for(Database.DeleteResult dr : drList) {

    if (dr.isSuccess()) {

    // Operation was successful, so get the ID of the record that was processed

    System.debug('Successfully deleted account with ID: ' + dr.getId());

    }

    else {

    // Operation failed, so get all errors

    for(Database.Error err : dr.getErrors()) {

    System.debug('The following error has occurred.');

    System.debug(err.getStatusCode() + ': ' + err.getMessage());

    System.debug('Account fields that affected this error: ' + err.getFields());

    }

    }

    }

    Hope this helps you!

    If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

    Thanks

    Varaprasad

    @For SFDC Support: varaprasad4sfdc@gmail.com

    Blog: http://salesforceprasad.blogspot.com/

    Salesforce latest interview questions  :

    https://www.youtube.com/channel/UCOcam_Hb4KjeBdYJlJWV_ZA?sub_confirmation=1

     
0/9000