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

What to do to Overcome the Error:Attempt to DeReference a null object

visual force page:

<apex:page standardController="Quotation__c" extensions="sendEmail1" sidebar="false">
<apex:sectionHeader title="Quotation Information Form" printUrl="{!$}&sfdc.override=1"/>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection title="Quotation Details" columns="1">  
                 <apex:outputField value="{!Quotation__c.Name}"/>
                <apex:outputField value="{!Quotation__c.To__c}"/>
               <apex:outputField value="{!Quotation__c.Address__c}"/>
               <apex:OutputField value="{!Quotation__c.Kind_Attn__c}"/>
               <apex:OutputField value="{!Quotation__c.Dear_Sir__c}"/>
               <apex:OutputField value="{!Quotation__c.Notes__c}"/>
               <apex:OutputField value="{!Quotation__c.Terms_and_Conditions__c}"/>
               <apex:OutputField value="{!Quotation__c.Items_Selected__c}"/>
               <!-- <apex:outputField value="{!Quotation__c.Items_Selected__r.Name}"/>
                <apex:outputField value="{!Quotation__c.}"/> -->

<apex:dataTable value="{!itemSelected}" var="fcst" width="100%" >
<apex:column width="8%" ><apex:facet name="header">Product</apex:facet><apex:outputLabel value="{!}" /></apex:column>
<apex:column width="8%"><apex:facet name="header">Item Description</apex:facet><apex:outputLabel value="{!fcst.Item_Description__c}" /></apex:column>
<apex:column width="8%"><apex:facet name="header">Unit Price</apex:facet><apex:outputLabel value="{!fcst.Unit_Price__c}" /></apex:column>
<apex:column width="8%"><apex:facet name="header">Quantity</apex:facet><apex:outputLabel value="{!fcst.Quantity__c}" /></apex:column>
<apex:column width="8%"><apex:facet name="header">Total Price</apex:facet><apex:outputLabel value="{!fcst.Total_Price__c}" /></apex:column>

<apex:commandButton value="send" action="{!send}"/>

Apex Controller:


public class sendEmail1
public Quotation__c quot;
public sendEmail1(ApexPages.StandardController controller)
 public sendEmail1()
 quot=[select Id,To__r.Email from Quotation__c where id=:ApexPages.currentPage().getParameters().get('id')];

public List<Items_Selected__c> getitemSelected ()
List<Items_Selected__c> ISRL =[select,Quantity__c,Item_Description__c,Unit_Price__c,Total_Price__c from Items_Selected__c where Quotation__c =: ApexPages.currentPage().getParameters().get('id')];
return ISRL;

public PageReference send()
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        PageReference pdf = Page.QuotePdf;
        Blob b = pdf.getContent();
        Messaging.EmailFileAttachment efa=new Messaging.EmailFileAttachment();
        String address=quot.To__r.Email;
        email.setToAddresses(new String[]{address});
        email.setFileAttachments(new Messaging.EmailFileAttachment[]{efa});
        Messaging.sendEmailResult[] r=Messaging.sendEmail(new Messaging.SingleEmailMessage[]{email});
        return null;


When the save Button is clicked,it is producing a Error as :ATTEMPT TO DEREFERENCE A NULL OBJECT.


Can i know where the problem had occured..


hi i got the same error i am still working on fixing it please let me if u got the answer. 


You should be able to tell where the error occurred from the debug log. If you need to, slap a bunch of debug statements in your code to help.


This error generally occurs when you try to reference a field or property on an object when that object is null. For example, if your quot variable is null, then trying to access the Id field, will give you this error.


In this case, it looks like your quot variable is not getting set. Since your page is based on a standard controller, the constructor that will be called in your extension class is the one that takes a standard controller. This constructor is empty, so the quot variable doesn't get set.