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
Rahul Gupta 194Rahul Gupta 194 

I want to fetch records which has been modified by system admmin profile in Apex code how to do it

How to query account on basis of profile i.e.
I want to see how many records have been edited by system admin or any other profile

Thanks in Advance ...
Please help
Jefferson FernandezJefferson Fernandez
Hi Rahul,
Assuming you know how to write Apex/SOQL. If not you may have to learn it first also for future use. But these are the steps/pseudocode that you will do:
  1. Query for the ProfileId of the target profile
  2. Query for the Users with the specific profileId
  3. Query for the Account on which their LastModifiedById are by the users on #2.
This is where you could learn how to write Soql just in case click here (https://developer.salesforce.com/docs/atlas.en-us.208.0.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_sosl_intro.htm).
Thanks,
pigginsbpigginsb
Hi, Rahul. You could traverse the relationships from Account to User to Profile in a single query, such as in this example...
List<Account> accountList = [select Id from Account where LastModifiedBy.Profile.Name = 'System Administrator'];
Checkout this reference regarding relationship queries: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_using.htm#sforce_api_calls_soql_relationships_query_using
Sagar PareekSagar Pareek
Hi Rahul,
Assuming you are trying to query all contact records modified by System Administrator profile this can be done using -
List<Contact> contactList = [select Id from Contact where LastModifiedBy.Profile.Name = 'System Administrator'];