0

Prevent Account creation upon Lead conversion

While doing the lead conversion from UI, there are 2 options shown in the screen: Option 1. Account field is prepopulated which comes from the Company field of Lead. Option 2. User can select Account from the lookup icon. I want user always follows the Option 2. User should be restricted if Option 1 is followed. Is there a way to meet this requirement? Thanks! Milan

1

You can do this with a couple of triggers and an Apex class. The point here is that you need to detect when conversion occurs, and if an account was created as a result of that conversion.

I'm not going to write a proper trigger framework; I leave this as an exercise to the reader.


public class StaticStorage {
  public static Set<Id> newRecordIds = new Set<Id>();
}

trigger storeNewAccountIds on Account (after insert) {
    // Just remember we are in record creation
    StaticStorage.newRecordIds.addAll(Trigger.newMap.keySet());
}

trigger checkForNewAccountOnLeadConvert on Lead (after update) {
    for(Lead record: Trigger.new) {

        // If the account Id is in the set, it's a new record...
        if(StaticStorage.newRecordIds.contains(record.ConvertedAccountId)) {
            record.ConvertedAccountId.addError('You may not create a new account while converting a lead.');
        }
    }
}
-1

Thanks sfdcfox!

I have tried do achieve this requirement through validation rule and Lead mapping concept.

Lead default value = checked Account default value = unchecked

Map the fields to each other

Create a Validation Rule on the Account object like this

AND( ISNEW(), Checkbox = TRUE )

Thanks, Milan

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.