• Colby Juarez
  • NEWBIE
  • 0 Points
  • Member since 2016
  • Client Service/ Retail and Services
  • Agrian Inc.

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hello Developer Community!

I am tasked with updating my company's whole database so that the contact owners match the Account owners. There are around 5k records to change and it would be taxing to go through an excel sheet and change them and re-load them via dataloader. So, I figured some code could do the trick in the Developer Console via Execute Anonymous Window. Would the code below work?

User-added image

Let me know your thoughts and thank you for your time.

Tony Garand
 

Hello,

 

I wrote the following trigger to prevent deletion of a Closed Won Opportunity:

 

 


trigger CannotDeleteClosedWon on Opportunity (before delete) 

{

    if(system.Trigger.isDelete)

    {

    for (Opportunity Opps : trigger.new)

         if (Opps.StageName == 'Closed Won')

            {

            Opps.addError('Cannot delete a Closed Won Opportunity');

            }

    }




}

 

The problem, I keep getting sent to a page with the following message:

 

CannotDeleteClosedWon: execution of BeforeDelete

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.CannotDeleteClosedWon: line 5, column 29

 

Any suggestions?