0

There is a requirement that if we have an attachment then and then only we can check a checkbox (i.e. isCreditCheckDone) and after then only we can convert lead into respective account and opportunity....but I've already provided an attachment to it and then when I'm trying to convert the lead it is showing this error (i.e. Validation error on Opportunity: Attachment required before marking credit check done).When I tried to debug and fix it. Then I come to know that this error message is written in custom setting and from there I traced back to the fact that it is from class named(i.e.TH_OpportunityValidationRule ) and method named (i.e. validateForToeslAndTcsl() ) further when I checked debug log I was able to track that the SOQL query that is written within that method is not returning any value. Further when I tried the same with admin it working but when tried it with the user have different profile it throwing same error.

        Set<Id> oppWithFilesIdSet = new Set<Id>();
    if(!requiredOppIdSet.isEmpty())
    {
        //Checking if related attachment exists or not

        List<ContentDocumentLink> contentDocLinkList = new List<ContentDocumentLink>();
        contentDocLinkList = [SELECT ContentDocumentId, LinkedEntityId  FROM ContentDocumentLink 
                            WHERE LinkedEntityId IN (SELECT Id FROM Opportunity WHERE Id IN: requiredOppIdSet) 
                            AND LinkedEntity.Type = 'Opportunity'];

        for(ContentDocumentLink objContentDocLink : contentDocLinkList)
        {
            oppWithFilesIdSet.add(objContentDocLink.LinkedEntityId);
        }

    }

    //Checking if related contact roles exist or not for TCSL short
    Set<Id> contactRoleOppIdSet = new Set<Id>();
    if(!tcslContactRoleCheckIdSet.isEmpty())
    {
        List<Opportunity> contactRoleCheckOppList = new List<Opportunity>();

        contactRoleCheckOppList = [SELECT Id , (SELECT Id FROM OpportunityContactRoles) FROM Opportunity WHERE Id IN: tcslContactRoleCheckIdSet];
        for(Opportunity objOpp : contactRoleCheckOppList)
        {
            if(objOpp.OpportunityContactRoles.isEmpty())
            {
                contactRoleOppIdSet.add(objOpp.Id);
            }
        }
    }

    for(Opportunity objNewOpp : triggerNew)
    {
        Opportunity objOldOpp = oldMap != null ? oldMap.get(objNewOpp.Id) : null;
        //Preventing conversion of TOESL type in case no attachment found
        if(((objOldOpp != null && objOldOpp.TOESL_Is_Credit_Check_Done__c != objNewOpp.TOESL_Is_Credit_Check_Done__c) || objOldOpp == null)
        && objNewOpp.TOESL_Is_Credit_Check_Done__c=='Yes'
        && objNewOpp.RecordTypeId == toeslRecordTypeID
        && !oppWithFilesIdSet.contains(objNewOpp.Id))
        {
            objNewOpp.addError(THCommonUtility.getErrorMessage('TOESL_ValidationForCredit'));
        }
        //Preventing stage change to Negotiation Review for TCSL Short if no contact role provided
        else if(contactRoleOppIdSet.contains(objNewOpp.Id))
        {
           System.debug('check point 2');
            objNewOpp.addError(THCommonUtility.getErrorMessage('TH_CV_IBG_Contact_Role_Val'));
        }
    }

Snip of Debug log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.