Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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;

    }
  }
}
share|improve this question

3 Answers 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.

share|improve this answer
    
What if i want to store the previous value of opportunity stage in some custom field..?@ Alex Tennant –  Razz Aug 8 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 at 12:19

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

share|improve this answer

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

share|improve this answer
    
i've checked everything but i'm not getting –  Razz Aug 8 at 10:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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