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
Aastha GulatiAastha Gulati 

write a trigger that fetches accounts related cases

Sangeet kaseraSangeet kasera
Hi Aastha,

You can use below query in trigger to fetch the cases related to Account

Below query when you want to fetch data from Account-
SELECT Name, (SELECT Id, AccountId, CaseNumber FROM Cases) FROM Account WHERE Id IN (SELECT AccountId FROM Case)

Alternative would be on Case Object-
SELECT Id, AccountId, Account.Name, CaseNumber FROM Case WHERE AccountId != ''

Adding an image from the developer console from the first query-
User-added image

Regards,
Sangeet

 
Sangeet kaseraSangeet kasera
Hi Aastha,

Will you please choose answer as best, If you found that my answer is relevant for you.
Which helps for other.

Regards,
Sangeet