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
prasad@s.ax832prasad@s.ax832 

Populate fields in VF page that is linked from a custom object detail page

I have a custom object objectA

I added a custom button to objectA, the button is linked to a VF page.

 

Now I need to populate some fields specific to objectA in the opened VF page and let the user fill in rest of the values.

Can some one please suggest a way to achieve this?

 

Thank you.

 

Best Answer chosen by Admin (Salesforce Developers) 
Imran MohammedImran Mohammed

There are different ways of doing this, below is one of them.

Make sure your VF page has the following apex::page tag

<apex:page standardController="ObjectA" extensions="ObjectAExtension">

</apex:page>

 

The controller class should be as below

public with sharing class ObjectAExtension

{

public ObjectA  oa {get; set;}

 

public ObjectAExtension(Apexpages.standardController sc)

{

oa = (ObjectA) sc.getRecord();

oa = [select field1, field2, ... from ObjectA where id = :oa.id];

                //Make changes to the fields that you want to pouplate by default

}

//This is for updating the record after user enters the values and submits to save

public Pagereference updateOA()

{

update oa;

}

}

 

In the VF page refer to the fields of ObjectA using apex:inputField tag to respect the datatype by default.

All Answers

GoldwinGoldwin

Hi Prasad,

 

In controller declare the property with get and set accessors.When the variable is requested
from a Visualforce page, the get accessor returns a value. if you set the custom value in the controller VF will take that, otherwise it will use the default values.

Imran MohammedImran Mohammed

There are different ways of doing this, below is one of them.

Make sure your VF page has the following apex::page tag

<apex:page standardController="ObjectA" extensions="ObjectAExtension">

</apex:page>

 

The controller class should be as below

public with sharing class ObjectAExtension

{

public ObjectA  oa {get; set;}

 

public ObjectAExtension(Apexpages.standardController sc)

{

oa = (ObjectA) sc.getRecord();

oa = [select field1, field2, ... from ObjectA where id = :oa.id];

                //Make changes to the fields that you want to pouplate by default

}

//This is for updating the record after user enters the values and submits to save

public Pagereference updateOA()

{

update oa;

}

}

 

In the VF page refer to the fields of ObjectA using apex:inputField tag to respect the datatype by default.

This was selected as the best answer
Imran MohammedImran Mohammed

I hope you are invoking the VF page in the below format in your custom button code

window.parent.location.href = '/apex/VFPageName/{!ObjectA.id}';

 

Let me know if you have any questions.

prasad@s.ax832prasad@s.ax832

Thank you Imran and Goldwin.

 

Imran, me being new to the development on this platform, your detailed explanation was very useful and I could try out many more things based on your suggestion.