[SalesForce] How to get LastModifiedbyName in Profile/

I am creating a table with all profiles and users who last modified the profile.

Profile p = [select Name, lastmodifieddate, lastmodifiedbyId from Profile];

LastModifiedByName column is not here…and it tried relationship reference as well with lastmodifiedBYID….

Is there a way to get the Name of the user who last modified the profile.

Best Answer

You have to follow the lastmodifiedby relationship via the dotted notation and then you can pull fields from the related user:

List<Profile> profiles=[select Name, lastmodifieddate, 
                        lastmodifiedbyId, LastModifiedBy.Name from Profile];
Related Topic