You need to sign in to do that
Don't have an account?
Sarah Choe
Auto populate a Standard contact name lookup field with current user name
Hi all,
I am looking for a way to auto(pre) populate a Contact name as the curent user name when he/she create a new case.
This can be internal user creating a case and community user creating a case.
below is my take but when i test with clicking 'new' case, I still see 'Contact Name' blank and need to be searched.
can anyone please help...?
trigger CaseContactName on Case (before insert) {
// List <Case> caseContactName = new List <Case>();
for (Case c : trigger.new){
if(c.ContactId == null){
c.ContactId = UserInfo.getUserId();
}
}
}
I am looking for a way to auto(pre) populate a Contact name as the curent user name when he/she create a new case.
This can be internal user creating a case and community user creating a case.
below is my take but when i test with clicking 'new' case, I still see 'Contact Name' blank and need to be searched.
can anyone please help...?
trigger CaseContactName on Case (before insert) {
// List <Case> caseContactName = new List <Case>();
for (Case c : trigger.new){
if(c.ContactId == null){
c.ContactId = UserInfo.getUserId();
}
}
}
Your trigger code is fine but for this requirement it won't work because trigger works in the backend. You need a Visualforce page and override the NEW case button. Or you can use create a custom button and put some onclick javascript and set the value of contact.
Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.
JS CODE:
See this screenshot, it will help you to create the custom button:
Thanks & Regards,
Gaurish
All Answers
Your trigger code is fine but for this requirement it won't work because trigger works in the backend. You need a Visualforce page and override the NEW case button. Or you can use create a custom button and put some onclick javascript and set the value of contact.
Please do not forget to mark this thread as SOLVED and answer as the BEST ANSWER if it helps address your issue.
JS CODE:
See this screenshot, it will help you to create the custom button:
Thanks & Regards,
Gaurish
many thanks!
Sarah
Hi Sarah, We can't use JavaScript on the existing standard NEW button. We will have to create a custom button if we want to use JavaScript. We can override the existing NEW button with Visualforce page.
Steps to override the existing the NEW button with a VF Page:
Go to Setup --> Type "Case" in Quick find in the left sidebar --> Click "Buttons, Links, and Actions" --> Click "Edit" in front of the New button --> Select Visualforce radio button for Salesforce Classic and Lightning Component for Lightning experience.
See screenshots for reference: