1

I'm having trouble getting my test class to pass tests. Getting:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Select from Add Placeholder Dropdown.: []

Class.TestDocManDocumentTriggerHandler.emptyPlaceHolderInsertLoan: line 24, column 1

@isTest
    public static void emptyPlaceHolderInsertLoan() {
        User usr = createUser();
        LLC_BI__DocManager__c docManager = new LLC_BI__DocManager__c(name='llc_bi_Loan__c');
        insert docmanager;

        LLC_BI__ClosingChecklist__c checklist = new LLC_BI__ClosingChecklist__c(
                    Name = 'DocCheckList',
                    LLC_BI__DocManager__c =  docmanager.id );
        insert checklist;

        LLC_BI__Loan__c loan = BatchTestUtility.addLoan(false,null);
        LLC_BI__LLC_LoanDocument__c doc = new LLC_BI__LLC_LoanDocument__c(
            Name=BatchTestUtility.loanDocman.dClass.Name,
            LLC_BI__DocType__c = BatchTestUtility.loanDocman.dType.Id,
            LLC_BI__Loan__c=loan.Id);
        system.debug('lll '+loan);
        system.debug('doccc'+doc+docmanager+checklist);

        Test.startTest();
        System.runAs(usr) {
            insert doc; //getting error here
        }
        Test.stopTest();

        doc = BatchTestUtility.refresh(doc);
        assertDocumentFields(doc);
    }

BatchtestUtility Class

public static DocManInfo loanDocman = new DocManInfo(BatchConstants.LOAN_DOC_MANAGER_NAME);
 public class DocManInfo {
        public LLC_BI__DocManager__c dMan = null;
        public LLC_BI__DocTab__c dTab = null;
        public LLC_BI__DocType__c dType = null;
        public LLC_BI__DocClass__c dClass = null;
        public LLC_BI__ClosingChecklist__c checklist = null;

        public DocManInfo(String docManName) {
            dman = (LLC_BI__DocManager__c)assignAndSave(
                [SELECT ID,Name  FROM LLC_BI__DocManager__c WHERE name =: docManName LIMIT 1],
                new LLC_BI__DocManager__c(Name = docManName));
            dtab = (LLC_BI__DocTab__c)assignAndSave(
                [SELECT ID,Name  FROM LLC_BI__DocTab__c LIMIT 1],
                new LLC_BI__DocTab__c(Name = 'DocTab',LLC_BI__DocManager__c = dMan.Id));
            dType = (LLC_BI__DocType__c)assignAndSave(
                [SELECT ID,Name  FROM LLC_BI__DocType__c LIMIT 1],
                new LLC_BI__DocType__c(Name = 'DocType',LLC_BI__DocManager__c = dMan.Id,LLC_BI__DocTab__c = dtab.Id));
            dclass =(LLC_BI__DocClass__c)assignAndSave(
                [SELECT ID,Name FROM LLC_BI__DocClass__c LIMIT 1],
                new LLC_BI__DocClass__c(Name = 'DocClass',LLC_BI__DocManager__c = dMan.Id,LLC_BI__DocType__c = dtype.Id));


            checklist = new LLC_BI__ClosingChecklist__c(
                    Name = 'DocCheckList',
                    LLC_BI__DocManager__c = dMan.Id,
                    LLC_BI__DocType__c = dtype.Id,
                    LLC_BI__DocClass__c = dClass.Id);
            checklist.put(BatchConstants.DOCUMENT_FIELD_CATEGORY_ID,'CATID');
            checklist.put(BatchConstants.DOCUMENT_FIELD_CATEGORY_NAME,'CATNAME');
            checklist.put(BatchConstants.DOCUMENT_FIELD_CLASS_NAME,'CLASSNAME');
            checklist.put(BatchConstants.DOCUMENT_FIELD_TYPE_ID,'TYPEID');
            checklist.put(BatchConstants.DOCUMENT_FIELD_TYPE_DESCRIPTION,'TYPEDESCRIPTION');

            checklist =(LLC_BI__ClosingChecklist__c)assignAndSave(
                Database.query('SELECT ID, Name, Document_Category_Id__c FROM LLC_BI__ClosingChecklist__c LIMIT 1'),
                checklist);
        }
    }

    private static sObject assignAndSave(List<sObject> existing, sObject newObject) {
        if (existing.size()>0) {
            return existing.get(0);
        }
        insert newObject;
        return newObject;
    }

My Main Class

Class is failing because if(ccl.size()>0){-- } and it is going to else part{objList[0].adderror('select from addPlacer dropdown')} enter image description here

1 Answer 1

1

Custom Validation Exception simply means that there is a validation rule or a trigger add error in your Salesforce instance that's fired when you are creating your test data .

Look for the rule or add error for with the error message "Select from Add Placeholder Dropdown" in your trigger

Understand the rule and create your test data accordingly so that the code reaches the part of the code that throws the error and then use try and catch in test class where you insert the record .

The exception message needs to be asserted .

4
  • it is not from validation rule and it is from addError('Select from Add Placeholder Dropdown'), since it is not covering if part it is going to else part
    – Eagerin Sf
    Commented Jul 18, 2019 at 13:59
  • Correct yes .Could be also trigger add error .Look at the query thats above it and make sure query returns atleast one error Commented Jul 18, 2019 at 14:02
  • Also you would need to insert in try and catch and catch the expection and assert it Commented Jul 18, 2019 at 14:03
  • this batchtestutility class is making me a lot of confusion. I tried updating code with try catch block but no luck
    – Eagerin Sf
    Commented Jul 18, 2019 at 14:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .