function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Freddy DavarisFreddy Davaris 

Update a specific account without querying it.

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


 

Best Answer chosen by Freddy Davaris
sfdcMonkey.comsfdcMonkey.com
HI freddy, 
try something like this :
List <Account> AccountsInHierarchy = [SELECT Field_A, Field_B, Field_C
                                      FROM     Account
                                      WHERE  Ultimate_Parent_ID__c = : Trigger.new[0].Account.Ultimate_Parent_Id__c
                                     ];

Thanks, let us know if it is work 

All Answers

sfdcMonkey.comsfdcMonkey.com
HI freddy, 
try something like this :
List <Account> AccountsInHierarchy = [SELECT Field_A, Field_B, Field_C
                                      FROM     Account
                                      WHERE  Ultimate_Parent_ID__c = : Trigger.new[0].Account.Ultimate_Parent_Id__c
                                     ];

Thanks, let us know if it is work 
This was selected as the best answer
GhanshyamChoudhariGhanshyamChoudhari
Account acc= new Account();
acc.Id=Trigger.new[0].Account.Ultimate_Parent_Id__c;
//update more account field here
update acc;

 
Freddy DavarisFreddy Davaris

Hey guys, thanks for the help! That's a good fix but it does not handle mass updates Here is what I was looking for:

https://salesforce.stackexchange.com/questions/216249/soql-query-limit-to-50000-records

Appreciate your time responding. 

FD