• Freddy Davaris
  • NEWBIE
  • 10 Points
  • Member since 2018

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

Hi All, 

I was wondering if there is any way of updating an account field in APEX if i have the account ID in the Triggered Object. Right now i am running into the issue that I can not do the following (Trigger is on the Opportunity).

List <Account> AccountsInHierarchy = [SELECT Field_A, Field_B, Field_C
                                      FROM     Account
                                      WHERE  Ultimate_Parent_ID__c = Trigger.new.Account.Ultimate_Parent_Id__c
                                     ];

Whenever I do this I get the following error: 
System.LimitException: Too many query rows: 50001
 

I have already tried limiting the numbers returned by my SOQL Query but the error persisted. Any help would be much appreciated. 

Best, 

FD


 

Hi Everyone,

Just started coding with APEX last week and am trying to create a trigger that whenever an account field is edited, it looks into the opportunities of the account that has been edited. From the account's opportunities, it updates (see code below) a field labeled "Next Renewable Opportunity" when the opportunity is the account's next opportunity to be renewed. 
 
trigger CheckForNextRenewableOpp on Account(after insert, after update) {   
    // Get the related opportunities for the accounts in this trigger.        
    List<Opportunity> relatedOpps = [SELECT Id,Name,Contract_Expiration_Date__c, Next_Renewable_Opportunity__c FROM Opportunity
        WHERE Contract_Expiration_Date__c__c != NULL AND AccountID IN :Trigger.New];          
    // Iterate over the related opportunities
   for(Opportunity opp : relatedOpps) {      
       if (Account.Next_Renewal_Date__c != Null){
            if ((date.valueof(opp.Contract_Expiration_Date__c) == date.valueOf(Account.Next_Renewal_Date__c) ) && (Opp.Next_Renewable_Opportunity__c == False)){
                opp.Next_Renewable_Opportunity__c = True; // Sets next renewable opportunity field to 'TRUE' 
                update opp;
            }
            else if (((date.valueof(opp.Contract_Expiration_Date__c) < Date.today()) || (date.valueof(opp.Contract_Expiration_Date__c) != date.valueOf(Account.Next_Renewal_Date__c)))
                     && (opp.Next_Renewable_Opportunity__c == True)){                       
                         opp.Next_Renewable_Opportunity__c = False; // Sets next renewable oppotuinity field to 'False'
                         update opp;
                     }
       }
   }
}

// Contract Expiration Date: Opportunity Field, Type: Date Field
// Next Renewal Date: Account Field, Type: Rollup Summary Field
// Next Renewable Opportunity: Opportunity Field, Type: Checkbox Field

Please Advise.  When I run the trigger I get this error:

Error:Apex trigger CheckForNextRenewableOpp caused an unexpected exception, contact your administrator: CheckForNextRenewableOpp: execution of AfterUpdate caused by: System.TypeException: Invalid date: common.apex.runtime.impl.ApexFieldToken@3c8ccc3b: ()

Thanking you in advance, 
FD

Hi All, 

I was wondering if there is any way of updating an account field in APEX if i have the account ID in the Triggered Object. Right now i am running into the issue that I can not do the following (Trigger is on the Opportunity).

List <Account> AccountsInHierarchy = [SELECT Field_A, Field_B, Field_C
                                      FROM     Account
                                      WHERE  Ultimate_Parent_ID__c = Trigger.new.Account.Ultimate_Parent_Id__c
                                     ];

Whenever I do this I get the following error: 
System.LimitException: Too many query rows: 50001
 

I have already tried limiting the numbers returned by my SOQL Query but the error persisted. Any help would be much appreciated. 

Best, 

FD