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
vijay aithavijay aitha 

how to save two different object in one page using extension controller

Hii,
how to save two different object records in one visualforce page using extension controller

Thank you.
Akshay_DhimanAkshay_Dhiman
Hi Vijay,
There cannot be more than one standard controller in a VF page but can have multiple extension controllers for a page.
One way what i can suggest for the requirement you have is establish relationship in between the two objects, which will help you traversing to the data of another object.
I think this example is perfect for your requirement :

Vf Page
<apex:page controller="myController">
<apex:pageblock>
    <apex:pageblockButtons>
         <apex:commandButton value="Save" action="{!saveObjects}"/>
    <apex:pageblockButtons/>
    <apex:pageblocksection>
         <apex:inputfield value="{!myA__c.Name}"/>
         <!-- add any other fields you want for this object -->
    </apex:pageblocksection>
    <apex:pageblocksection>
         <apex:inputfield value="{!myB__C.Color__c}"/>
         <apex:inputfield value="{!myB__C.Location__c}"/>
    </apex:pageblocksection>
</apex:pageblock>
</apex:page>

Apex Class
public class myController{
public ObjectA__c myA{get;set;}
public ObjectB__c myB{get;set;}
public myController(){
         myA = new ObjectA__c();
         myB = new ObjectB__c();
    }
    public void saveObjects(){
         insert myA;
         myB.ObjectA__c = myA.Id;
         insert myB;
    }
}
Important links:
http://salesforce.stackexchange.com/questions/1548/multiple-custom-objects-in-a-single-visualforce-page
https://developer.salesforce.com/forums/?id=906F000000097tYIAQ
Mark this answer as a solution if you find it helps you.

Regards,
Akshay
Uttpal chandraUttpal chandra
Hi, Akshay

I have tried but it is not working..Giving Error

Reagrds,
Uttpal