• Ashish Yelmule
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies

trigger LeadConversionTrigger on Lead( after update)

{

for( Lead l : Trigger.new )

{

// Check if the Lead is converting. 

//Once Lead is converted, Lead is read-only so this can only happen once 

if ( l.isConverted )

{

// Obtain a list of cases associated to the Lead

List< Case > CasesToConvert = [SELECT Id, Lead__c, ContactId, AccountId FROM Case WHERE Lead__c = l.Id];

 

// Update the Cases associated to the Lead to its converted Contact and Account Id

if ( CasesToConvert.size() > 0 )

{

for ( Case c : CasesToConvert )

{

c.ContactId = l.ConvertedContactId;

c.AccountId = l.ConvertedAccountId;

}

 

// Update the Cases

update CasesToConvert;

}

}

}

}


 

trigger LeadConversionTrigger on Lead( after update)

{

for( Lead l : Trigger.new )

{

// Check if the Lead is converting. 

//Once Lead is converted, Lead is read-only so this can only happen once 

if ( l.isConverted )

{

// Obtain a list of cases associated to the Lead

List< Case > CasesToConvert = [SELECT Id, Lead__c, ContactId, AccountId FROM Case WHERE Lead__c = l.Id];

 

// Update the Cases associated to the Lead to its converted Contact and Account Id

if ( CasesToConvert.size() > 0 )

{

for ( Case c : CasesToConvert )

{

c.ContactId = l.ConvertedContactId;

c.AccountId = l.ConvertedAccountId;

}

 

// Update the Cases

update CasesToConvert;

}

}

}

}