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
John NeffJohn Neff 

apex:commandButton throwing Attempt to de-reference a null object error - help!?

Hello, 

I have added inlineEditSupport and a commandButton to my vf page, however when testing my command button I am getting the error: 
 
Attempt to de-reference a null object
Error is in expression '{!saveCS}' in component <apex:commandButton> in page r2m_contracts_out: Class.R2MPipeLineController.saveCS: line 15, column 1

An unexpected error has occurred. Your development organization has been notified.
Here is my controller: 
 
public class R2MPipeLineController{

    public List<Opportunity> listOfLive {get; set;}
    public List<Opportunity> listOfViability {get; set;}
    public List<Opportunity> listOfLaunchPad {get; set;}
    public List<Opportunity> listOfContractSent {get; set;}
    public List<Opportunity> listOfQualified {get; set;}
    public Opportunity Live {get; set;}
    public Opportunity Viability {get; set;}
    public Opportunity LaunchPad {get; set;}
    public Opportunity ContractSent {get; set;}
    public Opportunity Qualified {get; set;}
    
    public PageReference saveCS(){
    UPDATE ContractSent;
    return null;
    }
    
public R2MPipeLineController() {
    listofLive = [Select id, name, CreatedDate, Company_Name__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Live' ORDER BY Weeks_Live__c DESC];
    listOfViability = [Select id, name, CreatedDate, Company_Name__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Viability' ORDER BY Days_Since_Last_Modified__c DESC];
    listOfLaunchPad = [Select id, name, CreatedDate, Company_Name__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Launch Pad' ORDER BY Days_Since_Last_Modified__c DESC];
    listOfContractSent = [Select id, name, CreatedDate, Company_Name__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c, Contract_Age__c from Opportunity WHERE StageName = 'Contract Sent' ORDER BY Contract_Age__c ASC];
    listOfQualified = [Select id, name, CreatedDate, Company_Name__c, Vertical__c, Weeks_Live__c, Days_Since_Last_Modified__c, Contract_SENT__c, NextStep, LeadSource, Probability, Spend_Last_Week__c, Spend_Last_30_Days__c, Owner_Name__c, Revenue_All_Time__c from Opportunity WHERE StageName = 'Qualified' ORDER BY Probability DESC]; 
}
}

and here is the pageblock that is yielding the error: 
 
<apex:form >
             <apex:pageBlock title="Contracts Out - Todd Deluke" mode="inlineedit">
                         <table cellpadding="5" style="border-collapse: collapse;table-layout:fixed" width="1100" border="1" >
                
                <apex:variable var="count" value="{!0}"/>
                <apex:repeat value="{!listOfContractSent}" var="cs">
                                                                         <tr style="display:{!IF(cs.Owner_Name__c ='Todd DeLuke', 'table-row', 'none')}">
                                  
                           
                             <td width="50">
                             <apex:outputField value="{!cs.Probability}" >
                                     <apex:inlineEditSupport event="ondblclick" showOnEdit="saveButton, cancelButton" />
                                </apex:outputField>
                            </td>
                          
                          
                        </tr>
                                                          </apex:repeat>
            </table>
            <apex:commandButton id="update" action="{!saveCS}" value="Update Opptys" 
        styleclass="updateButton"/> 
            </apex:pageBlock>
            </apex:form>

I am new to this type of functionality - and I can't seem to figure out what is causing the error.  Can anyone help?

Thanks in advance!

John


 
Best Answer chosen by John Neff
Mehul MakwanaMehul Makwana
This Error is occure because you are trying  to perform action on Null.

You are using ContractSent inside saveCS button, but as per your code there are nothing inside the ContractSent.

Instead of updating ContractSent try to update listOfContractSent.

Let me know if its work for you.

All Answers

Mehul MakwanaMehul Makwana
This Error is occure because you are trying  to perform action on Null.

You are using ContractSent inside saveCS button, but as per your code there are nothing inside the ContractSent.

Instead of updating ContractSent try to update listOfContractSent.

Let me know if its work for you.
This was selected as the best answer
John NeffJohn Neff

Thank you Mehul, I will give this a try. 
 

Will this allow me to update just a single record however, or will it update all opportunities in the list?

John NeffJohn Neff
it worked!  Thank you so much Mehul!