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
Sylvie SerpletSylvie Serplet 

VF page modified with slds markups return an "Attempt to de-reference a null object" error when trying to save

Hi,
I have a VF page running in Lightning that save and cancel perfectly. I have modified it with slds markups to look likes Lightning and now when I try to save the record I got an error message "Attempt to de-reference a null object".The cancel button still works.

Any thought?

Shorten codes are as follow:

VF Page that works
<apex:page standardcontroller="Fact_Finder__c" extensions="FFFormCtrExt" showHeader="false" sidebar="false" >
<style type="text/css">
 .buttonsubmit {
  width: 200px;
  font-size: 150% !important;
  background:#E9EEF2 !important;
  }
.buttoncancel {
  width: 200px;
  font-size: 150% !important;
  background:#E9EEF2 !important;
  } 
 .pbHeader {
  font-size: 150%;
  background-color:#E9EEF2 !important; 
  border-radius: 5px;
 }
 .bPageBlock .pbTitle {
  width: 100%;    
  text-align: center; 
}   
</style> 
 <apex:form style="width:800px; text-align:center; margin:auto;" enctype="multipart/form-data" > 
  <apex:pageMessages />
   <apex:pageBlock id="block" title="Accident & Illness Fact Finder" >        
     <apex:pageBlockButtons location="bottom" > 
             <apex:commandButton action="{!saveFF}" value="Submit" styleclass="buttonsubmit" reRender="block" > 
               <apex:param name="p" value="{!$CurrentPage.Name}" assignTo="{!CurrentPageName}" />
            </apex:commandButton>                         
                        <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" styleClass="buttoncancel" />
                </apex:pageBlockButtons> 
<style>
 body .bPageBlock .pbBody .black .pbSubheader{
  background-color:#000000;
  font-size: 120%;  
  border-radius: 5px; 
}  
.bPageBlock .detailList  
{
  border-bottom:1px solid #000000;
  border-right:1px solid #000000;
  border-left:1px solid #000000;
  border-radius: 5px;  
}
 input {width: 95%;} 
 output {width: 95%;}
 textarea {
  width: 95%;
  height: 150px; 
 }  
 label {
  float: left;
  width: 150px;
  margin-left: 20px;
  text-align: left;
 }
 .radioB input, .radioB label{
   float:none;
   display:inline;
   width: 30px;
 }      
</style>              

    <apex:outputPanel styleClass="black" layout="block" >
              <apex:pageblocksection columns="1" >                         
                    <apex:inputfield value="{!FF.Opportunity_Name__c}" />            
                    <apex:inputfield value="{!FF.Client_Name__c}" />
                    <apex:inputfield value="{!FF.Date__c}" />                  
                    <apex:selectRadio value="{!FF.Attached_to__c}" styleclass="radioB" style="width:350px;" layout="pageDirection" > 
                      <apex:selectOption itemValue="Business Pack" itemlabel="Business Pack" />
                      <apex:selectOption itemValue="Farm Pack" itemlabel="Farm Pack" />
                    </apex:selectRadio>                                                 
     </apex:pageblocksection>  
</apex:outputPanel>         
    
    <apex:outputPanel styleClass="black" layout="block">
      <apex:pageblocksection title="Other Information" showheader="true" collapsible="true" columns="1">
                   <apex:actionSupport event="onchange" action="{!readUser}" />
          <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Prepared by"/>
                    <apex:inputField value="{!FF.Owner__c}"/>            
          </apex:pageBlockSectionItem>
                    <apex:inputfield value="{!FF.Notes__c}"/>
            </apex:pageblocksection>                 
     </apex:outputPanel>
     </apex:pageBlock>
  </apex:form>         
</apex:page>

VF Page that does not work
apex:page standardcontroller="Fact_Finder__c" extensions="FFFormCtrExt" standardStylesheets="false" applyBodyTag="false" >
 
 <apex:form >
  <apex:slds />
   <div class="slds-scope">

 <div class="slds-container--large slds-align_absolute-center">
  <div class="slds-page-header">
       <div class="slds-media__body">
            <h1 class="slds-page-header__title slds-align-middle">Accident and Illness Fact Finder</h1>
        </div>
  </div>
 </div> 

 <div class="slds-form slds-form_compound">
<fieldset class="slds-box slds-theme--default slds-container--medium slds-align_absolute-center">  

   <div class="slds-form-element">
   <div class="slds-form-element__group">
        <div class="slds-form-element__row">
          <div class="slds-form-element slds-size_1-of-2">
  <label class="slds-form-element__label" for="text-input-01">Opportunity Name</label>
         <apex:outputfield value="{!FF.Opportunity_Name__c}" styleClass="slds-input"/> 
         </div>             
<div class="slds-form-element slds-size_1-of-2">
  <label class="slds-form-element__label" for="text-input-01">Client Name</label>
       <apex:outputfield value="{!FF.Client_Name__c}" styleClass="slds-input"/>     
       </div>  
  </div> 
</div>
</div>
<div class="slds-form-element">
<div class="slds-form-element__group">
        <div class="slds-form-element__row">
          <div class="slds-form-element slds-size_1-of-2">
      <label class="slds-form-element__label" for="text-input-01">Date</label>
      <apex:inputfield value="{!FF.Date__c}" styleClass="slds-input"/>    
</div>
<div class="slds-form-element slds-size_1-of-2">
  <legend class="slds-form-element__legend slds-form-element__label">Attached to</legend>
  <apex:selectRadio value="{!FF.Attached_to__c}" styleclass="slds-input" layout="pageDirection" >
                    <apex:selectOption itemValue="Business Pack" itemlabel="Business Pack" />
                    <apex:selectOption itemValue="Farm Pack" itemlabel="Farm Pack" />
   </apex:selectRadio>   
   </div>
   </div>
   </div> 
</div>  
</fieldset>
</div>  
 
<fieldset class="slds-box slds-theme--default slds-container--medium slds-align_absolute-center">
     <legend id="otherinfoform" class="slds-text-heading--medium slds-p-vertical--medium">Other Information</legend>    
   
           <apex:actionSupport event="onchange" action="{!readUser}" />   
 <div class="slds-form-element"> 
  <label class="slds-form-element__label" for="text-input-01">Prepared by</label>
   <div class="slds-form-element__control">
       <apex:outputfield value="{!FF.Owner__c}" styleClass="slds-input"/>
    </div>
 </div>
 
 <div class="slds-form-element">
  <label class="slds-form-element__label" for="text-input-01">Notes</label>
   <div class="slds-form-element__control">
       <apex:inputfield value="{!FF.Notes__c}" styleClass="slds-input"/>
   </div>
</div>                         

     </fieldset>  
 <div class="slds-m-top--small"></div>
 <div class="slds-p-horizontal--small slds-m-top--medium slds-size--1-of-1 slds-align--absolute-center">
            <apex:commandButton action="{!saveFF}" value="Submit" styleclass="slds-button slds-button--brand" > 
               <apex:param name="p" value="{!$CurrentPage.Name}" assignTo="{!CurrentPageName}" />
            </apex:commandButton>                         
            <apex:commandButton action="{!cancel}" value="Cancel" immediate="true" styleClass="slds-button slds-button--neutral" />
</div>

 </div>  
 </apex:form>  
</apex:page>

Same APEX Controller
public with sharing class FFFormCtrExt {

  public User selectedUser {get; set;}   
  public string CurrentPageName {get;set;}
 
  public Opportunity opp {get;set;}
  string recordId = ApexPages.currentPage().getParameters().get('recordId'); 
  public Fact_Finder__c FF {get; set;} 
  string FFId = ApexPages.currentPage().getParameters().get('FFId');   
 
     public FFFormCtrExt(ApexPages.StandardController controller) {    
      
       opp =  [SELECT Id, Name, ABN__c, ACN__c, Email__c, Phone__c, Address__c, Primary_Contact__c, Account.Name FROM Opportunity WHERE Id =:ApexPages.currentPage().getParameters().get('recordId')];      
   
       this.FF=(Fact_Finder__c)controller.getRecord();       
  
       FF.Opportunity_Name__c= recordId; 
            
       FF.Owner__c = UserInfo.getUserId();
       selectedUser = [ Select Id From User Where Id = :UserInfo.getUserId()];   
       
              
        } 
              
    public pageReference readUser()   {
        selectedUser = [ Select Id From User Where Id = :FF.Owner__c ];
        return null;      
    }      
                              
    public PageReference cancel(){   
     return new PageReference('/' + recordId);   
    }
    
    public PageReference saveFF() {           
      
      RecordType rt;             
      
            if(CurrentPageName == 'AccidentForm')   
            rt = [Select Id From RecordType Where DeveloperName = 'Accident_Illness' And sObjectType = 'Fact_Finder__c'];
        if(CurrentPageName == 'PIForm')   
            rt = [Select Id From RecordType Where DeveloperName = 'Professional_Indemnity' And sObjectType = 'Fact_Finder__c']; 
        if(CurrentPageName == 'GenericForm')   
            rt = [Select Id From RecordType Where DeveloperName = 'Generic' And sObjectType = 'Fact_Finder__c'];   
       
        FF.RecordTypeId = rt.Id;      
     
      
            insert (this.FF);           
        return new PageReference('/' + recordId); 
          
      }      
  }

Thanks,
Sylvie
Best Answer chosen by Sylvie Serplet
Sylvie SerpletSylvie Serplet
I have just to add the attribute rerender to the command button and it works fine now.

<apex:commandButton action="{!saveFF}" value="Submit" styleclass="slds-button slds-button--brand" reRender="block">

All Answers

Arun Prasath 5Arun Prasath 5
Hi Sylvie,

You've used 3 if conditions from the line 38 to 42. and assigned the record type id in FF.RecordTypeId.

The reported issue is due to Null value is assigning to the FF.RecordTypeId ie) the above condition doesn't satisfied.

And Please use 48th line inside Try block.

Thanks in Advance.
Sylvie SerpletSylvie Serplet
Hi Arun,
Thank you for your answer. Sorry but I do not understand what you mean. The if conditions works perfectly in the basic VF page the Record type id is allocated depending on the VF page name. But with the same page with SLDS markup it stop working and give me a null object error. It is exactly the same Apex class and VF page the only think that change is the SLDS styling. How can that impact the if condition?
Could you also please tell me what do you mean by use Try block?
Thanks,
Sylvie
 
Sylvie SerpletSylvie Serplet
I have just to add the attribute rerender to the command button and it works fine now.

<apex:commandButton action="{!saveFF}" value="Submit" styleclass="slds-button slds-button--brand" reRender="block">
This was selected as the best answer