• dbimn
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hi, could use some thoughts here.  Trying to get a trigger to populate a lookup field when an account record is created or updated.  I have a custom object, Sales_Grid_Assignment__c, for storing zipcodes and related data.  The intent of the trigger is to match the account's zipcode to a custom object record and populate the lookup field with the custom object record id.   Code works great in Sandbox.  In production, if the account record creation is by lead conversion, I get following error, but only if the user wants to create an opportunity upon conversion as well as a new company record.

 

Error: System.LimitException: Too many query rows: 50001 (System Code) Class.AssignSalesGrid.getGrid: line 6, column 1 Trigger.PrimaryAccountTrigger: line 4, column 1

 

I don't have anywhere near 50,000 custom object records, but I tried putting a LIMIT on the query anyway.  No joy.  Anyone see any glaring omissions or mistakes?  Thanks!

 

Here is the code for Trigger and Class...

 

TRIGGER:

trigger PrimaryAccountTrigger on Account (before insert, before update) {
    
 LIST<Account> company = Trigger.new;
 AssignSalesGrid.getGrid(company);

}

 

CLASS:

public class AssignSalesGrid {

    public static void getGrid(LIST<Account> company){
        
        List<Sales_Grid_Assignment__c> salesgrids = new List<Sales_Grid_Assignment__c>();
        salesgrids = [Select Id, Name
                from Sales_Grid_Assignment__c LIMIT 50000];
        
        Map <string,Id> mapGrids = new Map<string,Id>();
            for (Sales_Grid_Assignment__c sg: salesgrids)  {
          
                mapGrids.put(sg.Name,sg.Id);    
            }
    for (Account a :company){
            a.Sales_Grid_Assignment__c = mapGrids.get(a.BillingPostalCode);
        }
        
    }
}

  • June 21, 2013
  • Like
  • 0

Has anyone run into this?  I pass filter parameters via an annotated url to a report, and it works just fine for me, but if one of my users clicks the link with the same url, the parameter does not pass.  In fact, the filter that the parameter feeds disappears entirely from the report.

 

Any thoughts?

  • June 13, 2013
  • Like
  • 0

Hi All,

I'm not getting code coverage I need on this class.  Red lines aren't covered.  The test class is at the end of this post..

Any thoughts on how to cover these lines?  Thanks for any help!

 

UpdateMaxReviewDate (Code Covered: 69%)

 

 line source
 1  public with sharing class UpdateMaxReviewDate{
 2  
 3   public void updReviews(){
 4  
 5   Map<Id, Date> MaxDates = new Map<Id, Date>();
 6   List<IMNAccount__c> lstToUpdate = new List<IMNAccount__c>();
 7  
 8   for (AggregateResult ard : [Select imnaccount__c,
 9   Max(Review_Date__c) rd From Report_Review__c
 10   GROUP BY imnaccount__c]) {
 11  
 12   MaxDates.put(String.valueOf(ard.get('imnaccount__c')),(Date) ard.get('rd'));
 13  
 14  }
 15   Set <Id> imnacctSet = new Set<Id>();
 16   imnacctSet = MaxDates.keySet();
 17   for (IMNAccount__c imn : [Select i.Last_Report_Review__c, i.Id,
 18   i.Company__r.PM_Report_Review__c, i.PM_Report_Review_Date__c
 19   From IMNAccount__c i
 20   WHERE i.Id IN : imnacctSet]){
 21   imn.Last_Report_Review__c = MaxDates.get(imn.Id);
 22   imn.PM_Report_Review_Date__c = imn.Company__r.PM_Report_Review__c;
 23   lstToUpdate.add(imn);
 24   }
 25   if(lstToUpdate.size() > 0)
 26   update lstToUpdate;
 27  }

 

Here's my Test Code

 

@isTest
private class UpdateMaxReviewDateTest {

public static testMethod void testReviewDates() {
        
        Date d = Date.today();
        
        //Create Test Account
        Account atest = new Account();
        atest.Name = 'New Test Account';
        atest.PM_Report_Review__c = d;
        Database.insert(atest);
        
        //Create Test imnaccount
        IMNAccount__c itest = new IMNAccount__c();
        itest.Name = 'New Test Imnaccount';
        Database.insert (itest);
        
        //Create Test Report Review
        List<Report_Review__c> rList = new List<Report_Review__c>();
        for (Integer i=0; i<21; i++){
            Report_Review__c rtest = new Report_Review__c();
            rtest.Review_Date__c = d-i;
            rList.add(rtest);
        }
        
        Database.insert(rList);    
        
        Test.startTest();
        
        //instantiate class to be tested and call method
        UpdateMaxReviewDate urd = new UpdateMaxReviewDate();
        urd.updReviews();
        
        
        //validate
        for (IMNAccount__c imn : [Select i.Last_Report_Review__c, i.Id,
                            i.Company__r.PM_Report_Review__c, i.PM_Report_Review_Date__c
                            From IMNAccount__c i]){
                            Date a = imn.Company__r.PM_Report_Review__c;
                            Date b = imn.PM_Report_Review_Date__c;
                            System.assertEquals(a,b);
                                
                            AggregateResult agr = [Select Max(Review_Date__c) rd From Report_Review__c
                                        WHERE imnaccount__c = :imn.Id];
                            Date c = (Date) agr.get('rd');
                            Date e = imn.Last_Report_Review__c;
                            System.assertEquals(c,e);   
           }
           Test.stopTest();
}
}

  • February 14, 2013
  • Like
  • 0

Hello All, new to apex coding and running into a production issue.  Scheduled class runs fine in sandbox, deployed successfully with 100% code coverage, but now the job isn't executing in production.  Scheduled with the Schedule Apex tool in UI just as in Sandbox.  The job shows up in Scheduled Jobs but nothing happens, no errors, nothing to see in Apex Jobs.  Anyone see anything wrong with the following...

 

 This is the scheduler

 

1
2
3
4
5
6
global class AddParentCompanyScheduler implements Schedulable{
   global void execute(SchedulableContext SC) {
      AddParentCompany A = new AddParentCompany();
      A.getParents();
   }
}

 

this is the class and method the scheduler should execute.  imnaccount is a custom object.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public  class AddParentCompany {
//If an account has a parent account, any related opportunities or imnaccounts
//should have the same parent.

//Create a list of accounts with parents and loop through each record.
  public void getParents(){
    for (List<Account> acctsWithParents: [Select a.ParentId, 
      a.Id From Account a WHERE a.ParentID != null]){
        
        for(Account currAcct: acctsWithParents){
          
    // For every account in the resulting list, pull a list of opportunities.
    //Update the opportunities with the account's parent account.        
          for(List<Opportunity> oppsWithCurrAcct : [Select o.Parent_Company__c, 
                  o.AccountId, o.Id From Opportunity o 
                  WHERE o.AccountID = :currAcct.Id]){
            for(Opportunity currOpp: oppsWithCurrAcct){
              
              currOpp.Parent_Company__c = currAcct.ParentId;
              
            }
            Database.update (oppsWithCurrAcct);
          }
    // For every account in the resulting list, pull a list of imnaccounts.
    //Update the imnaccounts with the account's parent account.      
          for(List<IMNAccount__c> imnWithCurrAcct : [Select i.Parent_Company__c, 
                  i.Id, i.Company__c From IMNAccount__c i
                  WHERE i.Company__c = :currAcct.Id]){
            for(IMNAccount__c currImn: imnWithCurrAcct){
              
              currImn.Parent_Company__c = currAcct.ParentId;
              
            }
            Database.update (imnWithCurrAcct);
          }
          
          
        }
    }
  }
}

 

 

  • November 27, 2012
  • Like
  • 0

Hi, could use some thoughts here.  Trying to get a trigger to populate a lookup field when an account record is created or updated.  I have a custom object, Sales_Grid_Assignment__c, for storing zipcodes and related data.  The intent of the trigger is to match the account's zipcode to a custom object record and populate the lookup field with the custom object record id.   Code works great in Sandbox.  In production, if the account record creation is by lead conversion, I get following error, but only if the user wants to create an opportunity upon conversion as well as a new company record.

 

Error: System.LimitException: Too many query rows: 50001 (System Code) Class.AssignSalesGrid.getGrid: line 6, column 1 Trigger.PrimaryAccountTrigger: line 4, column 1

 

I don't have anywhere near 50,000 custom object records, but I tried putting a LIMIT on the query anyway.  No joy.  Anyone see any glaring omissions or mistakes?  Thanks!

 

Here is the code for Trigger and Class...

 

TRIGGER:

trigger PrimaryAccountTrigger on Account (before insert, before update) {
    
 LIST<Account> company = Trigger.new;
 AssignSalesGrid.getGrid(company);

}

 

CLASS:

public class AssignSalesGrid {

    public static void getGrid(LIST<Account> company){
        
        List<Sales_Grid_Assignment__c> salesgrids = new List<Sales_Grid_Assignment__c>();
        salesgrids = [Select Id, Name
                from Sales_Grid_Assignment__c LIMIT 50000];
        
        Map <string,Id> mapGrids = new Map<string,Id>();
            for (Sales_Grid_Assignment__c sg: salesgrids)  {
          
                mapGrids.put(sg.Name,sg.Id);    
            }
    for (Account a :company){
            a.Sales_Grid_Assignment__c = mapGrids.get(a.BillingPostalCode);
        }
        
    }
}

  • June 21, 2013
  • Like
  • 0

Has anyone run into this?  I pass filter parameters via an annotated url to a report, and it works just fine for me, but if one of my users clicks the link with the same url, the parameter does not pass.  In fact, the filter that the parameter feeds disappears entirely from the report.

 

Any thoughts?

  • June 13, 2013
  • Like
  • 0

Hi All,

I'm not getting code coverage I need on this class.  Red lines aren't covered.  The test class is at the end of this post..

Any thoughts on how to cover these lines?  Thanks for any help!

 

UpdateMaxReviewDate (Code Covered: 69%)

 

 line source
 1  public with sharing class UpdateMaxReviewDate{
 2  
 3   public void updReviews(){
 4  
 5   Map<Id, Date> MaxDates = new Map<Id, Date>();
 6   List<IMNAccount__c> lstToUpdate = new List<IMNAccount__c>();
 7  
 8   for (AggregateResult ard : [Select imnaccount__c,
 9   Max(Review_Date__c) rd From Report_Review__c
 10   GROUP BY imnaccount__c]) {
 11  
 12   MaxDates.put(String.valueOf(ard.get('imnaccount__c')),(Date) ard.get('rd'));
 13  
 14  }
 15   Set <Id> imnacctSet = new Set<Id>();
 16   imnacctSet = MaxDates.keySet();
 17   for (IMNAccount__c imn : [Select i.Last_Report_Review__c, i.Id,
 18   i.Company__r.PM_Report_Review__c, i.PM_Report_Review_Date__c
 19   From IMNAccount__c i
 20   WHERE i.Id IN : imnacctSet]){
 21   imn.Last_Report_Review__c = MaxDates.get(imn.Id);
 22   imn.PM_Report_Review_Date__c = imn.Company__r.PM_Report_Review__c;
 23   lstToUpdate.add(imn);
 24   }
 25   if(lstToUpdate.size() > 0)
 26   update lstToUpdate;
 27  }

 

Here's my Test Code

 

@isTest
private class UpdateMaxReviewDateTest {

public static testMethod void testReviewDates() {
        
        Date d = Date.today();
        
        //Create Test Account
        Account atest = new Account();
        atest.Name = 'New Test Account';
        atest.PM_Report_Review__c = d;
        Database.insert(atest);
        
        //Create Test imnaccount
        IMNAccount__c itest = new IMNAccount__c();
        itest.Name = 'New Test Imnaccount';
        Database.insert (itest);
        
        //Create Test Report Review
        List<Report_Review__c> rList = new List<Report_Review__c>();
        for (Integer i=0; i<21; i++){
            Report_Review__c rtest = new Report_Review__c();
            rtest.Review_Date__c = d-i;
            rList.add(rtest);
        }
        
        Database.insert(rList);    
        
        Test.startTest();
        
        //instantiate class to be tested and call method
        UpdateMaxReviewDate urd = new UpdateMaxReviewDate();
        urd.updReviews();
        
        
        //validate
        for (IMNAccount__c imn : [Select i.Last_Report_Review__c, i.Id,
                            i.Company__r.PM_Report_Review__c, i.PM_Report_Review_Date__c
                            From IMNAccount__c i]){
                            Date a = imn.Company__r.PM_Report_Review__c;
                            Date b = imn.PM_Report_Review_Date__c;
                            System.assertEquals(a,b);
                                
                            AggregateResult agr = [Select Max(Review_Date__c) rd From Report_Review__c
                                        WHERE imnaccount__c = :imn.Id];
                            Date c = (Date) agr.get('rd');
                            Date e = imn.Last_Report_Review__c;
                            System.assertEquals(c,e);   
           }
           Test.stopTest();
}
}

  • February 14, 2013
  • Like
  • 0

Hello All, new to apex coding and running into a production issue.  Scheduled class runs fine in sandbox, deployed successfully with 100% code coverage, but now the job isn't executing in production.  Scheduled with the Schedule Apex tool in UI just as in Sandbox.  The job shows up in Scheduled Jobs but nothing happens, no errors, nothing to see in Apex Jobs.  Anyone see anything wrong with the following...

 

 This is the scheduler

 

1
2
3
4
5
6
global class AddParentCompanyScheduler implements Schedulable{
   global void execute(SchedulableContext SC) {
      AddParentCompany A = new AddParentCompany();
      A.getParents();
   }
}

 

this is the class and method the scheduler should execute.  imnaccount is a custom object.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public  class AddParentCompany {
//If an account has a parent account, any related opportunities or imnaccounts
//should have the same parent.

//Create a list of accounts with parents and loop through each record.
  public void getParents(){
    for (List<Account> acctsWithParents: [Select a.ParentId, 
      a.Id From Account a WHERE a.ParentID != null]){
        
        for(Account currAcct: acctsWithParents){
          
    // For every account in the resulting list, pull a list of opportunities.
    //Update the opportunities with the account's parent account.        
          for(List<Opportunity> oppsWithCurrAcct : [Select o.Parent_Company__c, 
                  o.AccountId, o.Id From Opportunity o 
                  WHERE o.AccountID = :currAcct.Id]){
            for(Opportunity currOpp: oppsWithCurrAcct){
              
              currOpp.Parent_Company__c = currAcct.ParentId;
              
            }
            Database.update (oppsWithCurrAcct);
          }
    // For every account in the resulting list, pull a list of imnaccounts.
    //Update the imnaccounts with the account's parent account.      
          for(List<IMNAccount__c> imnWithCurrAcct : [Select i.Parent_Company__c, 
                  i.Id, i.Company__c From IMNAccount__c i
                  WHERE i.Company__c = :currAcct.Id]){
            for(IMNAccount__c currImn: imnWithCurrAcct){
              
              currImn.Parent_Company__c = currAcct.ParentId;
              
            }
            Database.update (imnWithCurrAcct);
          }
          
          
        }
    }
  }
}

 

 

  • November 27, 2012
  • Like
  • 0