• kpeterson
  • NEWBIE
  • 25 Points
  • Member since 2007

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 23
    Replies

When someone syncs a quote to an opportunity I need apex to be triggered so that I can copy values from quote line item custom fields to their related opportunity line item's custom fields.  Is there a trigger for this?

 

The only thing close to this that I've thought of is firing apex when an Opportunity is updated and checking if the "Synced Quote" field changed.  This would tell me that the opportunity was just recently synced but I won't have direct relationships from the opportunity line items to the originating quote line items to accurately copy values between them.

We have people making changes in production rather than sandboxes a majority of the time (can't change this) and they aren't always aware of what the apex is tied to.  I know there is the "Run All Tests" button in the setup interface but that really bogs down the browser with everything it returns and isn't very usable for them.  Is there a way to maybe schedule tests and have the results emailed to me so I can be aware of anything that broke recently?


I've had "Too Many Query Rows" come up quite a few times now and i have not gotten any official response so I've made some simple cases to show the error.

I have a Full sandbox from production.  If I run this query in the explorer I get a count of 8987.

Code:
select count() from opportunitylineitem

I've created this test method to test my different limit issues.

Code:
public class CountTests {

 static testMethod void testCountTests()
 {
  Integer iCount = 0;
  for (OpportunityLineItem oOpportunityLineItem : [SELECT Id FROM OpportunityLineItem])
  {
   iCount++;
  }
  system.debug(iCount);
  
  system.debug([SELECT COUNT() FROM OpportunityLineItem]);
 }
}

The first section (the for loop) fails with "Too many query rows: 501" but it was my understanding that I should be able to process more records than the limit through the SOQL For Loop setup.  Does the SOQL For Loop still count towards the Query Rows count?

The second section (the count SOQL) also throws a "Too many query rows: 501" but I'm not returning the rows.

Could someone please let me know if I'm misunderstanding the limits or let me know if this is a known issue that has a fix/is being fixed.


I'm getting a "Too many query rows" error on a SOQL For Loop.  It was my understanding that you could use this approach to prevent governor limits from occurring.
 
This is line 106 in the test method:
Code:
insert oAssignments;

 
This is line 40 within the trigger:
Code:
for (OpportunityLineItem oOpportunityLineItem : [SELECT Id, OpportunityId, Project__c, PricebookEntry.Product2Id, PricebookEntry.ProductCode, PricebookEntry.Name FROM OpportunityLineItem WHERE Project__c IN :oProjectsMap.KeySet()])

 
 
Code:
System.Exception: Too many query rows: 501

Trigger.AssignmentInsertPopulateProductFlagsHandler: line 40, column 57

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AssignmentInsertPopulateProductFlagsHandler: execution of BeforeInsert

caused by: System.Exception: Too many query rows: 501

Trigger.AssignmentInsertPopulateProductFlagsHandler: line 40, column 57

Class.TestAssignmentInsertPopulateProductFlags.testAssignmentInsertPopulateProductFlagsHandler: line 106, column 9

 


Message Edited by kpeterson on 02-19-2008 06:38 AM
I have one assignment with multiple checkboxes.  I also have multiple workflow rules for the assignment that detect different checkbox combinations.  When one of the workflow rules detect their checkbox combination they update 2 hidden fields on the assignment which triggers apex to create a new assignment based on the values set in the 2 hidden fields.

My issue is when 2 of the workflow rules are evaluated true they both try to update the 2 hidden fields but only one of them wins.  I was hoping that each workflow's field update caused a separate update but it seems that all field updates are pooled together and then done at once.  Is there a way to manage workflow rules competing to update the same field?  I'd like it if each field update triggered a separate update event so that they both could get their next assignment created.

Any ideas?
I've deployed all my triggers and classes to a full sandbox (structure and data) without any problems.  All my tests create their own test objects/data so it doesn't rely on instance data.  This one in particular uses two hardcoded users that exists in all instances but since I'm creating the test accounts any existing data should not interfere with the queries.

Yet when I try to deploy to our production instance I get a "too many query rows: 501" error on this line:


Code:
System.assertEquals(60, [SELECT COUNT() FROM SFDC_Assignment__c WHERE Account__c IN :oAccounts AND OwnerId = :oOriginalUser.Id AND Resource__c = :oOriginalUserResource.Id]);

 Is this error saying that too many rows are being returned?  The documentation says that 1,000 is the max number of records that can be retrieved through a query but it's flagging it on 501 and this is a COUNT() query so it shouldn't matter.


Message Edited by kpeterson on 12-12-2007 06:30 AM
What's the best way to use users in unit tests?  You can't create temporary users in apex code for unit tests because they are a 'setup entity'.  Should you hardcode some users that are in the system and hope they don't change in the future and break your unit tests?  Should you select the top N users from the user list and just use whoever is returned everytime?
AccountTeamMembers is a standard child object so I can't define a trigger for it but is there some other way I can catch changes to it in my Apex code?  If someone tries to add a new accountteammember and I want to do validations on their role how can I do that?
Is it acceptable to cause failures in a unit test when obtaining 100% coverage on code that raises an error on purpose?  Like in the case that I have an insert trigger check to make sure another record doesn't already exists and it raises an error on the object if it does so it doesn't get inserted.  This causes an error in the unit test because I intentionally cause the error to get 100% coverage.  Is this against a unit test best practice or how do you get around this?

If you create a Product (Product2), enable scheduling and define a default revenue schedule, when you add that product to an Opportunity, a schedule will be created.

 

For instance, if my default revenue schedule is defined as:

  • Revenue schedule type = Repeat Amount for each installment
  • Revenue Installment Period = monthly
  • Number Of Revenue Installments = 12

And then I add this product to an opportunity with a quantity of 1 and a price of $500, I'll see 12 schedule entries (OpportunityLineItemSchedule records), $500 each, and occurring every month.

If I add this same product to an opportunity through Apex and specify quantity=1 and price=500, the product (OpportunityLineItem) will be added, but no schedule entries will be created.

 

Here's my code:

 

Product2 search_product = [select Id from Product2 where ProductCode='Budget_T1_LP_Call_Proxy']; Pricebook2 pricebook = [SELECT Id, Name FROM Pricebook2 WHERE isStandard=true AND isDeleted=false AND isActive=true]; PricebookEntry pbentry=null; try { pbentry = [select Id from PricebookEntry where Pricebook2Id=:pricebook.Id and Product2Id=:search_product.Id and isActive=true and UnitPrice=0 and UseStandardPrice=false]; } catch (System.Queryexception e) { pbentry = new PricebookEntry(Pricebook2Id=pricebook.Id,Product2Id=search_product.Id,isActive=true,UnitPrice=0,UseStandardPrice=false); insert pbentry; } OpportunityLineItem opp_product = new OpportunityLineItem(OpportunityId=io.Opportunity__c,PriceBookEntryId=pbentry.Id,Quantity=1, UnitPrice=io.monthly_budget__c, ServiceDate=io.Monthly_budget_bill_date__c ); insert opp_product;

 

My guess is that Salesforce wrote code to create the schedule outside of the standard controller and it is not executed when you simply add the product through Apex.

 

Thoughts? Can anyone confirm this?

 

 

For some background, see these posts:

  1. Revenue scheduling unit test not working
  2. Can't test product scheduling
  • March 16, 2009
  • Like
  • 0
Should updating a child record fire an update trigger on the master? We have a trigger on Master-Detail record which pushed some values down to the child records. And we have another trigger on the child record which does some computation. Updating master records causes infinite recursion as the master trigger updates child records which fires the master trigger again and on it goes. I also tested updating child record directly and it also seems to fire the After Update trigger on the master.

Has anybody run into this issue before? Is there a solution to this problem?
We have people making changes in production rather than sandboxes a majority of the time (can't change this) and they aren't always aware of what the apex is tied to.  I know there is the "Run All Tests" button in the setup interface but that really bogs down the browser with everything it returns and isn't very usable for them.  Is there a way to maybe schedule tests and have the results emailed to me so I can be aware of anything that broke recently?


I've had "Too Many Query Rows" come up quite a few times now and i have not gotten any official response so I've made some simple cases to show the error.

I have a Full sandbox from production.  If I run this query in the explorer I get a count of 8987.

Code:
select count() from opportunitylineitem

I've created this test method to test my different limit issues.

Code:
public class CountTests {

 static testMethod void testCountTests()
 {
  Integer iCount = 0;
  for (OpportunityLineItem oOpportunityLineItem : [SELECT Id FROM OpportunityLineItem])
  {
   iCount++;
  }
  system.debug(iCount);
  
  system.debug([SELECT COUNT() FROM OpportunityLineItem]);
 }
}

The first section (the for loop) fails with "Too many query rows: 501" but it was my understanding that I should be able to process more records than the limit through the SOQL For Loop setup.  Does the SOQL For Loop still count towards the Query Rows count?

The second section (the count SOQL) also throws a "Too many query rows: 501" but I'm not returning the rows.

Could someone please let me know if I'm misunderstanding the limits or let me know if this is a known issue that has a fix/is being fixed.


I'm getting a "Too many query rows" error on a SOQL For Loop.  It was my understanding that you could use this approach to prevent governor limits from occurring.
 
This is line 106 in the test method:
Code:
insert oAssignments;

 
This is line 40 within the trigger:
Code:
for (OpportunityLineItem oOpportunityLineItem : [SELECT Id, OpportunityId, Project__c, PricebookEntry.Product2Id, PricebookEntry.ProductCode, PricebookEntry.Name FROM OpportunityLineItem WHERE Project__c IN :oProjectsMap.KeySet()])

 
 
Code:
System.Exception: Too many query rows: 501

Trigger.AssignmentInsertPopulateProductFlagsHandler: line 40, column 57

System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AssignmentInsertPopulateProductFlagsHandler: execution of BeforeInsert

caused by: System.Exception: Too many query rows: 501

Trigger.AssignmentInsertPopulateProductFlagsHandler: line 40, column 57

Class.TestAssignmentInsertPopulateProductFlags.testAssignmentInsertPopulateProductFlagsHandler: line 106, column 9

 


Message Edited by kpeterson on 02-19-2008 06:38 AM
I have one assignment with multiple checkboxes.  I also have multiple workflow rules for the assignment that detect different checkbox combinations.  When one of the workflow rules detect their checkbox combination they update 2 hidden fields on the assignment which triggers apex to create a new assignment based on the values set in the 2 hidden fields.

My issue is when 2 of the workflow rules are evaluated true they both try to update the 2 hidden fields but only one of them wins.  I was hoping that each workflow's field update caused a separate update but it seems that all field updates are pooled together and then done at once.  Is there a way to manage workflow rules competing to update the same field?  I'd like it if each field update triggered a separate update event so that they both could get their next assignment created.

Any ideas?

When I connect Eclipse 3.0 to our sandbox I get the following error message :

AxisFault: null: Duplicate retrieve names specified for package 'Mass Update Contact Address 1%2E0'

null: Duplicate retrieve

I have deleted the custom S control “Mass update Contact address” and I still get the same error message .

The salesforce Schema seems to be partially loaded I can only see one s-control

I get the same error when I connect my Production box.

Eclipse work correctly with my developer login.

any idea ?




  • January 13, 2008
  • Like
  • 0
I've deployed all my triggers and classes to a full sandbox (structure and data) without any problems.  All my tests create their own test objects/data so it doesn't rely on instance data.  This one in particular uses two hardcoded users that exists in all instances but since I'm creating the test accounts any existing data should not interfere with the queries.

Yet when I try to deploy to our production instance I get a "too many query rows: 501" error on this line:


Code:
System.assertEquals(60, [SELECT COUNT() FROM SFDC_Assignment__c WHERE Account__c IN :oAccounts AND OwnerId = :oOriginalUser.Id AND Resource__c = :oOriginalUserResource.Id]);

 Is this error saying that too many rows are being returned?  The documentation says that 1,000 is the max number of records that can be retrieved through a query but it's flagging it on 501 and this is a COUNT() query so it shouldn't matter.


Message Edited by kpeterson on 12-12-2007 06:30 AM
I hope someone here can help. i'm new to Eclipse and the APEX plugin i've been trying to get a project set up from an existing company. below is an error i'm getting that is preventing me from downlaoding / sync what's already there, and it is preventing me from getting to the salesforce.schema which i desperately need to get access to ResourceException: Resource '/(company)/InstalledPackages/AFQ31/S-Controls/Include / Exclude ' does not exist. i appreciate the time anyone spent to read this.
  • December 12, 2007
  • Like
  • 0
I am building a fairly complex set of apex triggers and classes that does the following:
  • Automatically create a custom object (household) whenever a Contact is created
  • Keep that custom object in sync with the Contact as it changes
  • Automatically create Contact roles on Opp insert when you flag the Contact in the data
  • Create contact roles automatically for other Contacts connected to the primary contact's household
  • Roll up Opportunity amounts to the Contact that is primary contact role, and household members
We've built out a bunch of triggers, classes and tests. We've done lots of bulk testing, and think we understand how batches work, and how that affects the various governor limits. We can't test all scenarios that we might see in the data--there are limits to how large the test batches can be which makes it impossible to predict how large batches will behave.

When doing rollups like we're doing, we end up getting lots of data. Each opp we insert has one primary contact role, which could have 10 opportunities, and those opp ammounts need to be rolled up to that contact and the couple other contacts in it's household.

When we run across contacts that are primary on a lot of opps, we're running into script execution limits and heap size limits. These limits seem way too low if we're hitting them with 200 contacts that have a total of 300 opporunities we want to roll up. We've done some refactoring to avoid loops inside of loops to keep execution down.

I have found through trial and error that I can reduce the number of errors by turning the batch size down to 100 or 50. This is much slower, but stays below the governor limits. But even at a batch size of 50 opps being inserted, I'm still going over my heap size in some cases.

I've also run into one problem where my code for adding Contact Roles on Opp insert doesn't add contact roles to all opps at a large batch size, but does at a smaller batch size. The alarming thing is that no Apex errors are thrown during the import process, leading me to believe my code is executing correctly. If udates were failing, or a list was too large, or too many DML or SOQL statements, I would expect an error. We're stumped on this one right now.

I know complex code situations like mine surely can't be diagnosed over these boards, so I'm writing this more to express concern about the utility of Apex for more complex coding like we're trying to do. Dealing with batches, navigating the landscape of these low governor limits, not being able to write tests for real-world situations, seemingly not getting errors when I expect them are all concerning to me. We're really excited about Apex, but the learning curve and now the reality that we may not be able to do much of what we want to do becuase of low governor limits is getting us down right now.

Any thoughts would be appreciated!

Steve

Hello.  I'm a .NET developer learning my way around Java and the Eclipse IDE.  I need to move another developer's trigger from our Sandbox to production in a few days for a release but have no real clue how to do this.  I know I need to use the Apache Ant tool, but I'm totally lost.  Is there any documentation out there on how to do this?  I've heard that it's a command line program, and that's fine...but I'm totally lost on this.

Any help or direction is GREATLY appreciated.
Bryan
good day every one. i am the newest of saleforce. i've got a problem that cant be resolved and need help from all of you. my problem is:
when i try to excecute query for queryresult i got the following msg:
"Invalid element in com.sforce.soap.enterprise.sobject.SObject - type"
how may i  resovle this error.!
pls.....help me.

PoorMan.
good day every one. i am the newest of saleforce. i've got a problem that cant be resolved and need help from all of you. my problem is:
when i try to excecute query for queryresult i got the following msg:
"Invalid element in com.sforce.soap.enterprise.sobject.SObject - type"
how may i  resovle this error.!
pls.....help me.

PoorMan.


Code:
trigger deleteTempAcc on Account (after update) {

account acc=trigger.new[0];

account acctodelete=[select Oracle_Company_ID__c from account where id=:acc.id ];

if(acctodelete.Oracle_Company_ID__c==0)
delete acctodelete;

}

 
hi all,
 
i need to delete account when some field in it got updated.
 
in following example when oracle_company_id get updated, account should be deleted.
 
but i am getting error:: self_reference_from_trigger.
 
please help me out.
  • December 10, 2007
  • Like
  • 0