• SF_Steven
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies

I'm starting to get a little dangerous with APEX.  :smileyhappy:

 

My sandbox went down for mainteniance as I was getting ready to test this a second time - it didn;' work the first time.  I think I might be misunderstanding how trigger.old and new are suppsed to work.   Will this code automatically convert a lead when the status is changed to qualified?

 

Also - my test class only gets 76% converage.  To help get a better understanding, what would I need to add to get to 100%?

 

trigger LeadConvert on Lead (after update) {

  // no bulk processing; will only run from the UI and Lead Status must be changed to qualified 
  if (Trigger.new.size() == 1) {
    if (Trigger.old[0].isConverted == false)  {
    if (Trigger.new[0].isConverted == false && Trigger.new[0].Status == 'Qualified') {
 
              }
         }
    }
}

 Test Class:

 

public class LeadConvert {

    static testMethod void LeadConvert() {
    
    //create a lead with qualified status
    lead l1 = new lead();
    l1.status = 'Qualified';  
    l1.lastname = 'Joe';         
    l1.firstname = 'Smith';         
    l1.company = 'Company ABC'; 
    l1.isConverted = False ;
    insert l1;
    string holder = l1.id;
    
    //create lead that does not match criteria
    Lead L2 = new lead();
    L2.Status = 'Open';
    L2.lastname = 'Jane';         
    L2.firstname = 'Smith';         
    L2.company = 'Company DEF';
    L2.isConverted = False;
    insert L2;
    string holder2 = L2.id;  
    
    //Update 
    L2.Status = 'Qualified';
    update L2;
        }
 }

 

I was wondering if this APEX trigger I’m trying to write is bigger than a bread box.   So far – I have three triggers in my organization (one of which still needs a little tweaking) that are going to save me hours and hours of work each week.  I have one last piece of automation that will be critical – but I’m having a tough time figuring out where to start.  Here’s what my process looks like – any chance anyone can take a shot?  This is a little outside of my skill set as what I've written so far has been fairly basic.

 

All of my campaigns are outbound telemarketing – customers are often part of multiple lists and, on occasion, these lists can come in within days of each other.   What I would like to do – is have a trigger that applies a "stand-off" rule of ninety days for any new leads on upsert or insert.   In other words, we don't want to call these customers back to back for different prodcuts.  So as my leads are imported – if there has been an attempt or contact in the last ninety days, the lead will be imported with the status as ‘pending’, and then will change to ‘open’ once we are outside of the ninety day window.    The 'pending' status would keep these from going into the outbound dialer.

 

There would be two objects at work here – the lead object, which would have a field called ‘Call Date’ and another field called ‘Party ID’ to match against on upsert/insert.   The other object would be the opportunity object (in the case of conversion) and would also have the same two fields to test on import.   So I need the trigger to look at the Account object, if there’s a matching party ID, check and see if the call date is null, if not, then see if the call date is > 90 days and if that is false, import as pending.    If all of those statements are true, then  move over to the opportunity object and apply the same test.

 

Then the last piece would be to have those leads that are changed to a ‘pending’ status changed back to an ‘open’ status once outside of that 90 day window based on the call date match.   I think I would have to have a field that would hold the call date from any matching object and build a time based workflow from that field.    I think I can solve for this last part, but the trigger piece is blowing my mind right now!

I have a convertLead trigger I'm writing and had a question that I wasn't 100% clear on after some reading.

 

When using that function in an Apex trigger, does convertLead use the field mapping already set in Salesforce or does thiat function as a trigger work independently of the conversion mapping within the system?   In other words, do I need to map out all my custom fields a second time in the trigger?

 

 

Thanks!

The subject line says it all - I just figured out the data model and have the groundwork done for my implementation.  This is one of two issues an Apex trigger can solve.  

 

Thanks in advance!

I'm starting to get a little dangerous with APEX.  :smileyhappy:

 

My sandbox went down for mainteniance as I was getting ready to test this a second time - it didn;' work the first time.  I think I might be misunderstanding how trigger.old and new are suppsed to work.   Will this code automatically convert a lead when the status is changed to qualified?

 

Also - my test class only gets 76% converage.  To help get a better understanding, what would I need to add to get to 100%?

 

trigger LeadConvert on Lead (after update) {

  // no bulk processing; will only run from the UI and Lead Status must be changed to qualified 
  if (Trigger.new.size() == 1) {
    if (Trigger.old[0].isConverted == false)  {
    if (Trigger.new[0].isConverted == false && Trigger.new[0].Status == 'Qualified') {
 
              }
         }
    }
}

 Test Class:

 

public class LeadConvert {

    static testMethod void LeadConvert() {
    
    //create a lead with qualified status
    lead l1 = new lead();
    l1.status = 'Qualified';  
    l1.lastname = 'Joe';         
    l1.firstname = 'Smith';         
    l1.company = 'Company ABC'; 
    l1.isConverted = False ;
    insert l1;
    string holder = l1.id;
    
    //create lead that does not match criteria
    Lead L2 = new lead();
    L2.Status = 'Open';
    L2.lastname = 'Jane';         
    L2.firstname = 'Smith';         
    L2.company = 'Company DEF';
    L2.isConverted = False;
    insert L2;
    string holder2 = L2.id;  
    
    //Update 
    L2.Status = 'Qualified';
    update L2;
        }
 }

 

I was wondering if this APEX trigger I’m trying to write is bigger than a bread box.   So far – I have three triggers in my organization (one of which still needs a little tweaking) that are going to save me hours and hours of work each week.  I have one last piece of automation that will be critical – but I’m having a tough time figuring out where to start.  Here’s what my process looks like – any chance anyone can take a shot?  This is a little outside of my skill set as what I've written so far has been fairly basic.

 

All of my campaigns are outbound telemarketing – customers are often part of multiple lists and, on occasion, these lists can come in within days of each other.   What I would like to do – is have a trigger that applies a "stand-off" rule of ninety days for any new leads on upsert or insert.   In other words, we don't want to call these customers back to back for different prodcuts.  So as my leads are imported – if there has been an attempt or contact in the last ninety days, the lead will be imported with the status as ‘pending’, and then will change to ‘open’ once we are outside of the ninety day window.    The 'pending' status would keep these from going into the outbound dialer.

 

There would be two objects at work here – the lead object, which would have a field called ‘Call Date’ and another field called ‘Party ID’ to match against on upsert/insert.   The other object would be the opportunity object (in the case of conversion) and would also have the same two fields to test on import.   So I need the trigger to look at the Account object, if there’s a matching party ID, check and see if the call date is null, if not, then see if the call date is > 90 days and if that is false, import as pending.    If all of those statements are true, then  move over to the opportunity object and apply the same test.

 

Then the last piece would be to have those leads that are changed to a ‘pending’ status changed back to an ‘open’ status once outside of that 90 day window based on the call date match.   I think I would have to have a field that would hold the call date from any matching object and build a time based workflow from that field.    I think I can solve for this last part, but the trigger piece is blowing my mind right now!

I have a convertLead trigger I'm writing and had a question that I wasn't 100% clear on after some reading.

 

When using that function in an Apex trigger, does convertLead use the field mapping already set in Salesforce or does thiat function as a trigger work independently of the conversion mapping within the system?   In other words, do I need to map out all my custom fields a second time in the trigger?

 

 

Thanks!

The subject line says it all - I just figured out the data model and have the groundwork done for my implementation.  This is one of two issues an Apex trigger can solve.  

 

Thanks in advance!