Skip to main content
edited tags
Link
crmprogdev
  • 41k
  • 9
  • 58
  • 116
deleted 81 characters in body
Source Link
Alex S
  • 2.3k
  • 7
  • 40
  • 68

When I run the test my debug lines show that the values for those fields arein the same for both oldOppisUpdate (containingsection show that the Trigger.oldMap values from my Trigger) and newOpp -for the o.Ramp_Profile__c - (containing the& Trigger.newMapCloseDate values)fields are unchanged.

When I run the test my debug lines show that the values for those fields are the same for both oldOpp (containing the Trigger.oldMap values from my Trigger) and newOpp - o. - (containing the Trigger.newMap values).

When I run the test my debug lines in the isUpdate section show that the values for the Ramp_Profile__c & CloseDate fields are unchanged.

edited title
Source Link
Alex S
  • 2.3k
  • 7
  • 40
  • 68

Retrieve Trigger.oldMapnewMap Values In After Update Context

@isTest
public class WE_OppUpdatesTest{
    
    @testSetup
    static void dataSetup() {
        
            List<Opportunity> opportunities1 = WE_TestDataUtility.createOpportunities(
                25,                                 // noOpps
                '<*>',                              // identifier
                date.today().addMonths(1),          // closeDate
                'Standard');                        // rampProfile

            insert Opportunities1;
    }
    
    static testMethod void testOppUpdates(){
        
        List <Opportunity> opportunities = [SELECT Id,RecordTypeId,Name,CloseDate,Ramp_Profile__c FROM Opportunity WHERE Name LIKE '%<*>%'];
        
        Test.startTest();
 
        List<Opportunity> OppClsMnths = new List<Opportunity>();
        
        for(Opportunity o : opportunities){
            o.CloseDate = o.CloseDate.addmonths(1);
            o.Ramp_Profile__c = 'Immediate';
       
        }
        update opportunities;
        Test.stopTest();
    }
}

Retrieve Trigger.oldMap Values In After Update Context

@isTest
public class WE_OppUpdatesTest{
    
    @testSetup
    static void dataSetup() {
        
            List<Opportunity> opportunities1 = WE_TestDataUtility.createOpportunities(
                25,                                 // noOpps
                '<*>',                              // identifier
                date.today().addMonths(1),          // closeDate
                'Standard');                        // rampProfile

            insert Opportunities1;
    }
    
    static testMethod void testOppUpdates(){
        
        List <Opportunity> opportunities = [SELECT Id,RecordTypeId,Name,CloseDate,Ramp_Profile__c FROM Opportunity WHERE Name LIKE '%<*>%'];
        
        Test.startTest();
 
        List<Opportunity> OppClsMnths = new List<Opportunity>();
        
        for(Opportunity o : opportunities){
            o.CloseDate = o.CloseDate.addmonths(1);
            o.Ramp_Profile__c = 'Immediate';
       
        }
        update opportunities;
        Test.stopTest();
    }
}

Retrieve Trigger.newMap Values In After Update Context

@isTest
public class WE_OppUpdatesTest{
    
    @testSetup
    static void dataSetup() {
        
            List<Opportunity> opportunities1 = WE_TestDataUtility.createOpportunities(
                25,                                 // noOpps
                '<*>',                              // identifier
                date.today().addMonths(1),          // closeDate
                'Standard');                        // rampProfile

            insert Opportunities1;
    }
    
    static testMethod void testOppUpdates(){
        
        List <Opportunity> opportunities = [SELECT Id,RecordTypeId,Name,CloseDate,Ramp_Profile__c FROM Opportunity WHERE Name LIKE '%<*>%'];
        
        Test.startTest();
        
        for(Opportunity o : opportunities){
            o.CloseDate = o.CloseDate.addmonths(1);
            o.Ramp_Profile__c = 'Immediate';
       
        }
        update opportunities;
        Test.stopTest();
    }
}
Added Unit Test for context
Source Link
Alex S
  • 2.3k
  • 7
  • 40
  • 68
Loading
Source Link
Alex S
  • 2.3k
  • 7
  • 40
  • 68
Loading