• Alexandra Petrescu
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,

I am extremely new at writing apex code and I managed to write a trigger, but I don't quite know how to write a test class for it. My trigger looks like this:

trigger Changestage on Opportunity ( before update) {

    set<ID> oppId = new set<ID>();
    for (Opportunity opp: Trigger.new) {
    if ((opp.StageName == 'Detailed Design') && (trigger.oldMap.get(opp.Id).StageName == 'Concept Design') && (opp.Equipment_Margin__c == null)) {
          opp.addError('Cannot move the stage to Detailed Design if the Equipment Margin is empty');
        }  
    }
}

Any help is much appreciated.

Thank you!

Alexandra
Hi,

I am extremely new at writing apex code and I managed to write a trigger, but I don't quite know how to write a test class for it. My trigger looks like this:

trigger Changestage on Opportunity ( before update) {

    set<ID> oppId = new set<ID>();
    for (Opportunity opp: Trigger.new) {
    if ((opp.StageName == 'Detailed Design') && (trigger.oldMap.get(opp.Id).StageName == 'Concept Design') && (opp.Equipment_Margin__c == null)) {
          opp.addError('Cannot move the stage to Detailed Design if the Equipment Margin is empty');
        }  
    }
}

Any help is much appreciated.

Thank you!

Alexandra