function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NasipuriNasipuri 

Trigger

Hi,

 

I am very new to Apex Cade.

 

I am trying to write a trigger for Opportunity object as below.

This is intended to assign the Opportunity with Amount greater than amount 500 to a specific user.

Code:
trigger DinTestTrig on Opportunity (after insert ) {
Opportunity opp = new Opportunity() ; 
if(opp.Amount >=500)
{
opp.OwnerId='00550000000s6RGAAY';
}

}

But the trigger is not working, i.e. the owner is not changing accordingly.

 

Can anybody please help?

 
Thanks
Dinesh Nasipuri
mtbclimbermtbclimber
You can not modify values on the target objects in the request in after triggers. Try changing your trigger to being before:

trigger DinTestTrig on Opportunity (before insert ) {...}

NasipuriNasipuri

Hi,

Thanks for your response.

But when I am creating an opportunity with amount greater than 500 the owner is not changing.

 

Thanks,

Dinesh Nasipuri

 

SuperfellSuperfell
That'll never do anything because you create a new blank opportunity and look at the properties of that, and not the trigger context values. Try this.

trigger DinTestTrig on Opportunity (before insert ) {
for(Opportunity opp : Trigger.new) {
if(opp.Amount >=500)
{
opp.OwnerId='00550000000s6RGAAY';
}
}
}

Message Edited by SimonF on 08-13-2007 10:35 PM

NasipuriNasipuri

Thank you Simon .it is working fine now.

Regards,

Dinesh Nasipuri