Trigger for Auto Converting Leads

Trigger for Auto Converting Leads

Requirement:-
Webform__c is custom text field  on lead . And Whenever new lead is created with Webform__c==’free trail’ then lead should be converted autmatically
trigger AutoLeadConvert on Lead (after insert) {


leadStatus convertStatus =[SELECT MasterLabel FROM LeadStatus WHERE isConverted = true Limit 1];  
List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();  
for(lead lead:Trigger.new){     
          if(!lead.isConverted && Lead.Webform__c=='free trail'){        
               Database.leadConvert lc = new Database.leadConvert();        
               lc.setLeadId(lead.Id);        
               lc.setOpportunityName(lead.Name);        
               lc.setConvertedStatus(convertStatus.MasterLabel);        
               leadConverts.add(lc);      
          }        
}   

List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);  
}
 
 

Understanding Lead Conversion:

When you convert a lead, Salesforce creates a new account, contact, and, optionally, an opportunity using the information from the lead. Any campaign members are moved to the new contact and the lead becomes read only. If an existing account and contact have the same names as those specified on the lead, you can choose to update the existing account and contact. Information from the lead is inserted only into blank fields; Salesforce does not overwrite existing account and contact data.
All open and closed activities from the lead are attached to the account, contact, and opportunity. You can assign the owner of the records, and schedule a follow-up task. When you assign a new owner, only the open activities are assigned to the new owner. If you have custom lead fields, that information can be inserted into custom account, contact, or opportunity fields. Converted leads can’t be viewed, although they appear in lead reports. Salesforce updates the Last Modified Date and Last Modified By system fields on converted leads when picklist values included on converted leads are changed.
Consider the following when converting leads.
Campaigns: If the lead matches an existing contact and both records are linked to the same campaign, the campaign member status is determined by whichever is further along in the lifecycle of the campaign. For example, if the lead member status is “sent” and the contact member status is “responded,” the responded value is applied to the contact. Related campaign information is always associated with the new contact record, regardless of the user’s sharing access to the campaign.
When more than one campaign is associated with a lead, the most recently associated campaign is applied to the Primary Campaign Source field on the opportunity, regardless of the user’s sharing access to the campaign.
Chatter: When you convert a lead into an existing account, you don’t automatically follow that account. However, when you convert the lead into a new account, you automatically follow the new account, unless you disabled feed tracking for accounts in your Chatter settings.
Data.com / D&B Company: If you use Data.com Premium, when you add a lead from Data.com, a corresponding D&B Company record (if one exists in Data.com) is automatically created in Salesforce and linked to the lead record via its D&B Company field. If you later convert that lead: If the account is created from the conversion, the lead’s Company D-U-N-S Number field value transfers to the account’s D-U-N-S Number field, and the lead’s D&B Company field value transfers to the account’s D&B Company field. The lead’s Data.com Key field value transfers to the contact’s Data.com Key field. If you use Data.com Corporate, no D&B Company record is created, but the lead’s Data.com Key field value transfers to the contact’s Data.com Key field.
Divisions: The new account, contact, and opportunity are assigned to the same division as the lead. If you update an existing account during lead conversion, the account’s division is not changed, and the new contact and opportunity inherit the account’s division. Existing Contact When you update an existing contact with a lead that you are converting, lead information in multi-select picklist fields carries over to the existing contact only if the matching fields for the contact are blank.
Local Lead Names The Company Name (Local) on the lead automatically maps to Account Name (Local), along with their associated standard name fields.
Person Accounts If your organization uses person accounts, you can convert leads to either person accounts or business accounts. Leads with a blank Company field are converted to person accounts. The default person account record type for your profile is applied to the new person account. Note that you can only create leads with a blank Company field using the Force.com API. Leads with a value in the Company field are converted to business accounts. The default business account record type for your profile is applied to the new business account. As a best practice, use different lead record types and page layouts to differentiate leads that will be converted to person accounts from those that will be converted to business accounts. In particular, remove the Company field from the page layouts of leads that will be converted to person accounts, and make the Company field required on the page layouts of leads that will be converted to business accounts.
If you create a lead, convert it, and then attach it to a person account owned by someone else, the person account owner becomes the contact owner.
If you convert a lead owned by someone else and attach it to a person account that you own, the lead owner becomes the contact owner.
Record Types: If the lead has a record type, the default record type of the user converting the lead 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.
Salesforce to Salesforce: When you convert a lead, Salesforce to Salesforce inactivates the shared record and updates the External Sharing related list in your connection’s lead record with an Inactive (converted) status. Due to inactivation of the shared record, changes to the Lead Status during conversion aren’t reflected in your connection’s lead record. Standard and Custom Lead Fields The system automatically maps standard lead fields to standard account, contact, and opportunity fields. For custom lead fields, your administrator can specify how they map to custom account, contact, and opportunity fields.
The system assigns the default pick-list values for the account, contact, and opportunity when mapping standard lead pick-list fields that are blank. If your organization uses record types, blank values are replaced with the default pick-list values of the new record owner.
Territory Management: If your organization uses territory management, the new account is evaluated by account assignment rules and may be assigned to one or more territories. If the rules assign the account to exactly one territory, then the opportunity will also be assigned to that territory. If the rules assign the account to multiple territories, then the opportunity is not assigned to any territory.
Triggers: During lead convert, Apex triggers are fired, and universally required custom fields and validation rules are enforced, only if validation and triggers for lead convert are enabled in your organization.
Salesforce ignores lookup filters when converting leads if the Enforce Validation and Triggers from Lead Convert checkbox on the Lead Settings page is deselected.
Workflow: You can’t convert a lead that’s associated with an active approval process or has pending workflow actions. Converting a lead to a person account won’t trigger workflow rules.
When a lead is converted by someone who isn’t the lead owner, all workflow tasks associated with the lead that are assigned to that user, except email alerts, are reassigned to the lead owner. Workflow tasks assigned to users other than the lead owner and lead converter aren’t changed

Different types of lead Status

 

However, generally speaking, this is what each one of those status values means:

  • Open: The lead was entered into the system (manually or via import or via some other means) and hasn’t been contacted yet.
  • Contacted: One of your sales reps initiated some sort of communication and got in touch with the lead
  • Qualified: The lead is interested in your product and the sales process should begin. This is when the lead can be converted to an Account, Contact and/or Opportunity
  • Unqualified: The lead won’t be a part of your sales process and is set to Unqualified and there can be a multitude of reasons behind this like the person not being interested in your product or anything else.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s