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.

  • Why would you create table with all profiles and who last modified it? As you are pointing out, the Profile table already contains this information.
    – Phil Rymek
    Commented Oct 6, 2013 at 14:32
  • 1
    Probably the OP might be creating a VF page and displaying all the profiles in a table. Just a wild guess..
    – Sam
    Commented Oct 6, 2013 at 16:03

3 Answers 3


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];

Hope this helps

select lastmodifiedby.name from profile

If you want to know the name of the users then:

 //this contains all the LastModifiedById values you need
 Set<Id> userIDs = new Set<Id>();

 List<User> modUser = [SELECT Name FROM User WHERE Id IN: userIDs];

and this is an example of where I used it

trigger Suscripcion_ActualizaCortesiaAutoriza on Opportunity (before update) {

List<Opportunity> listaOpp = new List<Opportunity>();

for(Opportunity opp : trigger.new){
    if(string.isBlank(string.valueOf(opp.SFID__c)) && 
        opp.Autoriza__c == 'Blanca Nelly Garcia Gonzalez'){

Set<Id> setOpp = new Set<Id>();
Set<Id> aprobadorId = new Set<Id>();

    for(Opportunity opp : listaOpp){


    ProcessInstance[] pi = [SELECT Id, TargetObjectId,
                            (SELECT actorId, stepStatus FROM Steps) 
                            FROM ProcessInstance 
                            WHERE TargetObjectId IN: setOpp
                            AND Status = 'Approved'];

    for(ProcessInstance p : pi){
        for(ProcessInstanceStep step : p.steps){
            if(step.StepStatus == 'Approved'){
            User aprobador = [SELECT Name FROM User WHERE Id IN: aprobadorId LIMIT 1];

        for(Opportunity opp : listaOpp){
            String nombre = '';
            for(ProcessInstance p : pi){
                if(opp.id == p.TargetObjectId && opp.Autoriza__c == 'Blanca Nelly Garcia Gonzalez'){
                    nombre = aprobador.Name;
                    opp.Autoriza__c = 'falso';
            if(nombre != ''){
                opp.Autoriza__c = nombre;


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .