Posts

Showing posts with the label bulkdelete

Script to delete multiple records using Apex salesforce

Delete multiple records from salesforce anonymous block using some script.find the below script just paste the script in the anonymous vlock and select the code and click on Execute Highlighted. Before that if any conditions need to check add it in SOQL Query or if condition then it will filter the records and delete the records. If there are more records we have to run this script multiple times .if we try to delete all the records at a time we might get the DML and limit exceptions.so adding limit in SOQL query and executing. Example :  Object : ABC__c Fields : field1__c, field2__c list<ABC__c> abclist = new list<ABC__c>(); List<ABC__c > alltldroles = [SELECT id,name,field1__c,field2__c                              FROM ABC__c LIMIT 1000]; if(alltldroles.size()>0){     for(ABC__c tldroleslist : alltldroles) {          if(tldroleslist.field1__c != null && tldroleslist.field2__c!=null )  {           abclist.add(tldroleslist);       }