+ Start a Discussion
raseshtcsraseshtcs 

Auto Populate fields in input fields of the VF page

Hi,

I have overridden new and edit of a custom object with a VF page which allows the user to search and then insert records to the custom object. What I want to do is when a user clicks edit infront of the record from the related list, the fields of the object get auto populated in the search fields of my VF page. I was trying to pass parameters (as we normally do in case we need opportunity name to be defaulted with some value) through URL but it is not working is there another way to do the same.

 

Thanks in advance 

Rasesh

Best Answer chosen by Admin (Salesforce Developers) 
Prafull G.Prafull G.

Probably what you should do is to pass the parameters in url and then get those in constructor. Once you get the same in constructor assign the values to the properties of controller which binds to the inputText on page.

 

If you want to show the search results as well then you might call the search method from the constructor.

Something like

controller-

public class Controller1 {

  public String text1 {get; set;}

  public String text2 {get; set;}

 

  public controller1() {

    text1 = apexpages.currentpage().getparameters().get('param1');

    text2 = apexpages.currentpage().getparameters().get('param2');

    // OR you can only pass id and do SOQL on the record and fetch the fields to be bind with text1 and text2

  }

}

 

page-

<apex:inputText value="{!text1}"/>

<apex:inputText value="{!text2}"/>

 

Hope it helps.

 

All Answers

Shashikant SharmaShashikant Sharma

I think parameter approach should work, just pass it , retrive it in constructor and SOQL the record. Please share your code if it does not work.

raseshtcsraseshtcs

Hey...

I don't want to SOQL those parameters, I just want that the text box which the user uses to search for the desired records gets prepopulated with the field values of the record he wants to edit. In case of opportunity I have used the following:

 

 pageRef = new PageReference('/006/e?Return='+return+'&ent=' +ent+ '&opp3='+defaultname+'&accid='+accid);

where defaultname contains the default value for my new opportunity.

 

But in my case here I am not sure to which parameters should I assign the field values to so that they are prepopulated with the field values.

 

Regards

Rasesh

Shashikant SharmaShashikant Sharma

May be i am not able to understand your issue clearly, but can suggest you try to read about standard controller, if it can help you.

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_std.htm

raseshtcsraseshtcs

Ok let me explain it to you again

 

I have 2 inputText fields, on my VF page which I have used to override the new button of a custom object, in which user enters some text to search records from another object. He then selects a record from result and clicks on save which inserts the selected record into the custom object. Along with his search critera of the two fields.

Next time when he clicks on edit of the same record I want that the two inputText fields of the search page be pre populated with the search criteria he used to search the records before.

 

Please let me know if I make myself clear or not

 

Thanks

Prafull G.Prafull G.

Probably what you should do is to pass the parameters in url and then get those in constructor. Once you get the same in constructor assign the values to the properties of controller which binds to the inputText on page.

 

If you want to show the search results as well then you might call the search method from the constructor.

Something like

controller-

public class Controller1 {

  public String text1 {get; set;}

  public String text2 {get; set;}

 

  public controller1() {

    text1 = apexpages.currentpage().getparameters().get('param1');

    text2 = apexpages.currentpage().getparameters().get('param2');

    // OR you can only pass id and do SOQL on the record and fetch the fields to be bind with text1 and text2

  }

}

 

page-

<apex:inputText value="{!text1}"/>

<apex:inputText value="{!text2}"/>

 

Hope it helps.

 

This was selected as the best answer
Nagaraju Mogili 31Nagaraju Mogili 31
Hi Prafull,

   Thanks for your code, how can we insert the values of fields in to the database for the custom object
  can you please assist me on this