function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
smitha vikramsmitha vikram 

Help needed in writing Test class for flow calling apex and updating a record

I have the following Apex class and also the a flow calling the apex class. I have made an attempt to write the test class, but  i know its not even close, can someone help me through this?
bal with sharing class AddCommentbuttononOpp
{
   @InvocableMethod
  Webservice static void  getOppRecord(list<FlowRequest> oppId){
 if(oppId!=NULL)
{
 if( oppId[0].varOpptyRecord.Comments_Next_Steps__c!=null){
           oppId[0].varOpptyRecord.Comments_Next_Steps__c=System.today().format()+' '+  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')
        public Opportunity varOpptyRecord;
}

}

test class
@isTest
public class AddCommentbuttononOppTest {
    Static testMethod void unittest(){
  try
  {
  
   Opportunity newOpp = new Opportunity( StageName = '1 - Discover Opportunity', CloseDate = Date.today() + 30, Name = 'Test Opportunity 33', Comments_Next_Steps__c='Go tigers',Description='go tigers Opportunity');
  
        insert newOpp;
        system.debug('Inserted Test Opportunity: ' + newOpp.id);
      }catch(DMLException d){ 
        system.debug(d.getDMLMessage(0));   
      }
          test.startTest();
          
    AddCommentbuttononOpp.FlowRequest varWrapper = new  AddCommentbuttononOpp.FlowRequest();
          
          varWrapper.varOpptyRecord.Comments_Next_Steps__c='test';
           AddCommentbuttononOpp.getOppRecord( new List< AddCommentbuttononOpp.FlowRequest>{  varWrapper   }) ; 
  

        Test.stopTest();
    }
}

so far