+ Start a Discussion
Jason Lee 22Jason Lee 22 

Parent Account Lookup/auto fill

I am attempting to auto populate a parent account using the D&B global duns number of a child record. Is this possible, and what method would be used.
Always ThinkinAlways Thinkin
I would recommend using an Apex Trigger on Contact so you can properly bulkify it if you do a mass insert or update of Contacts. You would need to acquire all the D&B numbers of the inserted/updated Contacts into a List so you can run a query to retrieve all Accounts that have a matching D&B number. Populate a Map with the D&B number as the Key and the Account as the Value so you can iterate through the contacts and use map.get(D&B number) to retrieve the matching Account ID to populate the Contact's Account field.
SwarnasankhaSwarnasankha
Hi Jason! Can you answer a few questions to get a better understanding of the frequency and level of integration:
  • Is this a one time activity?
  • Is this a recurring activity?
    • If yes then does it need to occur in realtime?
      • If yes then I believe you would like to have it updated immediately upon creation of the Contact record?
  • What is the source of the Contact record creation because if it is the SFDC user interface then you will always need to choose an Account before saving the record?

These questions will help us in giving you the best approach to take.
Jason Lee 22Jason Lee 22
I may not have been clear in my original post.  I am attempting to use the D&B Global D-U-N-S number as a referance/lookup to auto populate the correct Parent account using the D&B Global Ultimate Business Name. 
Always ThinkinAlways Thinkin
Good questions from @swarnasankha that will help us help you. 

My propsed solution did recognize that you want to use the D&B Number as a foreign key and my assumption was that you wanted this to happen automatically if Contacts are inserted through the API. The other assumption is that the Contact arrives with the company's D&B Number. 

If you are manually entering Contacts in the UI, you're going to be forced to populate the Parent Account and it would most likely require a Visualforce page to create an automatic means of finding the matching Account prior to saving the new Contact.

You might also be able to edit the Accout Lookup Filter on the Contact.Account field to match the Contact.D&B Number field to the Account.D&B Number field to produce a suggested list of matching Accounts but you would want to set it to Optional so your end users can override it if no match is found.
Jason Lee 22Jason Lee 22
We will be using data.com to pull in new accounts/contacts and should have a limited number of manual account creations.  This will allow for the D&B duns number to be included everytime.
Always ThinkinAlways Thinkin
Since you'll have to query for the D&B Number on Accounts, you'll want to make sure the trigger is bulkified otherwise you could exceed the SOQL governor limit pretty quickly. Collecting all the D&B Numbers from the Contacts in Trigger.new into a List will allow you to return all matching Accounts. If you make a Map<String, Account> where String is the Account.D&B Number you'll be able to iterate through the Contacts in Trigger.new using get(D&B Number) on the Map to associate the correct Account to each Contact.