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
bouscalbouscal 

Set initial values for new lead apex page?

Have a process that requires creating both a Contact and a Lead, once the Contact page is saved the Lead page opens and don't want the user to have to type in the same info again.  Below is what I have and I'm passing the entered values in the URL '...?FirstName={!Contact.FirstName}... etc'.

When this page renders is shows the values but outside the fields that I need them saved to.  Suggestions?

 

apex:page standardController="Lead" sidebar="false" showHeader="false">
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock title="Sales Lead">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{! save}"/>
                <input type="button" value="Cancel" class="btn" onclick="window.parent.closepop();"/>
            </apex:pageBlockButtons>
      <apex:pageBlockSection title="Lead" collapsible="false" columns="1">
          <apex:inputField value="{!Lead.company}" />
          <apex:inputField value="{!Lead.firstname}">{!$CurrentPage.parameters.FirstName}</apex:inputField>
          <apex:inputField value="{!Lead.lastname}">{!$CurrentPage.parameters.LastName} </apex:inputField>
          <apex:inputField value="{!Lead.Product_Group__c}" required="True"/>
          <apex:inputField value="{!Lead.Phone}" />
          <apex:inputField value="{!Lead.Email}" />
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
Shiv ShankarShiv Shankar

One way which i sees to achieve this 

 

Actuely value we giveing inside 

 

<apex:inputField value="{!Lead.firstname}">

outside we are putting parameter value 

<apex:inputField value="{!Lead.firstname}">{!$CurrentPage.parameters.FirstName}

 

So i think first we shoud set the value in controller and than should show on VF Page. Like

 

//Controller class
public class LeadCustomController{
	public Lead newLead {get;set;}
	
	public LeadCustomController(){
		newLead = new Lead();
		newLead.firstName = ApexPages.currentPage().getParameters().get('FirstName');
		newLead.lastName = ApexPages.currentPage().getParameters().get('LastName');
	}
	
	public void customSave(){
		insert newLead;
	}
}

//VF page
apex:page standardController="Lead" sidebar="false" showHeader="false">
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock title="Sales Lead">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{! customSave}"/>
                <input type="button" value="Cancel" class="btn" onclick="window.parent.closepop();"/>
            </apex:pageBlockButtons>
      <apex:pageBlockSection title="Lead" collapsible="false" columns="1">
          <apex:inputField value="{!newLead.company}" />
          <apex:inputField value="{!newLead.firstname}"></apex:inputField>
          <apex:inputField value="{!newLead.lastname}"> </apex:inputField>
          <apex:inputField value="{!newLead.Product_Group__c}" required="True"/>
          <apex:inputField value="{!newLead.Phone}" />
          <apex:inputField value="{!newLead.Email}" />
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

 

 

 

 

All Answers

Shiv ShankarShiv Shankar

One way which i sees to achieve this 

 

Actuely value we giveing inside 

 

<apex:inputField value="{!Lead.firstname}">

outside we are putting parameter value 

<apex:inputField value="{!Lead.firstname}">{!$CurrentPage.parameters.FirstName}

 

So i think first we shoud set the value in controller and than should show on VF Page. Like

 

//Controller class
public class LeadCustomController{
	public Lead newLead {get;set;}
	
	public LeadCustomController(){
		newLead = new Lead();
		newLead.firstName = ApexPages.currentPage().getParameters().get('FirstName');
		newLead.lastName = ApexPages.currentPage().getParameters().get('LastName');
	}
	
	public void customSave(){
		insert newLead;
	}
}

//VF page
apex:page standardController="Lead" sidebar="false" showHeader="false">
    <apex:form >
        <apex:pageMessages />
        <apex:pageBlock title="Sales Lead">
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{! customSave}"/>
                <input type="button" value="Cancel" class="btn" onclick="window.parent.closepop();"/>
            </apex:pageBlockButtons>
      <apex:pageBlockSection title="Lead" collapsible="false" columns="1">
          <apex:inputField value="{!newLead.company}" />
          <apex:inputField value="{!newLead.firstname}"></apex:inputField>
          <apex:inputField value="{!newLead.lastname}"> </apex:inputField>
          <apex:inputField value="{!newLead.Product_Group__c}" required="True"/>
          <apex:inputField value="{!newLead.Phone}" />
          <apex:inputField value="{!newLead.Email}" />
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 

 

 

 

 

This was selected as the best answer
bouscalbouscal

Thank you Shiv, got me headed in the right direction.  Had to adjust a couple lines in the apex page.