The default process of qualifying a lead creates an opportunity, a contact and an account, if the fields are filled in. But how we can control, which entities are created?
If you create a lead, there are some default required fields, like the topic and the name. Entering the name, you get an additional dialog, to fill in the first name and last name separately.
This information is used during qualification to create a contact with the provided first- and last name.
There is also a section named company, where you past in the company name. This field is business recommended and will be used to create the account with this name during qualification.
Also, an opportunity is created during qualification. The opportunity is always created and after the qualification process is finished, the user will be redirected to the newly created opportunity.
But how to prevent creation of all three entities?
If you don’t like to create an account and a contact, you can use the default process flow. There are two fields called “Existing Contact?” and “Existing Account?” If you set this lookups to an existing entry, they won’t be created a second time.
Example: You set the lookup of the account, save the lead and click qualify. The system will create a new contact and a new opportunity, but no new account.
But what can you do, if you want to decide, which entity should be created?
First, you create three new fields fo type TwoOptions, called
Put these fields on the form, that the users can select, which entity should be created.
Now there are two possible solutions.
Solution 1: Using Workflows
You create a new field on each of the three entities and map this field with the corresponding create-field of the lead. Now, if you qualify the lead, the entities will be created and the value of the create-field of the lead will be transferred to the field on the entity.
Now create a new workflow, that will be executed on the creation of the entity and check, if the field is set to yes. If this is the case, delete the entry.
This solution can be used without writing a single line of code, but on each qualification, the system will create the entires and afterwards (based on the value of the creation field) will delete them again.
Solution 2: Using Plugins
The second solution would be, to create a new plugin with the following implementation on Execution:
// getting the leadid
if (!Context.InputParameters.TryGetValue("LeadId", out var leadRef)) return;
var lr = leadRef as EntityReference;
// getting the lead with some additional data
var lead = OrgService.Retrieve(lr.LogicalName, lr.Id, new ColumnSet("new_createaccount", "new_createcontact", "new_createopportunity"));
var createAccount = lead.GetAttributeValue<bool>("fro_createaccount");
var createContact = lead.GetAttributeValue<bool>("fro_createcontact");
var createOpportunity = lead.GetAttributeValue<bool>("fro_createopportunity");
Context.InputParameters["CreateAccount"] = createAccount;
Context.InputParameters["CreateContact"] = createContact;
Context.InputParameters["CreateOpportunity"] = createOpportunity;
Register this plugin with the message QualifyLead on the lead entity. Use the stage Pre-validation.
In the plugin, you can get and set the information on the Input Parameters of the Context. The used parameters are:
If you set the attribute to false, this entity won’t be created during the qualification process. But be aware, that if you don’t create an opportunity, the CRM system can’t redirect to the opportunity and therefore, there is no visible action during qualification.
You have to manually reload the lead, to see, that the lead is qualified.