function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
App DevelopmentApp Development 

Getting error while inserting test data in test class...

I have developed below test class but not getting why i am getting below error,

System.NullPointerException: Attempt to de-reference a null object..
the id i am passing has having the value..any suggestion?

apex class:

public class GSDPartnerCloneWithSkillsController {

    public ApexPages.StandardController controller {get; set;}
    public GSD_Partner__c GSDP {get;set;}
    public ID newRecordId {get;set;}
    public Id OldGSDResourceId {get;set;}
    public Id NewGSDResourceId {get;set;}

    
    public GSDPartnerCloneWithSkillsController(ApexPages.StandardController controller) {

        this.controller = controller;
        GSDP = (GSD_Partner__c)controller.getRecord();

    }
    
    public PageReference cloneWithItems() {

         Savepoint sp = Database.setSavepoint();
         GSD_Partner__c newGSDP;

         try {
         
             //GSDP = (GSD_Partner__c) GSDDataUtility.getObject('GSD_Partner__c', GSDP.id);
             List<GSD_Partner__c> InsertGSDPList = new List<GSD_Partner__c>();
             List<GSD_Partner__c> GSDPList = [SELECT supervisor__c,Queue_Suffix__c,case_exchange_identifier__c,quota_factor__c,minimum_assignments_monthly__c,open_all_hours__c,account__c,country_iso__c,notes__c,portfolio__c,maximum_assignments_daily__c,createdbyid,lastmodifieddate,id,phone__c,portal_user_identifier__c,last_daily_counter_reset__c,logistics_badge_id__c,name,isdeleted,queue__c,resource__c,systemmodstamp,provider_type__c,last_monthly_counter_reset__c,does_diagnosis__c,email__c,send_case_exchange_reminders__c,mru_code__c,createddate,can_see_quotes__c,ownerid,assignment_counter_daily__c,country_name__c,active__c,case_exchange_enabled__c,assignment_counter_monthly__c,does_own_logistics_and_parts__c,engagement_method__c,maximum_assignments_monthly__c,lastmodifiedbyid,currencyisocode,commitment_levels__c FROM GSD_Partner__c WHERE Id = :GSDP.id];
             for(GSD_Partner__c GSDP : GSDPList ){
                 newGSDP = GSDP.clone(false);
                 newGSDP.Queue_Suffix__c = 'Enter Unique value';
                 InsertGSDPList.add(newGSDP);
             } 
             insert InsertGSDPList;

             if(!InsertGSDPList.isEmpty()){
                 newRecordId = InsertGSDPList[0].id;
             }
           
             GSD_Resource__c OldGSDResource = [select id from  GSD_Resource__c where Partner__c = :GSDP.id limit 1];
             OldGSDResourceId = OldGSDResource.id;
             system.debug('OldGSDResourceId :'+OldGSDResourceId );
             
             GSD_Resource__c NewGSDResource = [select id from  GSD_Resource__c where Partner__c = :newRecordId  limit 1];
             NewGSDResourceId = NewGSDResource.id;
             system.debug('NewGSDResourceId :'+NewGSDResourceId);
             
             CLoneGSDResourceLang();
             CLoneGSDResourceNon();
             CLoneGSDResourcePPS();
             CLoneGSDResourcePMaster();
             CLoneGSDResourceServices();
             CLoneGSDResourceTech();

         } catch (Exception e){
            Database.rollback(sp);
            ApexPages.addMessages(e);
            return null;
         }

        return new PageReference('/'+newGSDP.id+'/e?retURL=%2F'+newGSDP.id);
    }
    
    public void CLoneGSDResourceLang(){
    
        List<GSD_Resource_Skills_mapping__c> InsertnewSkillList = new List<GSD_Resource_Skills_mapping__c>();
        List<GSD_Resource_Skills_mapping__c> SkillsList = [select id,Skill_Name__c,Skill_Category__c,Standard__c,Stand_By__c,Non_Product_Skill_Level__c,Web_App_Resp_Created_Dt__c,Web_App_Resp_Modified_Dt__c,Responsibility_Skill_Level__c,Web_App_Employee_Id__c,Web_App_ID__c,Web_App_Skill_Id__c from GSD_Resource_Skills_mapping__c where Skill_Category__c = :Label.GSDResourceLang and Resource_ID__c = :OldGSDResourceId];  
        if(!SkillsList.isEmpty()){
            for (GSD_Resource_Skills_mapping__c GSDrskill : SkillsList) {
                  GSD_Resource_Skills_mapping__c newGSDrskill  = GSDrskill.clone(false);
                  newGSDrskill.Resource_ID__c = NewGSDResourceId;
                  InsertnewSkillList.add(newGSDrskill);
            }
            system.debug('InsertnewSkillList:'+InsertnewSkillList);
            insert InsertnewSkillList ;
        }
    }
    
    public void CLoneGSDResourceNon(){
    
        List<GSD_Resource_Skills_mapping__c> InsertnewSkillList = new List<GSD_Resource_Skills_mapping__c>();
        List<GSD_Resource_Skills_mapping__c> SkillsList = [select id,Skill_Name__c,Skill_Category__c,Standard__c,Stand_By__c,Non_Product_Skill_Level__c,Web_App_Resp_Created_Dt__c,Web_App_Resp_Modified_Dt__c,Responsibility_Skill_Level__c,Web_App_Employee_Id__c,Web_App_ID__c,Web_App_Skill_Id__c from GSD_Resource_Skills_mapping__c where Skill_Category__c = :Label.GSDResourceNon and Resource_ID__c = :OldGSDResourceId];  
        if(!SkillsList.isEmpty()){
            for (GSD_Resource_Skills_mapping__c GSDrskill : SkillsList) {
                  GSD_Resource_Skills_mapping__c newGSDrskill  = GSDrskill.clone(false);
                  newGSDrskill.Resource_ID__c = NewGSDResourceId;
                  InsertnewSkillList.add(newGSDrskill);
            }
            system.debug('InsertnewSkillList:'+InsertnewSkillList);
            insert InsertnewSkillList ;
        }
    }
    
    public void CLoneGSDResourcePPS(){
    
        List<GSD_Resource_Skills_mapping__c> InsertnewSkillList = new List<GSD_Resource_Skills_mapping__c>();
        List<GSD_Resource_Skills_mapping__c> SkillsList = [select id,Skill_Name__c,Skill_Category__c,Standard__c,Stand_By__c,Non_Product_Skill_Level__c,Web_App_Resp_Created_Dt__c,Web_App_Resp_Modified_Dt__c,Responsibility_Skill_Level__c,Web_App_Employee_Id__c,Web_App_ID__c,Web_App_Skill_Id__c from GSD_Resource_Skills_mapping__c where Skill_Category__c = :Label.GSDResourcePPS and Resource_ID__c = :OldGSDResourceId];  
        if(!SkillsList.isEmpty()){
            for (GSD_Resource_Skills_mapping__c GSDrskill : SkillsList) {
                  GSD_Resource_Skills_mapping__c newGSDrskill  = GSDrskill.clone(false);
                  newGSDrskill.Resource_ID__c = NewGSDResourceId;
                  InsertnewSkillList.add(newGSDrskill);
            }
            system.debug('InsertnewSkillList:'+InsertnewSkillList);
            insert InsertnewSkillList ;
        }
    }
    
    public void CLoneGSDResourcePMaster(){
    
        List<GSD_Resource_Skills_mapping__c> InsertnewSkillList = new List<GSD_Resource_Skills_mapping__c>();
        List<GSD_Resource_Skills_mapping__c> SkillsList = [SELECT Id, Name, Skill_Name__r.Name, Responsibility_Skill_Level__c, Skill_Name__r.Product_Description__c, Skill_Name__r.Portfolio__c FROM GSD_Resource_Skills_mapping__c WHERE Resource_ID__c = :OldGSDResourceId AND Skill_Category__c =: Label.GSDResourcePMaster ];
        if(!SkillsList.isEmpty()){
            for (GSD_Resource_Skills_mapping__c GSDrskill : SkillsList) {
                  GSD_Resource_Skills_mapping__c newGSDrskill  = GSDrskill.clone(false);
                  newGSDrskill.Resource_ID__c = NewGSDResourceId;
                  InsertnewSkillList.add(newGSDrskill);
            }
            system.debug('InsertnewSkillList:'+InsertnewSkillList);
            insert InsertnewSkillList ;
        }
    }
    
    public void CLoneGSDResourceServices(){
    
        List<GSD_Resource_Skills_mapping__c> InsertnewSkillList = new List<GSD_Resource_Skills_mapping__c>();
        List<GSD_Resource_Skills_mapping__c> SkillsList = [SELECT Id, Name, Skill_Name__r.Name, Responsibility_Skill_Level__c, Skill_Name__r.Product_Description__c, Skill_Name__r.Portfolio__c, Skill_Name__r.Support_Activity__c,Standard__c, Stand_By__c FROM GSD_Resource_Skills_mapping__c WHERE Resource_ID__c = :OldGSDResourceId AND Skill_Category__c ='Services' ];
        if(!SkillsList.isEmpty()){
            for (GSD_Resource_Skills_mapping__c GSDrskill : SkillsList) {
                  GSD_Resource_Skills_mapping__c newGSDrskill  = GSDrskill.clone(false);
                  newGSDrskill.Resource_ID__c = NewGSDResourceId;
                  InsertnewSkillList.add(newGSDrskill);
            }
            system.debug('InsertnewSkillList:'+InsertnewSkillList);
            insert InsertnewSkillList ;
        }
    }
    
    public void CLoneGSDResourceTech(){
    
        List<GSD_Resource_Skills_mapping__c> InsertnewSkillList = new List<GSD_Resource_Skills_mapping__c>();
        List<GSD_Resource_Skills_mapping__c> SkillsList = [SELECT Id, Name, Responsibility_Skill_Level__c, Skill_Name__r.Name, Skill_Name__r.Technologies_Name__c FROM GSD_Resource_Skills_mapping__c WHERE Resource_ID__c =:OldGSDResourceId  AND Skill_Category__c =: Label.GSDResourceTech ];
        if(!SkillsList.isEmpty()){
            for (GSD_Resource_Skills_mapping__c GSDrskill : SkillsList) {
                  GSD_Resource_Skills_mapping__c newGSDrskill  = GSDrskill.clone(false);
                  newGSDrskill.Resource_ID__c = NewGSDResourceId;
                  InsertnewSkillList.add(newGSDrskill);
            }
            system.debug('InsertnewSkillList:'+InsertnewSkillList);
            insert InsertnewSkillList ;
        }
    }
}


test class:

@isTest
public class GSDPartnerCloneWithSkillsController_Test{

    private testMethod static void TestMethod1(){
    
        Global_Config__c GCObj=new Global_Config__c (CPQ_Mute_Validation_Rule__c=false,DPlus_Mute_Validation_Rule__c=true,Mute_Triggers__c=true,
                                                        Mute_Validation_Rule__c=true,Mute_Workflow_Rule__c=true,Name='GSD');
      
        insert GCOBJ;
        
                
        HPTriggerFrameworkObjectMapping__c PartCSObj= new HPTriggerFrameworkObjectMapping__c(name='GSD_Partner__c',DispatcherCalssName__c='GSDPartnerProfile');
        insert PartCSObj;
        
        HPTriggerFrameworkObjectMapping__c ResCSObj= new HPTriggerFrameworkObjectMapping__c(name='GSD_Resource__c',DispatcherCalssName__c='GSDNewResource');
        insert ResCSObj;
        
        HPTriggerFrameworkObjectMapping__c SKMObj= new HPTriggerFrameworkObjectMapping__c(name='GSD_Skill_Master__c',DispatcherCalssName__c='GSDSKillMaster');
        insert SKMObj;
        
        HPTriggerFrameworkObjectMapping__c RSKMMObj= new HPTriggerFrameworkObjectMapping__c(name='GSD_Resource_Skills_mapping__c',DispatcherCalssName__c='GSDResourceSkillMapping');
        insert RSKMMObj;
        
        Profile fsmManagerPro= [Select Id, Name from Profile where Name = 'GSD FSM Sub Regional Resource' limit 1];        
        
        User fsmProfileUser= new User( profileId = fsmManagerPro.id, username = 'testemail22@hp.com', email = 'testemail22@hp.com', 
                    emailencodingkey = 'UTF-8', localesidkey = 'en_US',languagelocalekey = 'en_US', timezonesidkey = 'America/Los_Angeles',
                    alias='cspu22', lastname='lastname', Adoption_Role_Type__c = 'IT', Email_Address__c = 'testemail3@hp.com',Legacy_Employee_Ref__c='12345', 
                    RMR_Primary_Operational_Role__c = 'Solution Architect');
        
        insert fsmProfileUser;
        
        World_Region__c WR=new World_Region__c();
        wr.Name='US';
        insert WR;
        
        
        
        RecordType rt = [select id,Name from RecordType where SobjectType='Account' and Name='Partner' Limit 1];
        account aObj=new account(name='Account1',RecordTypeId=rt.id,MDCP_Business_Relationship_ID__c = 'abc',World_Region1__c=wr.id);
        insert aObj;
        
        PageReference pref = Page.GSDpartnerClone;
        Test.setCurrentPage(pref);
        
        Gsd_partner__c pObj=new Gsd_partner__c(name='partnerEx1',Account__c = aObj.id,Phone__c='9739',Email__c='xyz@hp.com',Queue_Suffix__c='queue1');
        insert pObj;
        
        Apexpages.StandardController sc = new Apexpages.standardController(pObj);
        GSDPartnerCloneWithSkillsController PCObj=new GSDPartnerCloneWithSkillsController(sc);
        
        Test.startTest();
        
        GSD_Resource__c oldresource = [Select Id From GSD_Resource__c  where Partner__c = :pObj.id];
        system.debug('oldresource :'+oldresource);
        
        GSD_Skill_Master__c SMObj= new GSD_Skill_Master__c();
        SMObj.Skill_Name__c = 'testskillname';
        SMObj.Skill_Type__c='Non-Product';
        SMObj.Skill_Category__c='Language';
        SMObj.Name='German';
        insert SMObj;
        
        GSD_Resource_Skills_mapping__c RSMObj = new GSD_Resource_Skills_mapping__c();
        RSMObj.Skill_Name__c=SMObj.id;
        RSMObj.Standard__c=true;
        RSMObj.Stand_By__c=true;
        RSMObj.Non_Product_Skill_Level__c='0';
        RSMObj.Responsibility_Skill_Level__c='3';
        RSMObj.Skill_Category__c='Language';
        RSMObj.Resource_ID__c= oldresource.id;
        system.debug('RSMObj :'+RSMObj);
        insert RSMObj;
        
        PageReference ref = PCObj.cloneWithItems();
        
        
        PageReference redir = new PageReference('/'+PCObj.newRecordId+'/e?retURL=%2F'+PCObj.newRecordId);
        System.assertEquals(ref.getUrl(),redir.getUrl());
        
        List<GSD_Resource__c > newItems = [Select Id From GSD_Resource__c  where Partner__c = :PCObj.newRecordId];
        System.assertEquals(newItems.size(),1);
        
        List<GSD_Partner_Profile_Linkage__c> newItems1 = [Select Id From GSD_Partner_Profile_Linkage__c  where Accessible_To__c = :PCObj.newRecordId];
        System.assertEquals(newItems1.size(),1);
        
        Test.stopTest();
        

    }
    
}
Jamz_2010Jamz_2010
Hi,

Would you please post the stack trace of the error?

Cheers,

James