• NY70
  • NEWBIE
  • 0 Points
  • Member since 2011

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

Can anyone help me undertand why this happens in one of my classes and not in the another, even when the code is basically the same?

 

I have two classes which are basically looking for two different types of procedures on my custom object's records.

I get a list of records for which I have to send an email to.  On the help files for SingleEmailMessage, this methods state that:

 

setTargetObjectIdIDVoidOptional. The ID of the contact, lead, or user to which the email will be sent. The ID you specify sets the context and ensures that merge fields in the template contain the correct data.

Do not specify the IDs of records that have the Email Opt Out option selected.

All email must have a recipient value of at least one of the following:
  • toAddresses
  • ccAddresses
  • bccAddresses
  • targetObjectId
  • targetObjectIds
setToAddressesString[]VoidOptional. A list of email address to which you are sending the email. The maximum number of email addresses allowed is 100. This argument is allowed only when a template is not used.
All email must have a recipient value of at least one of the following:
  • toAddresses
  • ccAddresses
  • bccAddresses
  • targetObjectId
  • targetObjectIds

 

According to this help, I can either use setToAddresses or setTargetObjectId to setup the email address or OwnerId.  This works fine in one of my classes without any errors, but not in the other. Here is the code for both classes. 

 

class 1:

// Send an email to each account owner
list<Messaging.SingleEmailMessage> el = new list<Messaging.SingleEmailMessage>();
for(Actuals_Volume__c rec : recsList){
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   mail.setTargetObjectId(rec.Account__r.OwnerId);
   mail.setSaveAsActivity(false);
   mail.setSenderDisplayName('Salesforce Support');
   mail.setPlainTextBody('Your account: ' + rec.Account__r.Name +' has not ordered MGA in the past 30 days.');
   mail.setHtmlBody('Your account:<b> ' + rec.Account__r.Name +' </b>has not ordered MGA in the past 30 days.<p>'+
   'To view the account <a href=https://na11.salesforce.com/' + rec.Account__r.Id + '>click here</a>');
   el.add(mail);
}
system.debug('==========>>> el.size = ' + el.size());
		
if(!el.isEmpty()){
   Messaging.sendEmail(el);  <---- No error here at all
}

 Class 2:

// Send an email to each account owner
list<Messaging.SingleEmailMessage> el = new list<Messaging.SingleEmailMessage>();
for(Actuals_Volume__c rec : recsList){
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   mail.setTargetObjectId(rec.Account__r.OwnerId);
   mail.setSaveAsActivity(false);
   mail.setSenderDisplayName('Salesforce Support');
   mail.setPlainTextBody('Your account: ' + rec.Account__r.Name +' has not ordered Hematuria in the past 7 days.');
   mail.setHtmlBody('Your account:<b> ' + rec.Account__r.Name +' </b>has not ordered Hematuria in the past 7 days.<p>'+
   'To view the account <a href=https://na11.salesforce.com/' + rec.Account__r.Id + '>click here</a>');
   el.add(mail);
}
system.debug('==========>>> el.size = ' + el.size());
		
if(!el.isEmpty()){
   Messaging.sendEmail(el);  <-- get error here
}

 

  • July 26, 2011
  • Like
  • 0

I have a report in the matrix format and would like to create two formula fields.  The report is set-up in a way that the "Sum of Net Revenue" field is separated into weekly columns.  The challenge I'm having is how to subtract by week from the same field (Sum of Net Revenue). 

 

Formula field 1 (Revenue Variance) - This field will calculate the revenue difference from this week to last week.

Formula field 2 (% Variance) - This field will calculate the % difference from this week to last week.

 

Please help, happy to send screenshots if someone can show me how in this blog or otherwise.

 

Thank you!

 

 

  • March 31, 2011
  • Like
  • 0

I have a trigger on a custom object which depending on some criteria; it is supposed to create a list of emails to send.  I have created the trigger and it works fine.  Code coverage is 100%.  I’m ready to deploy it to production.

 

I’m calling a future method to process the records asynchronously.  I was expecting to be able to pass a list of account Ids created from my 2000 records to the future method to process but the trigger gives me 200 records at a time.  By the time the test method is done running, I’m very close to the limit of Number of future calls I can make.  What I really wanted and expected was for the future method to be called once and for all the processing to happen there.

 

Why does the trigger or apex automatically break up the 2000 records into bunches of 200 and process them separately? 

 

10:18:45.395|METHOD_EXIT|[7]|testAWAfterInsert

10:18:45.395|METHOD_ENTRY|[69]|System.debug(ANY)

10:18:45.395|USER_DEBUG|[69]|DEBUG|********** TEST 5 **********

10:18:47.357|METHOD_EXIT|[84]|system.Test.startTest()

10:18:47.358|DML_BEGIN|[85]|Op:Insert|Type:Actuals_Weekly__c|Rows:2000

10:18:48.160|USER_DEBUG|[19]|DEBUG|********** newAWs.size = 200

Number of future calls: 1 out of 10

...

10:18:55.859|USER_DEBUG|[19]|DEBUG|********** newAWs.size = 200

Number of future calls: 10 out of 10 ******* CLOSE TO LIMIT

 

Here is my trigger:

trigger AWTriggers on Actuals_Weekly__c (after delete, after insert, after undelete,after update,

                                         before delete, before insert, before update) {

   

    if(trigger.isAfter){

                      if(trigger.isInsert){

                                              AWAfterInsert myAfterInsert = new AWAfterInsert(Trigger.new);

                        }

                        if(trigger.isUpdate){}

                        if(trigger.isDelete){}

                        if(trigger.isUndelete){}

    }

   

    if(trigger.isBefore){

                        if(trigger.isDelete){}

                        if(trigger.isInsert){}

                        if(trigger.isUpdate){}

    }

}

Here is my class:

public with sharing class AWAfterInsert {

 

                        public AWAfterInsert(Actuals_Weekly__c[] newAWs){

                                                NotOrderedMGA14(newAWs);

                        }

                        public static void NotOrderedMGA14(Actuals_Weekly__c[] newAWs){

                                                System.debug('********** newAWs.size = ' + newAWs.size());

                                               

                                                Set<Id> accountIds = new Set<Id>();

                                                for(Actuals_Weekly__c aw : newAWs){

                                                                        accountIds.add(aw.Account__c);

                                                }

 

                                                AWGlobalUtils.asyncNotOrderedMGA14(accountIds);

                        }

}

Here is my future method:

global class AWGlobalUtils {

 @future public static void asyncNotOrderedMGA14(Set<Id> accountIds){

  System.debug('****************************** accountIds.size = ' + accountIds.size());

  list<Actuals_Weekly__c> awl = Database.query('Select Id, Procedure__c, Read_Date__c, Account__c, Account__r.Name, Account__r.OwnerId From Actuals_Weekly__c Where Procedure__c = \'MOLECULAR GRADING ASSAY\' And Read_Date__c < ' + getTargetDate() + ' And Account__c in : accountIds');

  System.debug('********** awl.size = ' + awl.size());

  Map<Id,Actuals_Weekly__c> am = new Map<Id,Actuals_Weekly__c>();

  if(!awl.isEmpty()) {

   for(Actuals_Weekly__c aw2 : awl){

    am.put(aw2.Account__c,aw2);

   }

  }

  System.debug('********** am.size = ' + am.size());

  // Send an email to each account owner

  list<Messaging.SingleEmailMessage> el = new list<Messaging.SingleEmailMessage>();

  for(Actuals_Weekly__c aw3 : am.values()){

   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

   mail.setTargetObjectId(aw3.Account__r.OwnerId);

   mail.setSaveAsActivity(false);

   mail.setPlainTextBody('Your account: ' + aw3.Account__r.Name +' has not ordered MGA in the past 14 days.');

   mail.setHtmlBody('Your account:<b> ' + aw3.Account__r.Name +' </b>has not ordered MGA in the past 14 days.<p>'+

   ' To view the account <a href=https://cs1.salesforce.com/' + aw3.Account__r.Id + '>click here</a>');

   el.add(mail);

  }

  System.debug('********** el.size = ' + el.size());

  if(!el.isEmpty()){

   Messaging.sendEmail(el);

  }

 }

}

Here is my test method:

@isTest

private class testAWAfterInsert {

 static testMethod void AccountHasOrderedBulkTesting2(){

   System.debug('********** TEST 5 **********');

   List<Account> testAL = new List<Account>();

   for(integer i=0; i<200; i++){

    testAL.add(new Account(Name = 'Test Account ' + i, Account_Classification__c = 'Doctor'));

   }

   insert testAL;

   Date d2 = date.newinstance(2011, 1, 17);

   List<Actuals_Weekly__c> testAWL2 = new List<Actuals_Weekly__c>();

   for(Account a : testAL){

    for(integer i=0; i<10; i++){

     testAWL2.add(new Actuals_Weekly__c(Account__c = a.Id, Read_Date__c = d2, Procedure__c = 'MOLECULAR GRADING ASSAY'));

    }

   }

   test.startTest();

   insert testAWL2;

   test.stopTest();

 }

} 

  • March 30, 2011
  • Like
  • 0

Can anyone help me undertand why this happens in one of my classes and not in the another, even when the code is basically the same?

 

I have two classes which are basically looking for two different types of procedures on my custom object's records.

I get a list of records for which I have to send an email to.  On the help files for SingleEmailMessage, this methods state that:

 

setTargetObjectIdIDVoidOptional. The ID of the contact, lead, or user to which the email will be sent. The ID you specify sets the context and ensures that merge fields in the template contain the correct data.

Do not specify the IDs of records that have the Email Opt Out option selected.

All email must have a recipient value of at least one of the following:
  • toAddresses
  • ccAddresses
  • bccAddresses
  • targetObjectId
  • targetObjectIds
setToAddressesString[]VoidOptional. A list of email address to which you are sending the email. The maximum number of email addresses allowed is 100. This argument is allowed only when a template is not used.
All email must have a recipient value of at least one of the following:
  • toAddresses
  • ccAddresses
  • bccAddresses
  • targetObjectId
  • targetObjectIds

 

According to this help, I can either use setToAddresses or setTargetObjectId to setup the email address or OwnerId.  This works fine in one of my classes without any errors, but not in the other. Here is the code for both classes. 

 

class 1:

// Send an email to each account owner
list<Messaging.SingleEmailMessage> el = new list<Messaging.SingleEmailMessage>();
for(Actuals_Volume__c rec : recsList){
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   mail.setTargetObjectId(rec.Account__r.OwnerId);
   mail.setSaveAsActivity(false);
   mail.setSenderDisplayName('Salesforce Support');
   mail.setPlainTextBody('Your account: ' + rec.Account__r.Name +' has not ordered MGA in the past 30 days.');
   mail.setHtmlBody('Your account:<b> ' + rec.Account__r.Name +' </b>has not ordered MGA in the past 30 days.<p>'+
   'To view the account <a href=https://na11.salesforce.com/' + rec.Account__r.Id + '>click here</a>');
   el.add(mail);
}
system.debug('==========>>> el.size = ' + el.size());
		
if(!el.isEmpty()){
   Messaging.sendEmail(el);  <---- No error here at all
}

 Class 2:

// Send an email to each account owner
list<Messaging.SingleEmailMessage> el = new list<Messaging.SingleEmailMessage>();
for(Actuals_Volume__c rec : recsList){
   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
   mail.setTargetObjectId(rec.Account__r.OwnerId);
   mail.setSaveAsActivity(false);
   mail.setSenderDisplayName('Salesforce Support');
   mail.setPlainTextBody('Your account: ' + rec.Account__r.Name +' has not ordered Hematuria in the past 7 days.');
   mail.setHtmlBody('Your account:<b> ' + rec.Account__r.Name +' </b>has not ordered Hematuria in the past 7 days.<p>'+
   'To view the account <a href=https://na11.salesforce.com/' + rec.Account__r.Id + '>click here</a>');
   el.add(mail);
}
system.debug('==========>>> el.size = ' + el.size());
		
if(!el.isEmpty()){
   Messaging.sendEmail(el);  <-- get error here
}

 

  • July 26, 2011
  • Like
  • 0

I have a trigger on a custom object which depending on some criteria; it is supposed to create a list of emails to send.  I have created the trigger and it works fine.  Code coverage is 100%.  I’m ready to deploy it to production.

 

I’m calling a future method to process the records asynchronously.  I was expecting to be able to pass a list of account Ids created from my 2000 records to the future method to process but the trigger gives me 200 records at a time.  By the time the test method is done running, I’m very close to the limit of Number of future calls I can make.  What I really wanted and expected was for the future method to be called once and for all the processing to happen there.

 

Why does the trigger or apex automatically break up the 2000 records into bunches of 200 and process them separately? 

 

10:18:45.395|METHOD_EXIT|[7]|testAWAfterInsert

10:18:45.395|METHOD_ENTRY|[69]|System.debug(ANY)

10:18:45.395|USER_DEBUG|[69]|DEBUG|********** TEST 5 **********

10:18:47.357|METHOD_EXIT|[84]|system.Test.startTest()

10:18:47.358|DML_BEGIN|[85]|Op:Insert|Type:Actuals_Weekly__c|Rows:2000

10:18:48.160|USER_DEBUG|[19]|DEBUG|********** newAWs.size = 200

Number of future calls: 1 out of 10

...

10:18:55.859|USER_DEBUG|[19]|DEBUG|********** newAWs.size = 200

Number of future calls: 10 out of 10 ******* CLOSE TO LIMIT

 

Here is my trigger:

trigger AWTriggers on Actuals_Weekly__c (after delete, after insert, after undelete,after update,

                                         before delete, before insert, before update) {

   

    if(trigger.isAfter){

                      if(trigger.isInsert){

                                              AWAfterInsert myAfterInsert = new AWAfterInsert(Trigger.new);

                        }

                        if(trigger.isUpdate){}

                        if(trigger.isDelete){}

                        if(trigger.isUndelete){}

    }

   

    if(trigger.isBefore){

                        if(trigger.isDelete){}

                        if(trigger.isInsert){}

                        if(trigger.isUpdate){}

    }

}

Here is my class:

public with sharing class AWAfterInsert {

 

                        public AWAfterInsert(Actuals_Weekly__c[] newAWs){

                                                NotOrderedMGA14(newAWs);

                        }

                        public static void NotOrderedMGA14(Actuals_Weekly__c[] newAWs){

                                                System.debug('********** newAWs.size = ' + newAWs.size());

                                               

                                                Set<Id> accountIds = new Set<Id>();

                                                for(Actuals_Weekly__c aw : newAWs){

                                                                        accountIds.add(aw.Account__c);

                                                }

 

                                                AWGlobalUtils.asyncNotOrderedMGA14(accountIds);

                        }

}

Here is my future method:

global class AWGlobalUtils {

 @future public static void asyncNotOrderedMGA14(Set<Id> accountIds){

  System.debug('****************************** accountIds.size = ' + accountIds.size());

  list<Actuals_Weekly__c> awl = Database.query('Select Id, Procedure__c, Read_Date__c, Account__c, Account__r.Name, Account__r.OwnerId From Actuals_Weekly__c Where Procedure__c = \'MOLECULAR GRADING ASSAY\' And Read_Date__c < ' + getTargetDate() + ' And Account__c in : accountIds');

  System.debug('********** awl.size = ' + awl.size());

  Map<Id,Actuals_Weekly__c> am = new Map<Id,Actuals_Weekly__c>();

  if(!awl.isEmpty()) {

   for(Actuals_Weekly__c aw2 : awl){

    am.put(aw2.Account__c,aw2);

   }

  }

  System.debug('********** am.size = ' + am.size());

  // Send an email to each account owner

  list<Messaging.SingleEmailMessage> el = new list<Messaging.SingleEmailMessage>();

  for(Actuals_Weekly__c aw3 : am.values()){

   Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

   mail.setTargetObjectId(aw3.Account__r.OwnerId);

   mail.setSaveAsActivity(false);

   mail.setPlainTextBody('Your account: ' + aw3.Account__r.Name +' has not ordered MGA in the past 14 days.');

   mail.setHtmlBody('Your account:<b> ' + aw3.Account__r.Name +' </b>has not ordered MGA in the past 14 days.<p>'+

   ' To view the account <a href=https://cs1.salesforce.com/' + aw3.Account__r.Id + '>click here</a>');

   el.add(mail);

  }

  System.debug('********** el.size = ' + el.size());

  if(!el.isEmpty()){

   Messaging.sendEmail(el);

  }

 }

}

Here is my test method:

@isTest

private class testAWAfterInsert {

 static testMethod void AccountHasOrderedBulkTesting2(){

   System.debug('********** TEST 5 **********');

   List<Account> testAL = new List<Account>();

   for(integer i=0; i<200; i++){

    testAL.add(new Account(Name = 'Test Account ' + i, Account_Classification__c = 'Doctor'));

   }

   insert testAL;

   Date d2 = date.newinstance(2011, 1, 17);

   List<Actuals_Weekly__c> testAWL2 = new List<Actuals_Weekly__c>();

   for(Account a : testAL){

    for(integer i=0; i<10; i++){

     testAWL2.add(new Actuals_Weekly__c(Account__c = a.Id, Read_Date__c = d2, Procedure__c = 'MOLECULAR GRADING ASSAY'));

    }

   }

   test.startTest();

   insert testAWL2;

   test.stopTest();

 }

} 

  • March 30, 2011
  • Like
  • 0