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

Trigger not updating Contact.RelatedTo field, with no reason why not.
trigger UpdateReportsTo on User (after update) {
// user.Reports_to__c is a USER Id // contact ReportsTo is a CONTACT Id
for (User u : Trigger.New) { if(u.Reports_to__c != null && u.Contact_Id__c != null){ // does the new Reports_to__c user have a contact id? User mgr = [Select Id, Contact_Id__c FROM User Where Id = :u.Reports_to__c]; if(mgr.Contact_Id__c != null){ // user has the contact linkage needed // update the target's contact record.ReportsTo with the mgr.Contact_Id__c value Contact targetmgr = [Select Id From Contact Where Id = :mgr.Contact_Id__c]; Contact userContact = new Contact(Id = u.Contact_Id__c); userContact.ReportsTo = targetMgr; update(userContact); } } }}
The above trigger isn't firing both in unit tests as well as in the UI. I get no errors...just no update to the contact record. Any ideas at all?
Thanks.
Can you post your test ?
Sure, below is the test and under that are the methods in the TestHarness that this tet cares about.
I appreciate any help, I've been staring at this trivial trigger for hours which is more than frustrating.
- Bryan
Make sure that the trigger is active
It should fire. put some debug statements inside so you will come to know when it fires.
one suggestion, You put queries inside for loop which might hit the governor limit when you execute batch update on User object. you should devise you code so that this limitation can be avoided.
Make sure trigger is active
Put some debug logs and monitor debug logs from SetUp--> Administrative SetUp==> Monitoring ==> Debug Log
If can view execution stack path
It looks inside your test Handler class ,
you have attemted to Mixed DML Exception,
First you have Insert user record and then Contact record , It will be Mixed DML ..
Thanks,
Bala
Thanks for the replies. The trigger is active and valid, and I took out some of the System.debug statements in the snippets I posted before for brevity. I'll look into inserting some more of those and using the System Log (redesigned apparently).
Thanks.
Bryan
Right, so as a follow up, I was able to get this to work...sort of. I created a second field (text) in the contact table that I simply write the manager.Id to instead of writing the manager to the RelatedTo field. No clue what the deal is, but that was it. Now I have to see if that will satisfy workflow rules and the like, but it's something.
Anyone out there know if this is some known issue with the RelatedTo field on the Contact?
Oh, and when I was writing to the RelatedTo field I was testig by getting the SaveResult back and it was a Sucess each and every time, only with no vlaue change to the RelatedTo field.