• suryaaSarvesh
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hello,

I am a newbie to Apex triggers and need an advice with the following requirement.

Requirement:

We need to have a report generated out of UserPackageLicense object to track number of managed package licenses being used. With my reasearch, I figured out reporting on UserPackageLicense object is not possible since it is not exposed in reporting.

Hence I decided to have a custom pick list at user object and whenever there is an update to a user object, I tried to fire a trigger to go and check UserPackageLicense object for that user and update the custom pick list in user object. I started with the below code to test

trigger UPackageLicense on User (before update) {
    List<UserPackageLicense> up =new List<UserPackageLicense>();
    for(User u : Trigger.new){
        u.Id=up.UserId;
        u.Trigger__c=up.UserId;
       Update u;
    }
}

But getting a below error
AfterUpdate caused by: System.FinalException: Record is read-only

Any help is much appreciated!

Thanks,