You need to sign in to do that
Don't have an account?
MrBurnz1980
Update Contact record from customer portal user record
I am trying to write a simple trigger that will update the contact record if a user updates their email address in the customer portal (User record). The code below works but I get a DML exception once the code is Active and a new contact is being enabled to be a customer portal user, exisiting customer portal user record is modified. What am I doing wrong? Thanks.
trigger ContactUpdater on User bulk (after update) { Contact a; for (User u : Trigger.new) { String contactId = u.ContactId; if (contactId!=null && contactId!='') { a = [select Id,Email from Contact where Id=:contactId]; a.Email = u.Email; update a; } } }
The trigger works but if for example I change the role of the customer portal user here is what the error I get.
Well ooopss! how can I missed that!
Anyways user is considered as a setup object and if you are doing any DML on setup object, another DML to a non setup Object in our case contact is not allowed. To make this work you can try using future methods.
So try some thing like this. Create a new Class
Call the same from trigger
To know more about future methods you can go through this link http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm
Thanks I keep getting the following error on the trigger code
You should have caught It.
Edited my answer, changes are highlighted Please check that!