6

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!

3 Answers 3

7

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]'
5
  • My issue, that I need to be sure at at the moment of account creation, per salesforce triggers execution flow, in case of conversion lead-related triggers will be fired only after account related triggers, so at the moment of account creation a valid ConvertedAccountId does not appear in the Lead table.
    – Eugene
    Commented Jun 20, 2013 at 20:48
  • What about the first option, though? If you map a field from the Lead to the Account during conversion to indicate it was a Lead, would that suffice? Do you just need to know it was a Lead, or which Lead it came from?
    – Mike Chale
    Commented Jun 21, 2013 at 11:13
  • "map a field from the Lead to the Account during conversion to indicate it was a Lead" - unfortunately this cannot be done using triggers, as per above Lead Before will only be executed after Account After... so where to map then?
    – Eugene
    Commented Jun 21, 2013 at 12:43
  • I added to my answer; see na14.salesforce.com/help/doc/en/customize_mapleads.htm
    – Mike Chale
    Commented Jun 21, 2013 at 12:50
  • thanks, Mike... that is really simplest way to deal with. Appreciate your help!
    – Eugene
    Commented Jun 21, 2013 at 13:35
0

Also - We simply use the value in "LeadSource" field on the contact object to see it came from Lead or not. in addition create a validation rule on lead field "Leadsource" to make it required.

This will save creating any new fields and doesn't require use of soql.

0

If you select any existing account when convert Lead, the field Lead.ConvertedAccountId will be populated by EXISTING account Id. So if you want to detect "was account created manually or from lead" you can compare Lead.ConvertedDate(Date type) and Account.CreatedDate(Datetime type). Or you can create checkbox in Account and fill it in the Lead trigger after converting (but you should also compare NOW time and Account.CreatedDate time).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .