I have a process builder which perform apex invocable action. Its working fine in dev sandbox and this are the components I have built: 1. Process Builder 2. Apex Invocable class (ProcessBuilderClass) 3. Associated test class (ProcessBuilderClass_Test)
When I run my test class in Dev sandbox, all test methods are pass. But, when I try to deploy to QA sandbox through change set where I include above components and when I validate by running my test class, it got failed.
Just for reference, here is my code:
Process Builder: My Process builder criteria: Whenever recordtype/stagename/ownerId of opportunity changes, it will call apex class. Which will update time stamp field on opportunity. And its active only Here is my class code:
public class TestTimeStampUpdate {
@InvocableMethod
public static void UpdateTimeStamp(List<Id> opptyIds)
{
List<Opportunity> oppList = new List<Opportunity>();
for(Id oppId : opptyIds) {
Opportunity opp = new Opportunity();
opp.Id = oppId;
opp.TestField__c = DateTime.now().getTime();
oppList.add(opp);
}
if(!oppList.isEmpty()) {
update oppList;
}
}
}
Here are my test methods that are pass in dev sandbox, but not while deploying to QA:
@isTest
private class TestTimeStampUpdate_Test {
static testMethod void TestMethod2() {
test.startTest();
Opportunity opp = getOpportunity(); // Insert and return opportuntiy
opp.StageName = '2 - StageII';
Decimal testTS = opp.TestField__c;
update opp;
Opportunity oppRec = [SELECT id,TestField__c FROM Opportunity WHERE Id =: opp.Id];
System.assert(oppRec.TestField__c > testTS);
test.stopTest();
}
static testMethod void TestMethod1() {
test.startTest();
Opportunity opp = getOpportunity();
Decimal testTS = opp.TestField__c;
User usr = getUser();
opp.OwnerId = usr.Id;
update opp;
Opportunity oppRec = [SELECT id,TestField__c FROM Opportunity WHERE Id =: opp.Id];
System.assert(oppRec.TestField__c > testTS);
test.stopTest();
}
}
Please help me out where I am missing ? I really appreciate for your help.