1

I'm having this method which I can't test in my test class.

It's my call on my ReplayFuture.cls, wich is called from my oppbatch class.

if(replayRecord.MethodName__c ==
ReplayConstants.CREATEQUESTIONARIE_AND_POPULATEVALUE_INUSERRELATEDFIELD_FUTURE){
                           String inputVal1 = replayRecord.InputParameterValue1__c;
                            Map<String,Boolean> inputVal2 = (Map<String,Boolean>)JSON.deserialize(replayRecord.InputParameterValue4__c,Map<String,Boolean>.class);
                            OM_R1_Opportunity_Batch.createQuestionarieAndPopulatevalueInUserRelatedfieldFuture(inputVal1,inputVal2,replayId,isReplay);

                        }

So, here is an example of wath i made, but i can't finish this one.

for example in this case:

if(replayRecord.MethodName__c ==
ReplayConstants.POPULATE_VALUE_IN_SALES_CREDIT_APPROVER_EMPLOYEEID_FUTURE_STR){
                            Set<ID> inputVal1 = (Set<ID>)JSON.deserialize(replayRecord.InputParameterValue1__c,Set<ID>.class);
                            OM_R1_Opportunity_Batch.populatevalueInSalesCreditApproverEmployeeIdFuture(inputVal1,replayId,isReplay);
                        }

In my testClass I have this:

My replay method creation

static Replay__c createReplayRecord(String className, String
 methodName,String errorMessage,Decimal replayCount,String
 inputParamVal1,String inputParamVal2,
                                          String inputParamVal3,String inputParamVal4,String inputParamVal5,String inputParamVal6,String
 inputParamVal7,String inputParamVal8){

         Replay__c replay = new Replay__c();
         replay.ClassName__c = className;
         replay.MethodName__c = methodName;
        replay.ErrorMessage__c = errorMessage;
         replay.InputParameterValue1__c = inputParamVal1;            
         replay.InputParameterValue2__c = inputParamVal2;            
         replay.InputParameterValue3__c = inputParamVal3;            
         replay.InputParameterValue4__c = inputParamVal4;            
         replay.InputParameterValue5__c = inputParamVal5;            
         replay.InputParameterValue6__c = inputParamVal6;            
         replay.InputParameterValue7__c = inputParamVal7;            
         replay.InputParameterValue8__c = inputParamVal8;            
         replay.ReplayStatus__c = UTIL_Constants.NOT_STARTED_STR;
         replay.ReplayCount__c = replayCount;

         insert replay;      
         return replay;
     }


My set <ID> creation

  static Set<Id> createIdSet(){
         Set<Id> idSet = new Set<Id>();      
         Account accToInsert = createTestAccount('123','5652474');
         idSet.add(accToInsert.Id);          
         return idSet;
     }

And my testing method:

replayRecord =
 createReplayRecord(ReplayConstants.OM_R1_OPPORTUNITY_BATCH_STR,ReplayConstants.POPULATE_VALUE_IN_SALES_CREDIT_APPROVER_EMPLOYEEID_FUTURE_STR,'Test
 Error
 OM_R1_Opportunity_Batch',0,JSON.serialize(idSet),null,null,null,null,null,null,null);
         result = ReplayFutureCall.invokeFutureCall(replayRecord.Id);
         System.assertEquals(UTIL_Constants.SUCCESS_STR,result);

So, can you help me up with my first example?

  • Since you're calling an @future method that's in a different class, what you'll want to do is create mock response of the expected results. See Mock in the Apex Code Developer Guide. – crmprogdev Jan 15 '16 at 16:10

Your Answer

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

Browse other questions tagged or ask your own question.