• Maggie von Stein
  • 0 Points
  • Member since 2014

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1
Hi There,

I am attemping to write a simple Apex Trigger that updates the owner ID based on a picklist value.

Picklist contains the aliases of our account managers and based on this I want to update the owner ID on insert.

Reason for this is because we have administrators entering opportunities and it will save them time rather than having to create the record then change it owner.

I have the following:

trigger UpdateOwnerID on Opportunity (after insert) {
    for (Opportunity objOpportunity : Trigger.new)
        if (objOpportunity.Owner.Alias <> objOpportunity.Account_Manager__c)               
            objOpportunity.Owner.Alias = objOpportunity.Account_Manager__c;


But I keep getting this error:

Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UpdateOwnerID caused an unexpected exception, contact your administrator: UpdateOwnerID: execution of AfterInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.UpdateOwnerID: line 7, column 1

Any help would be appreciated.