+ Start a Discussion
Osiris77706Osiris77706 

System Debug not displaying.

I'm trying to use system.debug() thdisplay the number of records my trigger has changed. im using an integer counter that increases everytime a record is changed, and at the end it is displayed. the only problem is that debug is not displaying.

 

here's my code:

 

/*  This is a bulk Trigger designed to change the status of leads created before
 *  a pre-determined date to a pre-determined status automatically
 *
 * @Author: Greg Coley
 * @Created: July 20th 2010
 */

//Fires on the succesfull update of a lead
trigger oldLeadBulkStatusUpdate on Lead (after insert)
{
    //the status to be put in place of the older leads current status
      String newStatusForOldLeads;
   
   
    //set the new status below in format('Status goes between single quotes like this')
     newStatusForOldLeads = 'Dead';

   
    //the list that will hold the selected list
      List<Lead> oldLeads;

   
    //search for all the leads whose status we havent changed yet, because salesforce limits us to pulling only 1000
    //objects at a time from the db, we mus limit our search results, i limit to 900...just in case.
    oldLeads = [select id, createdDate, status, isConverted from Lead where status !=: newStatusForOldLeads limit 900];
     

   
   
   
    //Do not change this line.
    for (Lead ld: trigger.new)
  {
      //Create the counter, which will be used to tell us how many records we have updated.
      Integer changeCounter;
     
           
      //the predetermined date that qualifies a lead as 'old'
      Date   oldThreshold;
     
     
     
    
     //set the threshold date below in format(YYYY,MM,DD)
     oldThreshold = Date.newInstance(2010, 12, 31);
    
         
     //initialize the counter to zero
      changeCounter = 0;
     
     
      // provided the search returns any results we loop through the results and change the status
      // for the lead to the predetermined status, as long as the leads created date is before
      // the pre determined date.
      if(oldLeads.size() > 0){
      for(Lead currentLead: oldLeads)
      {
     
      if (currentLead.CreatedDate < oldThreshold && currentLead.isConverted == false)
        {
          currentLead.status = newStatusForOldLeads;
          update(currentLead);
          changeCounter++;
        }
       
            }
      }
      //throws feedback to the system log
        system.debug(' ________________________________________________________________ ');
        system.debug('|Updated: '+ changeCounter +' Records out of a possible 900                                        |');
        system.debug('|================================================================ |');
        system.debug('|Note: if the two numbers above are the same you probably have to                               |');
        system.debug('|run again. when the first number is 0, all updates are finished.                                      |');
        system.debug('------------------------------------------------------------------------------------------------------------------');
     
      
  }

 


}

Osiris77706Osiris77706

perhaps i should also mention that this is ment for one time use, to clear out a couple thousand old leads. 

DTCFDTCF

When you say the debug is not displaying, what do you mean? Is it not showing anything in the debug logs at all, or is it not showing any increments?

 

First of all, if this is intended to run once or periodically, I recommend not putting it in a trigger. Create an apex class and run it periodically from a button. It's a bad idea to attach a bunch of trigger logic that you're hoping will run under various rare circumstances. Probably not a huge deal, but you'll get in trouble down the road with that approach.

 

Second, your trigger is not safe for bulk operations. You should create a array of Leads to update, and call a single update once at the end.

 

List<Lead> leadsToUpdate = new List<Lead>();

leadsToUpdate.add(currentLead);

 

at the end of your looping, do a single update leadsToUpdate;

 

 

Finally, I would try to debug the logic around this:       if (currentLead.CreatedDate < oldThreshold && currentLead.isConverted == false)

 

Are you sure that that condition is being met? Maybe there are no leads to update? How many "oldLeads" are being returned from your SOQL query in the first place?

 

To get debug logs to display, you have to create a "New" debug log instance for your username. You'll have up to 20 requests or so and then you'll have to create a new one.

Osiris77706Osiris77706

Thanks for the reply,

 

i mean that nothing shows up in the sytem log, in the sandbox where i am testing this trigger. i have the filter settings to show apex debug, from what i could gather, it was to show up there.

 

   after some rethinking i did decide that i should not run this as a trigger, i like the class and button idea, but im not sure how i would go about the button part. my current working idea is to run it kind of like a script in the system log window, in the "Execute apex" text area, it worked for my sand box, unfortunately my sandbox only has 25 or so leads that i put in for testing a couple projects i've been working on.

 

perhaps i should supply some more background. I'm an intern for a  company that has been using salesforce for atleast 3 years. I just finished going to school for programming, so i have a good deall of c#/java under my belt, but over the last 2 months i've been working with salesforce, which i have unfortunately never worked with before. My company has built up literally thousands of old leads that are just polluting salesforce because everyone of their statuses is "open" so i was aksed to come up with a way to change all the older ones statuses to something that would be easy for them to filter out using views.

 

...oh and even better i'm the only actual programmer with the company.

 

gv007gv007

system.debug(' __________________________________________________

______________ ');
        system.debug('|Updated: '+ changeCounter +' Records out of a possible 900                                        |');
        system.debug('|================================================================ |');
        system.debug('|Note: if the two numbers above are the same you probably have to                               |');
        system.debug('|run again. when the first number is 0, all updates are finished.                                      |');
        system.debug('------------------------------------------------------------------------------------------------------------------');

 

 

Waht you are trying do with log---->you are not seeing the above string.There to reasons you are code is not executing upto this lines  I did't went all the code ,but this is one possibility.

 

and Use system debug in starting also

 

 

if want disply some values in system log do like this

 

System.debug(' want display'+variable name or method name);

S is cap letter.

paul-lmipaul-lmi

try using the logging level parament.  i noticed that a lot of places where debugging is uses (like eclipse) are starting to demand the more defined usage

 

system.debug(LoggingLevel.DEBUG,'your stuff');