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
Dman100Dman100 

auto populate fields from lookup field

Is there a way to auto populate several fields based on the value from a lookup field?
 
For example, I have a custom lookup field on the Account object. When the user selects the account, I would like three custom fields (text boxes) to be auto-populated with the address, city and state from the account the user selected.
 
Is this possible?  If so, how?
 
Thanks.
HardhatHardhat
Not on the edit page.  You could write a workflow field update to fill these fields with the values from the parent account, but it'll only happen after the object is saved.
Christoph_AmannChristoph_Amann

Thanks for the tip.

Has anyone tried this yet? How do I get the value of the lookup field's street ? E.g. Parent account.street ?

Thank you to all for heloing on this issue.

Chris

 

werewolfwerewolf
Use the formula builder in the workflow field update screen -- it'll help you access the fields you're looking for.
Christoph_AmannChristoph_Amann

Well, I used the formula builder, but I couldn't find a way to fill a text field with the billing street of the account in the lookup field (or the parent account's billing street).

Has anybody got an idea?

Thanks in advance,

Christoph

daddyquatrodaddyquatro

This has to be possible. In the standard Contacts tab, when you pick an Account, the mailing address fields are automatically populated. The funtionality exists, I just can't find it.

 

werewolfwerewolf
It exists only because it's hardcoded for that particular page, the Contact page.  There's no notion of dynamically filled lookups elsewhere.  Soon you'll be able to write something like that in a Visualforce page though.
BALA_RAMBALA_RAM

TRY this code defenitly u get the solution for Autopopulation just you have to make Looup relation with User

 

trigger populateContactfromUser on Contact (before insert , before update){
    
    Set<ID> setConIds = new Set<ID>();
    for(Contact obj : trigger.new){
        if(obj.User_Name__c!= null)
        setConIds.add(obj.User_Name__c);
    }
    
     MAP<ID , User> mapCon = new MAP<ID , User>([Select Id,Email,Phone from User where id in: setConIds]);
     for(Contact obj : trigger.new)
       {
        if(obj.User_Name__c != null)
          {
            User c = mapCon.get(obj.User_Name__c);
            obj.Email= c.Email;
            //Similarly you can assign Address fields as well, just add those field in Contact SOQL as well
          }
       
       }
}

 

Developer.mikie.Apex.StudentDeveloper.mikie.Apex.Student
code works like a charm Bala, do you know if it will still work should multiple records be upserted?