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
John Neilan 18John Neilan 18 

Custom Controller Question

Hi,

I have a simple Visualforce page with 3 fields that launches from a controller method related to another VF page. The page loads properly using the controller below, but I am trying to pre-populate the Contact and Account records that are the master part of the custom object master-detail relationship. Can anyone advise how I can do this?
 
public class NewObjController {

    Engage__c eng = new Engage__c();
    public list<Engage__c> listEngage{ get; set; }
 
    public NewObjController() {
        listEngage=new list<Engage__c>();
        listEngage.add(eng);
        }
 
    Public void addEngage() {
        Engage__c eng1 = new Engage__c();
            listEngage.add(eng1);
            }
            
    public PageReference saveEngage() {
        for(Integer i=1; i<listEngage.size(); i++) {
    insert listEngage;
    }
    }
}

 
Best Answer chosen by John Neilan 18
ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

You need to assign the value for those fields which you would like to pre-populate on VF page in the controller something like given in the below thread:

https://developer.salesforce.com/forums/?id=906F000000096KRIAY

Another example:https://developer.salesforce.com/forums/?id=906F0000000g28zIAA

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

You need to assign the value for those fields which you would like to pre-populate on VF page in the controller something like given in the below thread:

https://developer.salesforce.com/forums/?id=906F000000096KRIAY

Another example:https://developer.salesforce.com/forums/?id=906F0000000g28zIAA

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
This was selected as the best answer
John Neilan 18John Neilan 18
Thanks. I did try those but I'm getting a "List has no rows" error.