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
Ahmad AmiriAhmad Amiri 

Auto fill fields that base on a picklist.

Hi
I have three fields that base on a picklist ‘postcode’ in my custom object ‘Address’.
I want write a code to auto fill fields (Country, State,... ) base on the “Post code”. So if a user change value on pick list it should directly populate value to others text fields.
I know that there are different ways to do it but there are not proper for this example.
• Write apex and use trigger, it is work but after saving the record.
• Workflow formula has limited length and in this case we have 290 “Post code” so formula becomes an out of size
• The last one is use VisualForce page with apex class. This one is work if I want create the page from scratch or override the page.

My question is how can I create a customize “Address” to modify the page?  Like add “event="onchange"” to pick list or send value to extension controller.
Or if there is another way to solve this problem.

Thanks in Advance.
Best Answer chosen by Ahmad Amiri
Deepak Kumar ShyoranDeepak Kumar Shyoran
For that you need to create a new VF Page with both standardController and extensions attribute and you have to write a method in your controller to Populate the value in your State and Country Fields on onchange event of your picklist and reRender the section to view those values


Please mark my answer as a solution to your question if it solves your problem.

All Answers

vmanumachu1.393650924860069E12vmanumachu1.393650924860069E12
You can use apex:actionstatus and capture "onchange" event.
Deepak Kumar ShyoranDeepak Kumar Shyoran
I think ApexTrigger will solve your problem. You can easily access the value of your Postal code field in both After and Before trigger.
All you need to do is to write a ApexTrigger on Before/After insert and Update whichever suites you better and then assign the value for Country and State field according to Postal code.

Please mark my answer as a solution to your question if it solves your problem.


Ahmad AmiriAhmad Amiri
Hi Deepak,
Thanks for your answer.
You solution is work but after I click the save button I want populate value in text fields directly when I change the value in picklist.
Ahmad AmiriAhmad Amiri
Hi vmanumachu1.393650924860069E12,
I know that but I couldn't find a way to add code to existing page or override the picklist. I know how to write  visual force page from scratch.
Deepak Kumar ShyoranDeepak Kumar Shyoran
For that you need to create a new VF Page with both standardController and extensions attribute and you have to write a method in your controller to Populate the value in your State and Country Fields on onchange event of your picklist and reRender the section to view those values


Please mark my answer as a solution to your question if it solves your problem.
This was selected as the best answer