You need to sign in to do that
Don't have an account?

To have the lookup user field as logged in user.
I have this functionality, wherein once I click on new button, it will need to choose specific record type, once I choose, I want my lookup field to be default logged in user?
How will be the trigger for it?
I have written Apex code as::
trigger Update_Field on my_object (after insert) {
//user defaultuser = [select id from user where name = 'default user'];
for (my_objec C:trigger.new) {
if(C.VTM_Name__c==null) {
C.VTM_Name__c= userinfo.getUserId();
}
}
}
but I am still not getting the default value as logged in user.
How will be the trigger for it?
I have written Apex code as::
trigger Update_Field on my_object (after insert) {
//user defaultuser = [select id from user where name = 'default user'];
for (my_objec C:trigger.new) {
if(C.VTM_Name__c==null) {
C.VTM_Name__c= userinfo.getUserId();
}
}
}
but I am still not getting the default value as logged in user.
Try the below it will works for you!!!
It will populate the current User in the Lookup field after save the record.
trigger UpdateUser on my_object (before Insert,before Update) {
Id Id1=UserInfo.getUserId();
for (my_object C:trigger.new) {
if(C.VTM_Name__c==null) {
C.VTM_Name__c=Id1;
}
}
}
Can you please Let me know if it works or not!!!
If it works don't forget to mark this as a best answer!!!
Thanks,
Raj