2

i can't figure it out where i did mistake..any help would be appreciated..

trigger oppiswonchec on Opportunity (before update) {

  for(opportunity opp : trigger.new){

    opportunity oppold = trigger.oldmap.get(opp.id);

    boolean oldoppiswon = oppold.StageName.equals('Closed won');
    boolean newoppiswon = opp.StageName.equals('Closed won');

    if(!oldoppiswon && newoppiswon ){
      opp.I_am_Awsome__c = true;

    }
  }
}
3

If all you are doing is flaging Opportunities that are won then you are better off using the IsWon field to drive your logic, then it doesn't matter if you change your stage names.

It would also be a lot easier to implement this as a workflow rule that fires when a record is 'created, and any time it’s edited to subsequently meet criteria' rather than a trigger, your entry criteria would simply be Opportunity: Won equals True and then you can use a field update to populate your field.

It's also possible that this workflow is unnecessary and that you could instead build whatever logic you were going to build using it using the IsWon field instead.

  • What if i want to store the previous value of opportunity stage in some custom field..?@ Alex Tennant – RaJu Aug 8 '14 at 11:56
  • 2
    @Razz You should be able to do this by using a field update which sets the value of your field to TEXT(PRIORVALUE(StageName)). If you need more information or help with any other problems then I would recommend posting another question, rather than commenting. – Alex Tennant Aug 8 '14 at 12:19
1

This logic would be better implemented as a workflow with a field update. I would avoid using a trigger altogether in this instance.

In the setup menu, you can go to Create > Workflows and Approvals > Workflow Rules

0

Have you double checked StageName values? If you haven't changed the labels, the standard values are "Close/Won" and "Close/Lost"

  • i've checked everything but i'm not getting – RaJu Aug 8 '14 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.