0

class method:-

Error on this line

  • lstofSobj = Database.query(query); -Unexpected token null
public void deleteRecord(){
         //system.debug('typeName::::'+typeName);             
         List<Product2> lstPrd = [SELECT Id, Name ,Product_Brand__c, Event_Edition_Pool__c FROM product2 WHERE Product_Brand__c=: oTargetEE.Name AND Cloned__c = true]; 
         query = 'SELECT id FROM '+ typeName +' WHERE Product__c IN :lstPrd limit 5000';                
         lstofSobj = Database.query(query);        
         List<CPQ_Clone_Progress__c> lstCloneProg  = [SELECT Id, Name FROM CPQ_Clone_Progress__c WHERE CPQ_Product_Clone__c = :oCPQProdClone.Id]; 

        if(lstPrd !=null && lstPrd.size() > 0  && lstCloneProg  !=null && lstCloneProg.size() > 0){
            List<SBQQ__ProductFeature__c> lstProdFeature = [SELECT Id FROM SBQQ__ProductFeature__c WHERE SBQQ__ConfiguredSKU__c IN :lstPrd ];
            List<SBQQ__ProductOption__c> lstprodOption = [SELECT Id FROM SBQQ__ProductOption__c  WHERE SBQQ__ConfiguredSKU__c IN :lstPrd ];
            List<SBQQ__ConfigurationRule__c> oProdConfigRules  = [SELECT Id, Name FROM SBQQ__ConfigurationRule__c WHERE SBQQ__Product__c IN :lstPrd];         
            oCPQProdClone.Cloned__c = false;
            Savepoint oSavePoint = Database.setSavepoint();
            try{
                delete oProdConfigRules;
                delete lstprodOption;
                delete lstProdFeature;
                delete lstCloneProg;
                delete lstPrd;
                delete lstofSobj;
                isCloned = 'Yes';
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'The cloned Products/Packages for the Event Edition '+ oCPQProdClone.Target_Event_Edition__c + ' has been deleted successfully'));          
                system.debug('deletelstPrd::::'+lstPrd);
                update oCPQProdClone;

            }
            catch(Exception e){
                isCloned = 'Yes';
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,e.getMessage()));
                system.debug('Messagedelete::::'+e.getMessage());
                Database.rollback(oSavePoint);      
            }        
        }
        else if(lstCloneProg!=null && lstCloneProg.size()> 0){
            oCPQProdClone.Cloned__c = false;
            delete lstCloneProg;
            isCloned = 'Yes';
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'The cloned Products/Packages for the Event Edition '+ oCPQProdClone.Target_Event_Edition__c + ' has been deleted successfully'));          
            system.debug('deletelstPrd::::'+lstPrd);
            update oCPQProdClone;       
        }
        else{
            isCloned = 'Yes';
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Products/Packages for the Event Edition '+ oCPQProdClone.Target_Event_Edition__c +' already deleted.'));
        }     
    }   

Test class:-

@isTest
public class test_CloneEventProducts_Ctrl{

    static testMethod void unitTest() {

    Test.StartTest();
    Account oAccount = new Account(Name='Rebook_EE Account', CurrencyIsoCode = 'USD');
    insert oAccount;

    Contact oCon = new Contact(LastName='Rebook_EECont', Email='test1contact@sforce.com', AccountId = oAccount.Id, MailingStreet = 'Test',MailingCity ='Test',MailingState='Alabama');
    insert oCon;

    User oUser = [SELECT Id FROM User WHERE Id = : UserInfo.getUserId()];
    AccountTeamMember oAtm =new AccountTeamMember(AccountId = oAccount.id, userId = oUser.id);
    insert oAtm;

    Event_Edition__c oEvent = new Event_Edition__c(Name = 'World of Concrete 2017',Approval_Service_Now_ID__c = '123', CurrencyIsoCode = 'USD', Event_Code__c = 'KDB,KDB2', Booth_Type__c = 'Island,Corner,Inline,Custom,Peninsula', No_Of_Corner__c = '0,1,2,3,4',Tab1__c = 'test' ,Tab7__c = 'test', Booth_Size__c = '100 SqFt,400 SqFt,900 SqFt,1600 SqFt,2500 SqFt', Start_Date__c = Date.today(),End_Date__c = Date.today());
    insert oEvent;

    Event_Edition__c oEvent3 = new Event_Edition__c(Name = 'World of Concrete 2018',Approval_Service_Now_ID__c = '1234', CurrencyIsoCode = 'USD', Event_Code__c = 'KDB,KDB2', Booth_Type__c = 'Island,Corner,Inline,Custom,Peninsula', No_Of_Corner__c = '0,1,2,3,4',Tab1__c = 'test' ,Tab7__c = 'test', Booth_Size__c = '100 SqFt,400 SqFt,900 SqFt,1600 SqFt,2500 SqFt', Start_Date__c = Date.today(),End_Date__c = Date.today());
    insert oEvent3;

    Opportunity oOpportunity = new Opportunity(Name = 'Expocad Opportunity', CloseDate = Date.today(), StageName = 'Closed Booked', EventEdition__c = oEvent.Id, AccountId = oAccount.Id, Billing_Contact__c = oCon.Id, Rebooked__c = false);
    insert oOpportunity;    

        //Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
        Id stdPb = Test.getStandardPricebookId();
        Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true);
        insert pb;
        Product2 prod = new Product2(Name = 'Floor Graphic', Family = 'Event',Brand__c='World of Concrete', Product_Brand__c='World of Concrete 2017' ,Event_Edition_Pool__c='WOC', Event_Edition_WOC__c='World of Concrete 2017',CurrencyIsoCode='USD', IsActive = true);
        insert prod;
        Product2 prod1 = new Product2(Name = 'Cool Package', Family = 'Package',Brand__c='Arab Health',Event_Edition_LFSC__c='Arab Health 2017', Product_Brand__c='Arab Health 2017' ,Event_Edition_Pool__c='LFSC',CurrencyIsoCode='BRL', IsActive = true);
        insert prod1;

        PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = stdPb, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
        insert standardPrice;

        PricebookEntry pbe = new PricebookEntry(Pricebook2Id = stdPb, Product2Id = prod1.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
        insert pbe;



    SBQQ__ProductRule__c objPRule = new SBQQ__ProductRule__c();
    objPRule.name= 'Test P Rule';
    objPRule.SBQQ__Type__c = 'Filter';
    objPRule.SBQQ__ConditionsMet__c = 'All';
    objPRule.SBQQ__Scope__c = 'Product';
    insert objPRule;

    SBQQ__ProductFeature__c objFeature = new SBQQ__ProductFeature__c();
    objFeature.name='Core Product';
    objFeature.SBQQ__Number__c = 10;
    objFeature.SBQQ__ConfiguredSKU__c = prod.id;
    objFeature.SBQQ__MinOptionCount__c = 1;
    insert objFeature;

    SBQQ__ProductOption__c objOptions = new SBQQ__ProductOption__c();
    objOptions.SBQQ__Number__c =5;
    objOptions.SBQQ__ConfiguredSKU__c = prod.id;
    objOptions.SBQQ__OptionalSKU__c = prod.id;
    objOptions.SBQQ__Feature__c = objFeature.id;
    insert objOptions;

    SBQQ__ConfigurationRule__c objCRules = new SBQQ__ConfigurationRule__c();
    objCRules.SBQQ__Product__c = prod.id;
    objCRules.SBQQ__ProductRule__c = objPRule.id;
    insert objCRules;

    CPQ_Product_Clone__c objClone = new CPQ_Product_Clone__c();
    objClone.Event_Series__c ='World of Concrete';
    objClone.Cloned__c = false;
    objClone.Source_Event_Edition__c = 'World of Concrete 2017';
    objClone.Target_Event_Edition__c = 'World of Concrete 2018';
    insert objClone;

    PageReference pgRef = Page.PrdCloneWithRelated; //Create Page Reference - 'Appt_New' is the name of Page
    Test.setCurrentPage(pgRef); //Set the page for Test Method
    ApexPages.currentPage().getParameters().put('CPC_Id', objClone.Id);//Pass Id to page
    CloneEventProducts_Ctrl cloneProd = new CloneEventProducts_Ctrl();

    cloneProd.dynamicQuery('product2');
    cloneProd.clonePrdwithRealted();
    cloneProd.deleteRecord();
    cloneProd.cancelRecord();

    Test.StopTest();
    }
}
2

The list lstPrd is empty, therefore it is throwing this error. Add a null check in the class for the list lstPrd because it is being used in your dynamic query.

List<Product2> lstPrd = [SELECT Id, Name ,Product_Brand__c, 
Event_Edition_Pool__c FROM product2 WHERE Product_Brand__c=: oTargetEE.Name AND Cloned__c = true]; 
query = 'SELECT id FROM '+ typeName +' WHERE Product__c IN :lstPrd limit 5000';   
if(lstPrd != null && lstPrd.size() > 0){
    lstofSobj = Database.query(query);
}

Also, before using lstofSobj, add validation for null check. In the test class, ensure that lstPrd is not null to cover those lines and create the data accordingly.

Let me know if it helps.

  • Do mark it useful. – Ankita Jul 10 '17 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.