You need to sign in to do that
Don't have an account?
AAngeles10
Apex Trigger - Update Field Values from Other Object (unrelated)
Hi,
I'm pretty new to writing triggers so please bear with me, I've been searching all over and can't seem to find an answer.
I have an object (Commission__c) that I want to update 3 fields (TradeID__c, Account__c, Revenue_in_Branch_Currency__c) from another object (Trade__c).
There is a text field (Deal_Number__c) on both objects that will be used to link them together.
This is the error I receive with the trigger I've build
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UpdateCommissionFields caused an unexpected exception, contact your administrator: UpdateCommissionFields: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.UpdateCommissionFields: line 9, column 1
I understand that the issue is within the List, but I'm just not sure how to correct it.
Cheers,
I'm pretty new to writing triggers so please bear with me, I've been searching all over and can't seem to find an answer.
I have an object (Commission__c) that I want to update 3 fields (TradeID__c, Account__c, Revenue_in_Branch_Currency__c) from another object (Trade__c).
There is a text field (Deal_Number__c) on both objects that will be used to link them together.
trigger UpdateCommissionFields on Commission__c (before insert, before update) { for (Commission__c cm: Trigger.new) { List<Trade__c> tr = [SELECT Id, Deal_Number__c, Account__c, Revenue_in_Branch_Currency__c FROM Trade__c WHERE Deal_Number__c = :cm.Deal_Number__c]; //error is in here for(Trade__c t: tr) { cm.TradeID__c = t.Id; cm.Account__c = t.Account__c; cm.Revenue_in_Branch_Currency__c = t.Revenue_in_Branch_Currency__c; } } }
This is the error I receive with the trigger I've build
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UpdateCommissionFields caused an unexpected exception, contact your administrator: UpdateCommissionFields: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.UpdateCommissionFields: line 9, column 1
I understand that the issue is within the List, but I'm just not sure how to correct it.
Cheers,
Here's what I ended up with.
I ended up removing one of the other fields and just used a formula field to grab the details.
All Answers
Try using the following trigger, Hope this helps & if it solves the query then please mark it as best answer since it will help others with similar issue!
I'm not sure if the SOQL fetches just 1 record, but that's all I need, just the record that matches on Deal Number.
We have many Commission and Trade records in the system, however the Deal Number is a unique value.
Thank you for sharing, I tried the updated trigger but I'm still getting the same error.
Cheers,
Allan
Here's what I ended up with.
I ended up removing one of the other fields and just used a formula field to grab the details.
Here i could see the SOQL statement is used within for loop. I am sure whether it is theright approach and we can easily hit the governer limits.
Regards,
Chandra
You can write SOQL statement within for loops but can't write DML inside a for loop