1

I have a class marked 'With Sharing' and a simple method to get all org wide emails to populate in a picklist on my page:

public String getOrgEmails(){
    List<OrgWideEmailAddress> orgWideEmails = new List<OrgWideEmailAddress>();

    orgWideEmails = [SELECT Id, Address, DisplayName FROM OrgWideEmailAddress LIMIT 50000];

    return JSON.serialize(orgWideEmails);
}

I had thought that when users set up org wide emails, and specified profiles who could access them, the query would only return org wide emails a user was profiled to have access to.

This is not the case. The query just returns all org wide emails. But, the org wide email address object is very limited and doesn't tell you what profiles have access to it.

Is there any way to actually limit the org wide emails returned by if the executing user has access to it based on profile permissions on the org wide email.

Salesforce is obviously capable of doing this check, which is why they let you set that up. But I cannot see how we are able to do this check in apex.