You need to sign in to do that
Don't have an account?
Trigger writing out current UserId and a Date
Im trying to create a simple trigger that writes out the UserId and Date (of the user triggering the trigger) to 2 custom fields.
Firstly is it possible to write out the user of the person triggering the trigger?
Secondly would something like this work? Trying to get it to trigger when the SS gets changed to 2 - Contact Made. I apologize for my shoddy coding, still learning! :)
trigger userForSS2 on Account (after update) {
if(Trigger.isUpdate & myAccount.Sales_Stage__c == '2 - Contact Made'){ myAccount.SQL_User__c = UserInfo.getUserId(); myAccount.SQL_Date__c = date.Today();
}
}
Any help would be great!
Michael
Absolutely possible.
could do the trigger before insert & update with a code something like
...for(Account myAccount : Trigger.new){ if(myAccount.Sales_Stage__c == '2 - Contact Made'){ myAccount.SQL_User__c = UserInfo.getUserId(); myAccount.SQL_Date__c = system.today(); }}...
All Answers
Absolutely possible.
could do the trigger before insert & update with a code something like
...for(Account myAccount : Trigger.new){ if(myAccount.Sales_Stage__c == '2 - Contact Made'){ myAccount.SQL_User__c = UserInfo.getUserId(); myAccount.SQL_Date__c = system.today(); }}...
Thanks for the swift responses guys!!
I managed to write some code quite similar to what you pasted below AT. But i was getting this error:
Error:Apex trigger userForSS2 caused an unexpected exception, contact your administrator: userForSS2: execution of AfterUpdate caused by: System.Exception: Record is read-only: Trigger.userForSS2: line 6, column 1
Reading the error obviously gave me the answer :) After Update wasnt a good idea!!
Thanks again for your help!
Michael