• TEJA M 19
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
Hi All,

I m trying to delete from a temperory object from database.saveresult. after successful process i am getting the ids and querying records and from quired records I am taking conact ids and entitlement ids and then querying based on the ids and deleting those records. 
Is there any optimized way that i can delete records without qureying from database because i have the ids for both temporary object and entilements here.

if(contEntToInsert != null && contEntToInsert.size()>0) {
                
                Database.SaveResult[] conEntList = Database.insert(contEntToInsert,false); 
                System.debug('conEntList------------>'+conEntList);
                integer index = 0;
                set<id> CONENTID = new set<id>();
                for (Database.SaveResult sr : conEntList){
                    if(sr.isSuccess()){
                        //set<id> CONENTID = new set<id>();
                        CONENTID.add(sr.getId());
                        system.debug('sr.getId()=======>' +sr.getId());
                        
                    }
                }
                
                List<Core_Contact_Entitlement__c> successConEntList = [SELECT id,Core_Contact_Id__c, Core_Entitlement_Id__c 
                                                                       from Core_Contact_Entitlement__c where id IN: CONENTID];
                system.debug('successConEntList'+ successConEntList);
                List<id> contactids = new List<id>();
                List<id> contEntitids = new List<id>();
                for(Core_Contact_Entitlement__c conEnt: successConEntList){
                    contactids.add(conEnt.Core_Contact_Id__c);
                    contEntitids.add(conEnt.Core_Entitlement_Id__c);    
                }
                system.debug('contactids'+ contactids);
                system.debug('contEntitids' + contEntitids);
                List<PRM_Batch_Entitlement__c> batchEntitlementtoDeleteList =[select id,PRM_Contact_Id__c,PRM_Entitlement_Id__c 
                                                                              from PRM_Batch_Entitlement__c where PRM_Contact_Id__c 
                                                                             IN: contactids AND PRM_Entitlement_Id__c IN:contEntitids];
                
                system.debug('batchEntitlementtoDeleteList' + batchEntitlementtoDeleteList);
                delete batchEntitlementtoDeleteList;
Hi I m little confused with the difference between issued and Dml Statements,Total number of SOQL queries issued 100, Total number of DML statements issued 150. i used FOR loop for insertion, I know its not best practice, I m trying to learn possibilities, I did nt use any soql query then why i m getting System.LimitException: Too many SOQL queries: 101, but insert is DML operation right? it should hit DML Exception 151? someone please explain me this.  

public class accountinse {
    
    public PageReference show(){
        List<Account> ac=new List<Account>();
        for(Integer i=0; i<200; i++){
            
            
            a.Name='testing12535'+i;
            a.AccountNumber='4857885';
            a.Type='Prospect';
            a.Industry='Biotechnology';
            a.AnnualRevenue=158758;
            a.Rating='cold';
            a.Phone='18578558';
            a.Identity_Proof__c='Adhar Card; PAN Card';
            a.Last_Name__c='a';
            ac.add(a);
        
        }
        insert ac;
        return null;
    }

}
Hi I m little confused with the difference between issued and Dml Statements,Total number of SOQL queries issued 100, Total number of DML statements issued 150. i used FOR loop for insertion, I know its not best practice, I m trying to learn possibilities, I did nt use any soql query then why i m getting System.LimitException: Too many SOQL queries: 101, but insert is DML operation right? it should hit DML Exception 151? someone please explain me this.  

public class accountinse {
    
    public PageReference show(){
        List<Account> ac=new List<Account>();
        for(Integer i=0; i<200; i++){
            
            
            a.Name='testing12535'+i;
            a.AccountNumber='4857885';
            a.Type='Prospect';
            a.Industry='Biotechnology';
            a.AnnualRevenue=158758;
            a.Rating='cold';
            a.Phone='18578558';
            a.Identity_Proof__c='Adhar Card; PAN Card';
            a.Last_Name__c='a';
            ac.add(a);
        
        }
        insert ac;
        return null;
    }

}