Profile has a setting "Modify All Data". How can we access "Modify All Data" in apex and in which object it is stored.
This permission can read from the PermissionSet object. All profiles have a Permission Set associated with them, you can read more about this in the documentation, specifically the section Associated Profiles.
In API version 25.0 and later, every profile is associated with a permission set that stores the profile’s user, object, and field permissions, as well as setup entity access settings. Permission sets that are owned by profiles can be queried but not modified.
The documentation also provides the following sample query.
When combined with the PermissionSetAssignment object, you can create a nested query that returns all users assigned to a particular permission like “Modify All Data”:
SELECT Name, (SELECT AssigneeId FROM Assignments) FROM PermissionSet WHERE PermissionsModifyAllData=true
This query gives you a list of all users that have the Modify All Data permission (through profile or through a permission set).
SELECT AssigneeId FROM PermissionSetAssignment WHERE PermissionSet.PermissionsModifyAllData = true
You can easily convert this into a SET and then use the contains method in order to check if the current user has these permissions.