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
s5s5 

Apex code to auto populate the field

Hi Team,

 

I created one visualforce page and in that i created 2 fields 'Books' and 'Books Name'.Here if i select Novel in  'Books' field,Only for this value  it has to populate Novel in 'Books Name'field and if i select story book in 'Books' field the 'Books Name' field has to autopopulate with 'null'.

 

Please tel me code how can this functionality be implemented in Visualforce page.

 

Thnaks in advance

Rahul SharmaRahul Sharma

Could you post your code snippet.

s5s5

I wrote code for different one and i need to add this functionality to that code.

Please help me in this

rohitsfdcrohitsfdc

is that a custom object, or you are doing it in VF page only. and is the "book" field a picklist??

 

 

s5s5

Yes this is the custom object and i am doing it in VF page and Books is not picklist,it is lookup

rohitsfdcrohitsfdc

could you please explain the problem in detail, i am not getting it

s5s5

see 'Books' field is the lookup of some other object field and in lookup only if i select Novel it automatically populate Books Name field with the value Novel .

Shashikant SharmaShashikant Sharma

What you require is 

 

1)add a action function, actionSupport and call it on change of Books field this should be called and pass the selected value as parameter. 

2)In action on contrller, if passeed parameter is 'Novel' search the record from the lookup object and assign it's id to lookup field, if story set it to null.

3)rerender the section containing lookup field

 

let me know if any isssues in it.