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
Sujata Tiwari 3Sujata Tiwari 3 

When click on Save, my lead records should creates.

Hi All,

I am giving inputs at run time, after hitting save button my records should get saved and display the record detail page. Here, I am using Standardcontroller = 'Lead'
<apex:page standardController="Lead" extensions="TrialReController" sidebar="false" showHeader="false">
<apex:form id="frm">
<apex:pageblock>
 <apex:pageblockButtons location="bottom">  
    <apex:commandButton value="Save" action="{!Save}" rendered="true" />
</apex:pageblockButtons>
<apex:pageblocksection columns="1">
    <apex:inputfield value="{!lead.FirstName}"/>
    <apex:inputfield value="{!lead.lastname}"/>
    <apex:inputfield value="{!lead.Phone}"/>
    <apex:inputfield value="{!lead.Email}"/> 
    <apex:inputfield value="{!lead.Account__c}"/> 
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
</apex:page>
********************************************************
public class TrialReController {
    public boolean x{get;set;}
    public boolean y{get;set;}
    public Lead lead{get;set;}
    public TrialReController(ApexPages.StandardController controller) {
        Lead lead = new Lead();
    }
    public void Save(){
        insert Lead;     //used upsert also, still not working
        //return new PageReference('/'+Lead.Id);
       }
}

I am not able to save my records its throwing error :
Attempt to de-reference a null object
Error is in expression '{!Save}' in component <apex:commandButton> in page trialredesign: Class.TrialReController.Save: line 29, column 1

Many many thanks for your help..!!
Ayush TripathiAyush Tripathi
Hi the error is inside your constructor replace it
 
lead = new Lead();

Moreover ensure all the required fields are represented I think you missed Company

 
Ayush TripathiAyush Tripathi
Hi Sujata

Is your query solved.if yes mark this thread closed.