I have some problem, and I hope someone will be able to advice me with that. Organisation have multiple recordTypes, BusinessProcess and Converted statuses for Lead.

Did anyone know is it possible to somehow map this in apex code to match right status to recordtype/BusinessProcess and use it with convertLead class?


I think you might be out of luck. Apparently only the user's default record type will be used:

Record types: If the organization uses record types, the default record type of the new owner is assigned to records created during lead conversion.

The default record type of the user converting the lead determines the lead source values available during conversion. If the desired lead source values are not available, add the values to the default record type of the user converting the lead.

from convertLead() API docs

  • 2
    May by we don't understand eachother. Model is Lead ->Recordtype -> Process And in process you define avalible converted statuses, you can of course create for example custom setting that will match RecordType.Name -> Avalible status. Using this I can assign right converted status to right record type - and this will work. My question is if I can dynamicly create such map in code? – Artur Kępczyński Mar 27 '14 at 15:01
  • Hmm, maybe I missed the boat here... assembling the map in code is one thing, but then how would one use it with the convertLead class? @ArturKępczyński – bigassforce Mar 27 '14 at 15:43
  • 1
    The issue is that you have to set lead status that match status in lead process - it is my only issue. So if you set status in setStatus() that does not match processs convert status it will break – Artur Kępczyński Mar 27 '14 at 15:44
  • I think user320 understands you perfectly. Process is just a set of picklist values, and record type is a subset of those picklist values (well, the available values are the intersection of those two sets). But the question at hand is whether one can assign the record type during conversion, and the answer is not really. You can do an @future afterInsert(Set<Id>) method and do the update there. But business process, AFAIK, cannot be queried in SOQL. – DavidSchach Apr 2 '14 at 21:45
  • 1
    I am also struggling to find the appropriated Converted Status for a given RecordType dynamically. I am required to set a LeadStatus upon Lead Conversion. But if the LeadStatus does not match the RecordType, the Conversion will fail with Database.Error[getFields=(Status);getMessage=invalid convertedStatus: Demo Set;getStatusCode=INVALID_STATUS; cf. developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… – Christian Szandor Knapp Aug 9 '16 at 18:34

Use APEX trigger Rules to update Record Type of created Account, Contact and Optionally A little more complicated from development point of view but more efficient and easy to support solution.

Instead of the workflows this solution use a single APEX trigger with Helper class to handle all needed functionality.

Step 1: The same as above. Create three picklist fields on Lead object (Expected Account Type, Expected Contact Type, Expected Opportunity Type) and populate them with Record Types names you have for Accounts, Contacts and Opportunities objects. These field will be visible to Users to let them to select Record Type they want for created after Lead Conversion records.

Step 2: Create trigger and helper class. See code samples here:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.