[SalesForce] way to determine how certain account has been created

As you know Salesforce accounts could be created either as a result of lead conversion or directly, by creating a new account using account creation form (and, accordingly, bypassing lead creation stage). Is there any way to distinguish newly created accounts by its creation type (where creation type is converted lead/manual creation)?

I was thinking about attaching to the account entities a special boolean flag which will be changed in the scope of lead after update trigger, but per this post Lead Conversion Trigger Order of Execution the both (before/after) of Lead-related triggers are being fired at the last order (our tests showing the same behavior), while we need to know it somewhere in the scope of Account After Create trigger.

Accordingly, if such flag is the only approach, then we need to attach some custom coding to the New button, appearing in the account creation form… but this seems to be a really boring solution.

Maybe there a simpler/efficient one?

Thank you in advance!

Best Answer

I can think of two ways of doing this:

  1. Have a checkbox field on the Lead, Was_Lead__c (default: checked) that maps to a field on the Account. This value can be carried over on Lead conversion. If you need to trace it back to the original Lead, you could probably use a formula that provides the Lead's ID field. To configure this, go to Setup | Customize | Leads | Fields and look for the Map Lead Fields button in the Custom Fields section. See http://na14.salesforce.com/help/doc/en/customize_mapleads.htm for more details.

  2. You could do a SOQL query on your closed Leads. The following query will provide you a list of all Accounts and Contacts that originated from a converted Lead. You could filter it on specific Account Ids, if necessary.

Get all converted Accounts and Contacts:

SELECT ConvertedAccountId,ConvertedContactId,Id FROM Lead WHERE Status = 'Qualified'

Find the original Lead for a specific Account:

SELECT Id FROM Lead WHERE ConvertedAccountId = '[AccountId]'
Related Topic