+ Start a Discussion
smitha vikramsmitha vikram 

how to write unit test for apex class using flow

I have wriiten the following apex class that a flow calls.I am clueless on how to write the unit test for this, any leads or logic i can get started with is much appreciated.
global with sharing class AddCommentbuttononOpp
  Webservice static void  getOppRecord(list<FlowRequest> oppId){   // here the value of List is list of flows records of opprotinity type from the flow and the value is obtained from below
                                                                   // class flow request.
 if( oppId[0].varOpptyRecord.Comments_Next_Steps__c!=null){             // here we pass the opportunity record ie in the first position and hence[0] and that has for the opprottunity.
           oppId[0].varOpptyRecord.Comments_Next_Steps__c=system.now().format('dd_MM_yyyy') +' '+  oppId[0].varOpptyRecord.Comments_Next_Steps__c;
           string temp =  oppId[0].varOpptyRecord.Description;
     if(temp==null && !string.isNotBlank(temp)){
     oppId[0].varOpptyRecord.Description =  oppId[0].varOpptyRecord.Comments_Next_Steps__c;  
     }else if(temp!=null && string.isNotBlank(temp)){
        oppId[0].varOpptyRecord.Description =  oppId[0].varOpptyRecord.Comments_Next_Steps__c +'\n' +temp;
update oppId[0].varOpptyRecord;
//One for getting the values from Flow to Apex a
global class FlowRequest
        @InvocableVariable(label = 'Opportunity Record')  // this is a variable of data type opportunity just like an integer or decimal 
		                                                     that is declared in here so that the values declared in flow ie: the for the object with fields that gets populated from flow and is 
															 passed on from here into the class vairable oppid above.
															 here we could add mutiple values incase the flow needs any other data type such as account of contact etc.
        public Opportunity varOpptyRecord;