• AAngeles10
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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.
 
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,
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.
 
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,