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
Bhumi BhalodiyaBhumi Bhalodiya 

Autolaunched flow from custom button url - how to write test class to cover the Flow?

Quote is the parent class.
EPC__c and OM__c - These are the custom object under the Quote. (Means EPC and OM Contains Lookup relationship with Quote)
I have a custom button to Delete all Records on EPC and OM on Quote's related list.
Custom Link Button
And flow is like this:

Flow to delete all records which have a parent id Quote
I just want to write a test class to cover the above flow. But not able to cover the flow using below code:

Test Method

Thanks.
mukesh guptamukesh gupta
Hi Bhumui,

Can youu please send test class code, sothat i will update it

Regards
Mukesh
Bhumi BhalodiyaBhumi Bhalodiya
Hello Mukesh,
OMMassDeleteTest is my test Method.
Here I am posting it again:
 
@IsTest
public class CostBreakdownControllerTest {

    @testSetup static void setup() {
        // Create common test records

         //Create Account
         Account acc= new Account(Name='TESTacc');
         insert acc;
         
         //Create Opportunity
         Opportunity opp = new Opportunity();
         opp.Name='opTEST';
         opp.AccountId =acc.Id;
         opp.Proposal_Due_Date__c=Date.newInstance(2021, 12, 5);
         opp.CloseDate= Date.newInstance(2021, 12, 9);
         opp.StageName= 'New';
         opp.Technical_Analysis__c= 'Perform';
         insert opp;
         
         //Create Quote Record
         Quote quoteTest = new Quote(Name= 'TEST!');
         quoteTest.OpportunityId= opp.Id;
         Insert quoteTest;
         System.debug('quoteTest.Id: '+ quoteTest.Id );
         
         //Create custom settings records
         CsvToQuotesMapping__c customSettings = new CsvToQuotesMapping__c(Name= 'EPC subtotal');
         customSettings.FieldsAPIName__c = 'EPC_subtotal__c';
         customSettings.Cost_Type__c = 'EPC';
         insert customSettings;
 
         CsvToQuotesMapping__c customSettingsOM = new CsvToQuotesMapping__c(Name= 'Total O&M cost');
         customSettingsOM.FieldsAPIName__c = 'OM_cost_MNX_kWp__c';
         customSettingsOM.Cost_Type__c = 'OM';
         insert customSettingsOM;
 
         //Create EPC Breakdown Record
         list<EPC_Breakdown__c> EPCInsertList = new list<EPC_Breakdown__c>();
         EPC_Breakdown__c EPCTest1 = new EPC_Breakdown__c(Name='EPC Document One',Quote__c=quoteTest.Id);
         EPCInsertList.add(EPCTest1);

         EPC_Breakdown__c EPCTest2 = new EPC_Breakdown__c(Name='EPC Document Two',Quote__c=quoteTest.Id);
         EPCInsertList.add(EPCTest2);

         EPC_Breakdown__c EPCTest3 = new EPC_Breakdown__c(Name='EPC Document Three',Quote__c=quoteTest.Id);
         EPCInsertList.add(EPCTest3);

         insert EPCInsertList;
 
         //Create OM Breakdown Record
         list<OM_Breakdown__c> OMInsertList = new list<OM_Breakdown__c>();
         OM_Breakdown__c OMTest1= new OM_Breakdown__c(Name='OM Document One',Quote__c=quoteTest.Id);
         OMInsertList.add(OMTest1);

         OM_Breakdown__c OMTest2= new OM_Breakdown__c(Name='OM Document Two',Quote__c=quoteTest.Id);
         OMInsertList.add(OMTest2);

         OM_Breakdown__c OMTest3= new OM_Breakdown__c(Name='OM Document Three',Quote__c=quoteTest.Id);
         OMInsertList.add(OMTest3);
         insert OMInsertList;
         
        
         //Create Document
         ContentVersion cv = new ContentVersion();
         cv.Title = 'Test Document';
         cv.PathOnClient = 'TestDocument.xmls';
         cv.VersionData = Blob.valueOf('Test Content');
         cv.IsMajorVersion = true;
         Insert cv;

          //Get Content Documents
        Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cv.Id].ContentDocumentId;
        
        //Create ContentDocumentLink 
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId =  quoteTest.Id;
        cdl.ContentDocumentId = conDocId;
        cdl.shareType = 'V';
        Insert cdl;
         
    }
//OM Delete All Records Flow Test
     @isTest static void OMMassDeleteTest(){

      test.startTest();
      // Get the quote record as parent of EPC
      Quote quoteTest =  [SELECT Id FROM Quote WHERE Name='TEST!' LIMIT 1];
      List<OM_Breakdown__c> OMList = new List<OM_Breakdown__c>();
      Database.DeleteResult[] OMDeleteResult;

      if(quoteTest != null){
        Id quoteID = quoteTest.Id;
        // Get the quote record as parent of EPC
        OMList =  [SELECT Id FROM OM_Breakdown__c WHERE Quote__c =: quoteTest.Id];
      }
      if(OMList.size()>0){
        OMDeleteResult = Database.delete(OMList, false);
      }
      test.stopTest();

      for(Database.DeleteResult dr : OMDeleteResult) {
        System.assertEquals(dr.isSuccess(),true);
      }
    }
}

Thanks.