You need to sign in to do that
Don't have an account?
Need Help writing a Trigger to Populate fields on a Custom Object when saved.
We have a custom object 'TimeSlip' that I need to have a couple fields auto-populated via trigger if they are left blank when a new 'TimeSlip' is saved. The first is a lookup field to the Contact object. The second is a lookup field to another custom object.
The two fields I need to auto populate are:
Resource_Name__c - Lookup(Contact) field that, if blank, should auto populate with the current user name {!User.Name} on save.
Case_Resource_ID__c - Lookup(Case Resource) field that, if blank, should auto populate with the Case Resource ID, where {!User.Name} matches the Case Resource Name, on save.
Any help would be greatly appriciated!
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal
All Answers
I have try this:-
If this solves your problem, kindly mark it as the best answer.
Hit Like, if it saved your work :-)
Thanks,
Vatsal
Error: Compile Error: Variable does not exist: userList at line 17 column 16
Sorry just replace userList with contactList.
just replace line 17 with below code:
Below is the working trigger:-
If this solves your problem, kindly mark it as the best answer.
Thanks you.
Can a 2nd condition be added to the following line that makes sure the id selected has a Case__c (on Case Resource Object) that matches the Case__c manually entered on the timeslip before saving?
for(Case_Resource__c caseResource : [select id from Case_Resource__c where Resource_Name__c =: userId]){
I have sense realized I need to add to that since this will return multiple case resource ID's. A user can be assigned a case resource id for many cases. I want to pull back the 1 case resource ID where the username matches the Case Resrouce Name, and the Case on the case resource name, matches the Case on the Timeslip.
So with which field of timslip should I match case of case resorce?
Can you give me list of all the fields of both objects?
Case Resource Fields:
Case__c Lookup(Case)
Rate__c Formula(Currency)
Resource_Name__c Lookup(User)
TimeSlip fields:
Case__c Master-Detail(Case)
Resource_Name__c Lookup(Contact)
Case_Resource_ID__c Lookup(Case Resource)
If this solves your problem, kindly mark it as the best answer.
Thanks,
Vatsal