You need to sign in to do that
Don't have an account?
Test class for an after insert trigger
Can someone please help me write a test class for an after insert trigger. I am newbie to Salesforce and trying to figure out the promote the trigger from Sandbox to Production. Below is the trigger source code.
trigger SetUserExpirationDate on User (after insert) { List<User> ul = new List<User>(); for (User u : Trigger.new) { User usertoUpdate = new User(Id = u.Id, Expiration_Date__c = u.CreatedDate.addYears(3)); ul.add(usertoUpdate); } update ul; }
Try this code
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex
All Answers
Try this code
As a common practice, if your question is answered, please choose 1 best answer.
But you can give every answer a thumb up if that answer is helpful to you.
Thanks,
Alex
Hi Alex,
Thanks a ton for the swift response, the unit test class worked like a charm. but unfortunately the code coverage is still 26%, even though I dont have any other trigger in my ORG or any other custom code in my ORG. Can you please help me know why this would be.
Thanks,
Pranay
Hi Pranay,
Please try the below test class and let me know if you face any issues:
I get the below error
Shyama