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
Kumar5Kumar5 

Tab Panel Upsert Method

Hello All,

I am creating Visual force page with tabpanel having two tabs contacts and opportunites. I want to  upsert the records using the id with first tab details.

Please help me with upsert method 

<apex:page Controller="panelController" showHeader="true">
<apex:form >
    <!-- Define Tab panel .css styles -->
    <style>
    .activeTab {background-color: #236FBD; color:blue; background-image:none}
    .inactiveTab { background-color: lightgrey; color:black; background-image:none}
    </style>
            
    <!-- Create Tab panel -->
    <apex:tabPanel switchType="client" selectedTab="name2" id="ContactTabPanel"
        tabClass="activeTab" inactiveTabClass="inactiveTab">
        <apex:tab label="One" name="name1" id="tabOne">
         <apex:pageBlock title="ContactDetails"> 
         <apex:inputField value="{!confields.name}"/>
         <apex:inputField value="{!confields.phone}"/>
         <apex:inputField value="{!confields.type}"/>
       
       <apex:inputField value="{!confields.phone}"/>
         <apex:inputField value="{!confields.email}"/>
        </apex:pageblock>
         <apex:commandButton value="save" action="{!saveRecord}"/>
        </apex:tab>
        <apex:tab label="Two" name="name2" id="tabTwo">
        
         <apex:pageBlock title="OpportunityDetails"> 
         <apex:inputField value="{!oppfields.name}"/>
         <apex:inputField value="{!oppfields.status}"/>
         <apex:inputField value="{!oppfields.date}"/>
       

        
        <apex:pageBlock title="contactdetails">
       <apex:inputField value="{!confields.citizenship__c}"/>
         <apex:inputField value="{!confields.alliance__c}"/>
        </apex:pageblock>
         <apex:commandButton value="save" action="{!saveRecord1}"/>
        </apex:tab>
        
         </apex:tab>
    </apex:tabPanel>
  </apex:form>
</apex:page>


Controllerpublic with sharing class panelController {

public Account accfields{get;set;}
public contact confields{get;set;}

public panelController(){
accfields=new Account();
confields=new Contact();
}
public PageReference saveRecord() {
    insert accfields;
    insert confields;
        return null;
    }
    
    Public PageReference SaveRecord1()
    {}
}

Thanks,
Kumar
 
Vishal_GuptaVishal_Gupta
Hi Kumar,

Please do the following changes in your code :
<apex:tabPanel switchType="client" selectedTab="name2" id="ContactTabPanel"
        tabClass="activeTab" inactiveTabClass="inactiveTab">
        <apex:tab label="One" name="name1" id="tabOne">
         <apex:actionRegion > 
         <apex:pageBlock title="ContactDetails"> 
         <apex:inputField value="{!confields.lastname}"/>
         <apex:inputField value="{!confields.phone}"/>
         <apex:inputField value="{!confields.type}"/>
       
       <apex:inputField value="{!confields.phone}"/>
         <apex:inputField value="{!confields.email}"/>
        </apex:pageblock>
         <apex:commandButton value="save" action="{!saveRecord}" reRender="test"/>
         </apex:actionRegion >
        </apex:tab>
        <apex:tab label="Two" name="name2" id="tabTwo">
        <apex:actionRegion >
         <apex:pageBlock title="OpportunityDetails"> 
         <apex:inputField value="{!oppfields.name}"/>
         <apex:inputField value="{!oppfields.status}"/>
         <apex:inputField value="{!oppfields.date}"/>
       </apex:pageBlock>
       
        <apex:pageBlock title="contactdetails">
        <apex:inputField value="{!confields.citizenship__c}"/>
         <apex:inputField value="{!confields.alliance__c}"/>
        </apex:pageblock>
         <apex:commandButton value="save" action="{!saveRecord1}" reRender="test"/>
         </apex:actionRegion >
        </apex:tab>
</apex:tabPanel>
public with sharing class panelController {

public Account accfields{get;set;}
public contact confields{get;set;}
public Opportunity oppfields{get;set;}

public panelController(){
accfields=new Account();
confields=new Contact();
oppfields = new Opportunity();
}

public void saveRecord()
 {
    upsert confields;
      
    }
    
    Public void SaveRecord1()
    {
           upsert confields;
           insert oppfields;
    }
}
Let me know if it will work for you.

Thanks,
Vishal

 
Kumar5Kumar5
It worked thank you
Vishal_GuptaVishal_Gupta
Hi Naresh,

If my previous response resolve your issue then mark it as best answer so it will help others in future.

Thanks,
Vishal