You need to sign in to do that
Don't have an account?
Future? Im a newbie
trigger Touch_Imp on User (after insert) { if(trigger.isInsert){ Set<String> usercontactid = new Set<String>(); for (User u : Trigger.new) { usercontactid.add(u.contactid); } if([SELECT COUNT() FROM implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid]>0){ Implementation__c[] updateimp = [SELECT id from Implementation__c WHERE implementation__c.implementation_contact__c IN :usercontactid]; Database.update(updateimp); } } }
Above is my current code. But I get an error message about updaing a setup object and non-setup object at the same time when I try to create a user record now. I believe I need to use the future command to fix this, but I have no idea how. I'm pretty new to apex coding and I'm really hoping you guys can give me a step by step on how to accomplish this task.
More Info (background on what I'm trying to do):
I'm trying to get my triggers on my Imp object to fire after my new user is created. The only way I know how to do that is to update the Imp record after the User record is updated. If there is a better way to accomplish this, please let me know! If I can supply any more needed information, just ask and I'll see what I can stir-up.
Thanks for reading, and hopefully helping :smileyhappy:
Try this-
Cheers,
Sandeep
All Answers
Couple of questions:
1. What is the exact error
2. How is there Implementation_contact__c with the ID of the new user if they did not exist before?
Comment:
1. The correct way to reference the field in the select statement is:
and
1. Here is the exact error
2. These are customer portal users, they were contacts who then became users once enabled. Which is why I am comparing the contactid on the user record to the imp contact.
I hope this answers your questions.
Also thank you for your comments, my SELECT statements were a little redundant there.
Does THIS Help?
does what help? i made your changes from the comments before i got the error message above.
Click on THIS in the above post.
oh, sorry
But when I do I get this: An Unexpected Error has occurred.
I get that to a lot on these forums.....
to fix simply, click in the url address and press enter or glick go. F5 to reload may work too.
http://boards.developerforce.com/t5/Apex-Code-Development/Future-Im-a-newbie/td-p/boards.developerforce.com/t5/Apex-Code-Development/Future-Im-a-newbie/td-p/342177
That is what your link goes to, thats not valid AFAIK.
http://boards.developerforce.com/t5/Apex-Code-Development/MIXED-DML-OPERATION-DML-operation-on-setup-object-is-not/td-p/135305
Lets see if this one works....
Try this-
Cheers,
Sandeep
Thank you for the code, but I dont understand the Public Class part. How do I use that? it is seperate from the triger correct? and if so where does it go?
I found the Apex Classes section and added it there. Thank you for the help, at first glance it appears to work. Let me do some more testing in my sandbox here and I will see if all is well.
Thanks so much for giving me the full code!!
Yes, you need to add the public class as new apex class. Njoy and keep learninig :)
I'm having trouble with code coverage and getting this into my production org. Can someone maybe help me get this through? So far any triggers I have gotten up there I have just guessed on. and that really isn't good for my org I'm sure.
I was able to make up enough to get it through. =)
Thanks again for all the help!!!!