+ Start a Discussion
Kathir DevanKathir Devan 

why record i snot saved...

hi dear,

my functionality is When i click the button diff level of record is saved.my err is attempt to dereference a null object.This err when i add return null; with in page reffrnc save() not getting above err but record is not saved here my code below please find why this happen and what should i do...

public PageReference Save()
{
List<level1s__c> selectLevel1 = new List<level1s__c>();

    //this.stdController.save();
    

    /////////// LEVEL1 ///////////////////
   List<level1s__c> selectedLevel1 = new List<level1s__c>(); 
    
    for(Level1sClass cCon: getList1Details())
    {
         system.debug('cCon'+cCon.selected);
        if(cCon.selected == true)
        {
            system.debug('firstCCCCCCCCCC:'+cCon.lev1);
            selectedLevel1.add(cCon.lev1);
        }
    }           
     
    Level1__c[] levl1= [Select Id from Level1__c where Account__c=: ApexPages.currentPage().getParameters().get('id')]; 
    delete levl1; 
    if(selectedLevel1 != null)
    {     
        for(level1s__c con : selectedLevel1)
        {
            system.debug('CCCCCCCCCC:'+con+'\n');
            string acctid =ApexPages.currentPage().getParameters().get('id');
            List<Level1__c> lvl1obj= new  Level1__c[0];
            lvl1obj.add(new Level1__c(Name='Level1',Account__c=acctid,cLevel1__c=con.id));
            insert lvl1obj;
    
        }
    }    
    ///////////////// LEVEL2 //////////////////////
   List<level2s__c> selectedLevel2 = new List<level2s__c>(); 
    
    for(Level2sClass cCon: getList2Details() )
    {
         system.debug('cCon'+cCon.selected);
        if(cCon.selected == true)
        {
            system.debug('firstCCCCCCCCCC:'+cCon.lev2);
            selectedLevel2.add(cCon.lev2);
        }
    }           
     
    Level2__c[] levl2= [Select Id from Level2__c where Account__c=: ApexPages.currentPage().getParameters().get('id')]; 
    delete levl1; 
    if(selectedLevel2 != null)
    {     
        for(level2s__c con : selectedLevel2)
        {
            system.debug('CCCCCCCCCC:'+con+'\n');
            string acctid =ApexPages.currentPage().getParameters().get('id');
            List<Level2__c> lvl2obj= new  Level2__c[0];
            lvl2obj.add(new Level2__c(Name='Level2',Account__c=acctid,cLevel2__c=con.id));
            insert lvl2obj;
    
        }
    }    
  
    return null;
    
}