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
Mahesh GorrepatiMahesh Gorrepati 

can we use ALLROWS for the relation query. kindly check the below code;

list<Account> acctoupdate = [select id,name,Active_policies__c,    Expired_policies__c,Expiring_policies__c,
                                             (select id,name,customer_name__c,    plan_status__c from customer_policy_details__r where id in:newrecords.keyset() All rows)
                                             from account where id in: accountids];
AnkaiahAnkaiah (Salesforce Developers) 
Hi Mahesh,

Yes.
You can use ALL ROWS to query records in your organization's Recycle Bin. You cannot use the ALL ROWS keywords with the FOR UPDATE keywords.

Refer the help article.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_SOQL_query_all_rows.htm

If this helps, Please mark it as best answer.

Thanks!!
AnkaiahAnkaiah (Salesforce Developers) 
Hi Mahesh,

ALL ROWS is not working for sub query.

You can modify your query like below.
 
List<customer_policy_detail__c>	custompolicylist =[select id,
                                                          name,
														  customer_name__c,
														  plan_status__c,
                                                          Account__c,
														  Account__r.Name,
                                                          Account__r.Active_policies__c,
														  Account__r.Expired_policies__c,
														  Account__r.Expiring_policies__c
														  FROM customer_policy_detail__c 
														  where id in:newrecords.keyset() 
														  AND Account__c IN:accountids All ROWS];

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​