8

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.

2
  • 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

16

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

Hope this helps

select lastmodifiedby.name from profile
0

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'){
        listaOpp.Add(opp);  
    }
}

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

if(!listaOpp.isEmpty()){
    for(Opportunity opp : listaOpp){

        if(opp.Cortesia_Autorizada__c){
            setOpp.add(opp.Id);
        }
    }

    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'){
                aprobadorId.add(step.ActorId);
            }
        }
    }
    if(!aprobadorId.isEmpty()){
            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;
                    break;
                }else{
                    opp.Autoriza__c = 'falso';
                    break;
                }
            }
            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 .