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
PARISE RAVIKIRANPARISE RAVIKIRAN 

System.AssertException: Assertion Failed: Expected: Consented, Actual: null Class.LeadTriggerUtilityTest.duplicateLeadOptInInsertEloquaUser: line 1390, column 1

 @isTest
    static void duplicateLeadOptInInsertEloquaUser() {
        User elqIntUser = [Select Id from User where username = :Label.Eloqua_Integration_User_Name limit 1];
        
Test.startTest();
        System.runAs(elqIntUser) {
            Lead sfdcLead2 = CreateLead('John', 'duplicateLeadOptInInsertEloquauser', notOptInOrOut, 'Docusign', 'United States');
            sfdcLead2.HasOptedOutOfEmail = false;
            sfdcLead2.Hard_Opt_In__c = true;
            LeadTriggerControl.executeAfterUpdate = true;
            Database.DMLOptions dml2 = new Database.DMLOptions();
            dml2.DuplicateRuleHeader.AllowSave = true;
            Database.SaveResult sr2 = Database.insert(sfdcLead2, dml2);

            Lead l1 = GetLeadById(sfdcLead2.Id);
            System.assertEquals(false, l1.Outreach_Opt_Out__c);
            System.assertEquals(LeadToOpportunityUtilityCls.CONSENTED, l1.Email_Consent_Status__c);
        }
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Parise,



You are getting the value of Email_Consent_Status__c as Null. But in the assert statement you are expecting the vallue as "Consented". Can you check if the assert is correct ?

Let me know if you face any issues.

If this solution helps, Please mark it as best answer.

Thanks,
PARISE RAVIKIRANPARISE RAVIKIRAN
Ho to check whether it is correct or not
 
Sai PraveenSai Praveen (Salesforce Developers) 
Hi Parise,

You need to check the trigger logic for which you have written the test class for and see if you are making thet field as "Consented" or not.

it is very hard to tell which point you made mistake as you have not shared the Trigger and test class entirely.

Thanks,
 
PARISE RAVIKIRANPARISE RAVIKIRAN
/*************************************************************
     * Method Name  : updateDuplicateLeadsForScoreAndOptOutInsTest
     * Description  : Test the score, OptIns and OptOuts
     * Return Type  : n/a
     * Parameters   : none
     **************************************************************/
    @isTest
    static void updateDuplicateLeadsForScoreAndOptOutInsTest(){
        User elqIntUser = [Select Id from User where username = :Label.Eloqua_Integration_User_Name limit 1];
        
        Test.startTest();
        System.runAs(elqIntUser) {
            Lead sfdcLead6 = CreateLead('John', 'Lead 3', OptInOptOutScore, 'Docusign', 'United States');
            sfdcLead6.Enagement_Score__c = 10;
            sfdcLead6.Profile_Score__c = 5;
            sfdcLead6.Hard_Opt_In__c = true;
            LeadTriggerControl.executeAfterUpdate = true;
            Database.DMLOptions dml3 = new Database.DMLOptions();
            dml3.DuplicateRuleHeader.AllowSave = true;
            Database.SaveResult sr3 = Database.insert(sfdcLead6, dml3);
        }
        Test.stopTest();

        Lead[] leads = GetLeadsByEmail(OptInOptOutScore);
        System.assertEquals(3, leads.size(), leads.size());

        for (Lead l : leads) {
            system.assertEquals(true, l.Hard_Opt_In__c);
            system.assertEquals(10, l.Enagement_Score__c);
            system.assertEquals(5, l.Profile_Score__c);
        }

        Contact[] contacts = GetContactsByEmail(OptInOptOutScore);
        System.assertEquals(1, contacts.size(), contacts.size());

        for (Contact c : contacts) {
            System.assertEquals(false, c.Outreach_Opt_Out__c);
            System.assertEquals(LeadToOpportunityUtilityCls.CONSENTED, c.Email_Consent_Status__c);
            System.assertEquals(true, c.Hard_Opt_In__c);
        }
    }
Sai PraveenSai Praveen (Salesforce Developers) 
Hi ,

Firstly once you execute GetLeadsByEmail method now check what is the value you are getting the field and then use assertequals based on the value.

Same with GetContactsByEmail as well.

Thanks,