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
Money Care 7Money Care 7 

Record upsert in same record on lead object

Hi Guys

I have created 3 vf page based on lead object field.i am able to insert 1st page when i am inserting record in 2nd page its not working.how to upsert record in my page ...
SandhyaSandhya (Salesforce Developers) 
Hi,

Please refer below sample code.
 
public class MvcController {

    public PageReference previous() {
    PageReference pr=new PageReference('https://c.ap2.visual.force.com/apex/mvcPage');    
        return pr;
    }


   // public String previous { get; set; }
public Bottle__c bt{ get ; set ;}

Public MvcController(){
 bt =new Bottle__c();
 }

    public PageReference save() {      
 
        
        insert bt;
        PageReference pr=new PageReference('/' +bt.id);
        return pr;
        
    }
    
    public PageReference next1() 
    {
    
        return Page.mavcPage3;
        
    }

       public PageReference next() {     
        return Page.mvcPage2;      
        
    }


    public Decimal b_cost { get; set; }

    public Integer b_quant { get; set; }

    public String b_name { get; set; }

   
    
     public PageReference savennew() {
        insert bt;
     PageReference pr=new PageReference('https://c.ap2.visual.force.com/apex/mvcPage');
       //return pr;
        return pr;
    }
    public PageReference cancel() {  
    PageReference pr=new PageReference('https://c.ap2.visual.force.com/apex/mvcPage');   
        return pr;     
        
         
}
}
 
<apex:page controller="MvcController" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="next" action="{!next}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputText >Enter Bottle Name</apex:outputText>
<apex:inputField value="{!bt.Name}"/>
</apex:pageBlockSectionItem><br/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
 
<apex:page controller="MvcController" >
  <apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="next" action="{!next1}"/>
<apex:commandButton value="previous" action="{!previous}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputLabel >Enter Bottle Quantity</apex:outputLabel>
<apex:inputField value="{!bt.quantity__c}"/>
</apex:pageBlockSectionItem><br/>
<apex:pageBlockSectionItem >
<apex:outputLabel >Bottle Name    {!bt.Name} </apex:outputLabel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
 
<apex:page controller="MvcController" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!save}"/>
<apex:commandButton value="savennew" action="{!savennew}"/>
<apex:commandButton value="cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:pageBlockSectionItem >
<apex:outputText >Enter Bottle Cost</apex:outputText>
<apex:outputText value="{!bt.cost__c}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputText >Bottle Quantity</apex:outputText>
<apex:outputText value="{!bt.quantity__c}"/>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
 </apex:form>
</apex:page>

Hope this helps you!

If this helps you please mark it as solved.

Thanks and Regards
Sandhya