+ Start a Discussion

Question About Lead Convertsion Trigger


   Wondering if I write a trigger and Wanted it to fire off when the user clicks on Convert Lead .... My Trigger is not updating the Custom Object Recruiting Touchpoint and the field within it Contact????

Would I do an After update


trigger Z_TierLeadConvert on Lead (after update) {
List<Recruiting_TouchPoint__c> updatedRT = new List<Recruiting_TouchPoint__c>();
  for(Lead lead:System.Trigger.new) {
        if (lead.IsConverted) {
            Contact con = [SELECT Id,Tier_Score__c,TouchPoint_Date__c 
                            FROM Contact WHERE Contact.Id = :lead.ConvertedContactId];
                con.Tier_Score__c = lead.Tier_Score__c;
                con.TouchPoint_Date__c = lead.TouchPoint_Date__c;
            update con;
            Recruiting_TouchPoint__c allrt= [Select Contact__c
                                                From Recruiting_TouchPoint__c Where
                                                Lead__c = :lead.ConvertedContactId]; 
            allrt.Contact__c = con.Id;
    update updatedRT;



Anup JadhavAnup Jadhav

Do you get an error message when the trigger is fired? Your code doesn't follow the best practices around triggers which is required to avoid hitting governer limits.



Try printing out the values for lead.ConvertedContactId to see if the two select queries return any rows etc.


- A J


Hi Thank you for the kind reply but I know how to write a bulk trigger,right now I am trying to see if this works on a convert... the only thing i need to know is does after update work or is it before update and how to get into my custom objects to do a full update?


Anup JadhavAnup Jadhav

Since you are checking the 'isConverted' status flag, I'd suggest you create a trigger on 'after update', but I think (and I might be wrong here) you can use either 'after' or 'before' update since you are not modifying the Lead object itself.


The second part of your question about why it doesn't update the custom object Recruiting Touchpoint, I'd suggest outputting the lead.ConvertedContactId, and checking if 'con' or 'allrt' are null.


Hope this helps!


- A J