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
Abhishek patil 26Abhishek patil 26 

how to display two custom object (input)fields in single visual page.

Best Answer chosen by Abhishek patil 26
NagendraNagendra (Salesforce Developers) 

Hi Abhishek,

You need a controller or extension do this (controller is shown here):

public with sharing class controller {
    public ObjectA__c objectA { get; set; }
    public Task       task    { get; set; }
    public controller() {
        objectA = ...; // do query from page parameter, etc);
        task = new schema.task();
    }
    public pagereference save() {
        try {
            update objecta;
            task.whatid = objecta.id;
            insert task;
            return new apexpages.standardcontroller(objecta).view();
        } catch(exception e) {
            apexpages.addmessages(e);
            return null;
        }
    }
}
Refer to your ObjectA fields as {!objecta.provider__c}, and task fields as {!task.category__c}. You can populate other data as well, change the logic around, etc. If you're using the standard controller, you can refer to {!ObjectA__c.Provider__c} instead; you'll want to save the standard controller so you can save the data correctly (calling controller.save()).

Hope this helps.

Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra

All Answers

NagendraNagendra (Salesforce Developers) 

Hi Abhishek,

You need a controller or extension do this (controller is shown here):

public with sharing class controller {
    public ObjectA__c objectA { get; set; }
    public Task       task    { get; set; }
    public controller() {
        objectA = ...; // do query from page parameter, etc);
        task = new schema.task();
    }
    public pagereference save() {
        try {
            update objecta;
            task.whatid = objecta.id;
            insert task;
            return new apexpages.standardcontroller(objecta).view();
        } catch(exception e) {
            apexpages.addmessages(e);
            return null;
        }
    }
}
Refer to your ObjectA fields as {!objecta.provider__c}, and task fields as {!task.category__c}. You can populate other data as well, change the logic around, etc. If you're using the standard controller, you can refer to {!ObjectA__c.Provider__c} instead; you'll want to save the standard controller so you can save the data correctly (calling controller.save()).

Hope this helps.

Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
This was selected as the best answer
Abhishek patil 26Abhishek patil 26
hello,
can u give example with vf  page and controller.
and i have customer__c and agent__c object  so i need to create two tabs and in that tabs i need to enter their respective details and save the details.