• Todd Plunk
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Following up from this Question: https://success.salesforce.com/answers?id=9063A000000iRnpQAE

I am trying to track the most current campaign on a lead record when a lead status changes. We built a trigger already that tracks the date a lead status changes (below), but now I want to also track the current (or newest) campaign on the lead record.  Can I do this with a trigger?

Here is the current trigger in place that tracks the date a lead changes status:
// fills in the Recycle_Conversion_Date__c field with today's date
// whenever a lead's status is updated from Recycle to
// A, B, C, or TQL status.
trigger RecycleConversionDate on Lead (before update) {
  for (Lead oldLead : Trigger.old) { 
    Lead newLead = Trigger.newMap.get(oldLead.Id);
    if (oldLead.status == 'Recycle' && 
      (newLead.status == 'A- Lead Pursuing' || 
       newLead.status == 'B- Lead Contacted' || 
       newLead.status == 'C- Lead Responded' ||
        newLead.status == 'TQL - Totally Qualified Lead')) {
         newLead.Recycle_Conversion_Date__c = System.today();
    }
  }
}

Can we change this trigger to insert the most recent campaign on the lead record instead of the date?  I can't seem to find the proper Apex value that would give me a campaign name on a lead record. (aka, I am not a developer)

Use Case... when a lead changes from Recycle to C- Lead Responded, what is the newest, or most current campaign name on that lead record.  I don't really care about the campaign member status, I just want to know the name of the campaign at the time the lead status changes.

Hope this makes sense!  Thanks for the help!
Following up from this Question: https://success.salesforce.com/answers?id=9063A000000iRnpQAE

I am trying to track the most current campaign on a lead record when a lead status changes. We built a trigger already that tracks the date a lead status changes (below), but now I want to also track the current (or newest) campaign on the lead record.  Can I do this with a trigger?

Here is the current trigger in place that tracks the date a lead changes status:
// fills in the Recycle_Conversion_Date__c field with today's date
// whenever a lead's status is updated from Recycle to
// A, B, C, or TQL status.
trigger RecycleConversionDate on Lead (before update) {
  for (Lead oldLead : Trigger.old) { 
    Lead newLead = Trigger.newMap.get(oldLead.Id);
    if (oldLead.status == 'Recycle' && 
      (newLead.status == 'A- Lead Pursuing' || 
       newLead.status == 'B- Lead Contacted' || 
       newLead.status == 'C- Lead Responded' ||
        newLead.status == 'TQL - Totally Qualified Lead')) {
         newLead.Recycle_Conversion_Date__c = System.today();
    }
  }
}

Can we change this trigger to insert the most recent campaign on the lead record instead of the date?  I can't seem to find the proper Apex value that would give me a campaign name on a lead record. (aka, I am not a developer)

Use Case... when a lead changes from Recycle to C- Lead Responded, what is the newest, or most current campaign name on that lead record.  I don't really care about the campaign member status, I just want to know the name of the campaign at the time the lead status changes.

Hope this makes sense!  Thanks for the help!