HI I am new to salesforce I'm trying to code whenever lead is converted into account , contact. based on contactid a new user should be created. how I can do this please help me
As mentioned in the above link, you can add the user creation apex snippet in the trigger handler class.
I am adding the snippet present in the above link below for quick reference:
trigger TriggerOnConvertLeads on Lead (after insert, after update) {
List<lead> leadList = trigger.new;
Set<ID> leadIds= new Set<ID>();
for(lead leadRecord : leadList) {
if (leadRecord.Status == ‘Qualified’ && leadRecord.isConverted == false){
leadIds.add(leadRecord.Id);
}
//system.debug('size'+ leadIds.size());
if(leadIds.size() > 0){
ConvertLeads.LeadAssign(leadIds);
}
}
ConvertLeads class
Public class ConvertLeads
{
public static void LeadAssign(Set<Id> LeadIds)
{
LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus
WHERE IsConverted=true Limit 1];
List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
for(id currentlead : LeadIds){
Database.LeadConvert Leadconvert = new Database.LeadConvert();
Leadconvert.setLeadId ( currentlead );
Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
Leadconvert.setDoNotCreateOpportunity(TRUE);
//you can remove this line if you want to create an opportunity during conversion
MassLeadconvert.add(Leadconvert);
}
if (!MassLeadconvert.isEmpty()) {
List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
}
}}
For creating a user record you can check the below link for reference: https://developer.salesforce.com/forums/?id=906F000000092p2IAA
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
>> https://astreait.com/Lead-Conversion-In-Salesforce/
As mentioned in the above link, you can add the user creation apex snippet in the trigger handler class.
I am adding the snippet present in the above link below for quick reference:
For creating a user record you can check the below link for reference: https://developer.salesforce.com/forums/?id=906F000000092p2IAA
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.