You need to sign in to do that
Don't have an account?
Sebastian Jud
Help with a basic trigger to convert Leads to Opportunities
Convert a Lead to an Opportunity using triger
Hi guys given two fields on the lead object:
FieldA__c
FieldB__c
I need to write a trigger to convert from Lead to opportunity every time a user fill out those two fields. Can anyone help me with the trigger?
Thanks in advance!
Hi guys given two fields on the lead object:
FieldA__c
FieldB__c
I need to write a trigger to convert from Lead to opportunity every time a user fill out those two fields. Can anyone help me with the trigger?
Thanks in advance!
Please find below code:
Please mark as best answer if helped.
Regards,
Ramakant
You could you a Process Builder to Do it. Since its always recommnded to use declarative when you can before moving to Programatic approach.
Please Refer this https://github.com/DouglasCAyers/sfdc-auto-convert-leads-process Convert Leads into Accounts, Contacts, and (optional) Opportunities on-demand using Process Builder.
Let me know if this helps. Please mark as best answer if helped.
You can use process builder to do this .
The following image will help you.
Thanks,
Selva Sweet Potato tec
Below trigger will convert lead into accout , contact and opportunity whenever FieldA__c and FieldB__c will be filled by user.
Trigger AutoConverter on Lead (after insert, after Update) {
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 && col.FieldA__c != null && col.FieldB__c != null) {
Database.LeadConvert lc = new Database.LeadConvert();
String oppName = lead.Name;
lc.setLeadId(lead.Id);
lc.setOpportunityName(oppName);
lc.setConvertedStatus(convertStatus.MasterLabel);
leadConverts.add(lc);
}
}
if (!leadConverts.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
}
}
Please test and let me know if its working or not
I have created trigger as per your requirment. Please check and let me know if you have any issue
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh