1

I do have a requirement like I need to write a trigger on user object.The trigger must be before update, which should give the value of previous and current profile assigend to a user.

any help??

This is what I have done, but not getting anything in debug log

trigger UserProfileTrigger on User (before update) {

for(Integer i = 0; i< Trigger.new.size(); i++) {
        if(Trigger.new[i].Profile!= Trigger.old[i].Profile){
         System.debug('***SFDC: Trigger.old is: ' + Trigger.old[i].profile);
         System.debug('***SFDC: Trigger.new is: ' + Trigger.new[i].profile); 
         }
    }
}
1

The field within the User object is ProfileId, not profile.

0

Correct answer is we have to use profileId instead of profile. Thanks to FrankZ

 trigger UserProfileTrigger on User (before update) {

        for(Integer i = 0; i< Trigger.new.size(); i++) {
                if(Trigger.new[i].ProfileId!= Trigger.old[i].ProfileId){
                 System.debug('***SFDC: Trigger.old is: ' + Trigger.old[i].profileId);
                 System.debug('***SFDC: Trigger.new is: ' + Trigger.new[i].profileId); 
                 }
            }
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.