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
rajesh kumar 10rajesh kumar 10 

Hi i can a doubt in Test class for my Trigger i tried it but getting some Error can any pls tell whta the problem with my test class?

This is my trigger

trigger NCAccountApprovalSubmit on Account (after insert) {
   
   
     for (Account a : trigger.new) {
        if (a.RecordType_Name__c == 'Plant' && (a.Plant_Business_Type__c == 'New construction')
            && (a.plant_Type__c == 'potential plant')
            && (a.status__c!='active') && (a.super_region__c=='EAME')
            && (a.account_industry_type__c =='Power - Fossil'||a.account_industry_type__c =='O & G'))
        {
            Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
            app.setObjectId(a.id);
            Approval.ProcessResult result = Approval.process(app);
        }
       

    }
   
}

And this is my Test Class

static testMethod void accountApprovalSubmitTest1(){
        User ur = [Select u.Profile.Name, u.ProfileId, u.Id From User u where u.UserName = 'integration@ccivalve.com.beta' and isactive = true limit 1];
        System.runAs(ur){
            RecordType rdObj = [Select Id from RecordType where Name = 'Plant'];
            Account tempObj = new Account();
            tempObj.Name = 'Test';
            tempObj.Account_Industry_Type__c = 'Power - Fossil';
            tempObj.Country__c = 'CHINA';
            tempObj.Plant_Business_Type__c = 'Aftermarket';
            tempObj.Plant_Type__c = 'New Plant';
            tempObj.RecordTypeId = rdObj.Id;
            tempObj.Address__c = 'USA';
            tempObj.City__c = 'USA';
            tempObj.Postal_Code__c = 'USA';
            insert tempObj;
        }
}

the Error i was getting


Error Message System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process found.: []
Stack Trace Class.NCAccountApprovalSubmitTest.NCAccountApprovalSubmit.
AshwaniAshwani
Account you are inserting must enter the Approval criteria otherwise it will through error. Make sure there is a approval process for Account and record enters in its criteria.
rajesh kumar 10rajesh kumar 10
Hi for ur response

I have written this test class also but i was getting same error so can u please find it


@isTest

public class NCAccountApprovalSubmitTest {
         public static testmethod void methd1(){              
   account a1=new account();
                a1.Name='WorldOne';

                a1.RecordType_Name__c='plant';

                a1.Plant_Business_Type__c='New construction';

                a1.plant_Type__c='potential plant';

                a1.status__c='inactive';

                a1.super_region__c='EAME';

                a1.account_industry_type__c='Power - Fossil';

                insert a1;

// Create an approval request for the account

        Approval.ProcessSubmitRequest req1 =

            new Approval.ProcessSubmitRequest();

        req1.setComments('Submitting request for approval.');

        req1.setObjectId(a1.id);

        

        // Submit the approval request for the account

        Approval.ProcessResult result = Approval.process(req1);

        

        // Verify the result

        System.assert(result.isSuccess());    

     }     

}