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
ankur khattriankur khattri 

Auto Populate a Lookup Field based on a field value in same standard controller for eg contact

Sumit Kumar Singh 9Sumit Kumar Singh 9
Hello Ankur, 
Is it Standard visualforce page OR Custom Viaulforce page with standard controller.

Thanks, 
Sumit KumarSingh
ankur khattriankur khattri
hi sumit,
i have to create trigger
Sumit Kumar Singh 9Sumit Kumar Singh 9
Bro, 
If you use trigger, then it will get fired on save, edit delete etc. of record. No fileds on UI will be auto populated. However, you can see the autopoulated values on record detail page. 
You can use formula fields, OR workflow to yo populate the values, if it is on the same object.
Anyway, I am answering your  question - 
trigger copyFields on Contact(before insert, before update) {
    for(Contact c : Trigger.new) { 
        // Copying Last Name into First Name. 
        c.firstName = c.lastName;
        // You can assing static value
        c.firstName = 'Your Value'; 
    }
}

Hope, it will help you.

Thank,
Sumit Kumar Singh
ankur khattriankur khattri
THANKS A LOT SUMIT.
ankur khattriankur khattri
its for the normal field autopopulate.lookup trigger any idea..Sumit
ankur khattriankur khattri
Thanks Sumit..can u show me how to do workflow for it..thanks in advance
Sumit Kumar Singh 9Sumit Kumar Singh 9
Sorry bro, You can't update lookup field using workflow, my mistake that I mentioned workflow in my previous answer. You can do the same with "process Builder".

Thanks, 
Sumit Kumar Singh
ankur khattriankur khattri
ok thanks a lot sumit (y)
 
Dario BakDario Bak
Ankur this is the real thing. URL Hacking so you dont write code ;)

http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html