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
Shree KShree K 

Trying to pass Record Id of current Vf page to another Vf Page, getting error for controller

Hi all,
In first VF page I am getting basic Lead information and I want to pass that information to another VF page which will have detailed information about the Lead. Now after click on Save button I need to pass that record information and then add more info and save that Lead.

I am facing problem with the controller

Below is my VF page code and Controller

VFpage Code:

<apex:page controller="myLeadController">
    <apex:sectionHeader title="New Lead Page" />
    <apex:form >
        <apex:pageBlock title="Create a New Lead">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>        
            <apex:pageBlockSection title="Lead Information">
                <apex:inputField id="firstName" value="{!Lead.FirstName}"/>
                <apex:inputField id="lastName" value="{!Lead.LastName}"/>
                <apex:inputField id="companyName" value="{!Lead.Company}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:

public class myLeadController {
    
    Lead lead;

    public Lead getLead() {
        if(lead == null) lead = new Lead();
        return lead;
    }
    
    public PageReference save() {
        // Add the lead to the database. 
        insert lead;
        // Send the user to the detail page for the new lead.
       // need to pass the record id to Thankyou Page
        PageReference leadPage = new ApexPages.Thankyou
        leadPage.setRedirect(true);
        return leadPage;
    }

}


 
Best Answer chosen by Shree K
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help you
public class myLeadController {
    
    Lead lead;

    public Lead getLead() {
        if(lead == null) lead = new Lead();
        return lead;
    }
    
    public PageReference save() {
        insert lead;
		return new PageReference('/apex/Thankyou?id='+lead.id);
    }

}

Please let us know if this will help you

Thanks
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help you
public class myLeadController {
    
    Lead lead;

    public Lead getLead() {
        if(lead == null) lead = new Lead();
        return lead;
    }
    
    public PageReference save() {
        insert lead;
		return new PageReference('/apex/Thankyou?id='+lead.id);
    }

}

Please let us know if this will help you

Thanks
Amit Chaudhary
This was selected as the best answer
Shree KShree K
Thank you Amit Chaudary,
up to my knowledge, your code mean, record id passed through URL ,is it? So can you help how to pass the Record Id if two  VF pages using a shared controller
Amit Chaudhary 8Amit Chaudhary 8
If you are using same controller for two page then you can direcly access the id by Lead.ID or you can use ApexPages.currentPage().getParameters().get('id')  in another page. Please let us know if this will help u