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

Trigger Help
I have a trigger question.
I have a custom object named employee with a lookup field to the user record called Salesforce_user__c
I have another custom object called DD master list in which there is a field called Account_Manager__c that is a lookup to employee object.
Mt requirement is to populate the Account manager Salesforce User id in the new AM__c field. Below is the trigger i wrote(that does not work at all), if someone can help me with the test class and refinining the trigger I would be very grateful to you.
Please help
trigger SetDDmasterFields on DD_master_list__c (before insert, before update) { Map<Id,User> userMap = new Map<Id,User>(); for (dd_master_list__c dd : Trigger.new) { userMap.put(dd.account_manager__r.Salesforce_User__c, null); } userMap.remove(null); if (!userMap.keyset().isEmpty()) { for (User u : [SELECT Id FROM User WHERE Id IN :userMap.keyset()]) { userMap.put(u.Id,u); } for (dd_master_list__c dd : Trigger.new) { if (userMap.get(dd.account_manager__r.Salesforce_User__c) != null) { dd.AM__c = userMap.get(dd.account_manager__r.Salesforce_User__c).Id; } } } }
You can't use references directly in a trigger. You also don't really need to query the user table directly just the employee table based off the Account Managers.
Something like this should get you on the right track (I don't know the API name of the Employee table so you probably need to change that).
All Answers
You can't use references directly in a trigger. You also don't really need to query the user table directly just the employee table based off the Account Managers.
Something like this should get you on the right track (I don't know the API name of the Employee table so you probably need to change that).
Thanks a Ton Sean,
Can you please advise the test class as well. Many thanks again.
Try something like this (It may not compile / work on first go but should give you a good template)