• PranayMistry
  • NEWBIE
  • 33 Points
  • Member since 2015
  • Salesforce Administrator
  • Abbvie

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
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;
}

 
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;
}

 

Hi Folks,

               How to update original object fields with update DML statement in trigger after insert event. My code:

 

trigger myTrigger on Account (after insert) {

Account myAccount = trigger.new[0];
myAccount.Type = 'Enterprise Customer';
update myAccount;
}

 

Here the update DML statement throws the exception: System.FinalException: Record is read-only:

 

Please let me know and all suggestions are appreciated with any sample code or correction to above code.

 

Thanks.