Skip to main content
deleted 1181 characters in body
Source Link
Carly
  • 15
  • 1
  • 8

Trigger Handler:

public with sharing class CallReportTriggerHandler {

    public static String loanApp;

    @AuraEnabled(cacheable=true)
    public static void setFields(object[] aTrigger) {
        List<Loan_Application__c> loanAppsToUpdate = new List<Loan_Application__c>();
        Set<String> loanAppsIdSet = new Set<String>();
        List<Call_Report__c> newTrigger = (List<Call_Report__c>) aTrigger;
        for (Call_Report__c callReport : newTrigger) {
                if (String.isNotBlank(loanApp)) {
                    for (String applicationId : loanApp.split(',')) {
                        if (!loanAppsIdSet.contains(applicationId)) {
                            Loan_Application__c appObj = new Loan_Application__c();
                                appObj.Call_Report__c = callReport.Id;
                                appObj.Id = applicationId;
                                loanAppsToUpdate.add(appObj);
                                loanAppsIdSet.add(applicationId);
                        }
                    }
                }
            
            }
        
        update loanAppsToUpdate;
    }
}

Trigger Handler:

public with sharing class CallReportTriggerHandler {

    public static String loanApp;

    @AuraEnabled(cacheable=true)
    public static void setFields(object[] aTrigger) {
        List<Loan_Application__c> loanAppsToUpdate = new List<Loan_Application__c>();
        Set<String> loanAppsIdSet = new Set<String>();
        List<Call_Report__c> newTrigger = (List<Call_Report__c>) aTrigger;
        for (Call_Report__c callReport : newTrigger) {
                if (String.isNotBlank(loanApp)) {
                    for (String applicationId : loanApp.split(',')) {
                        if (!loanAppsIdSet.contains(applicationId)) {
                            Loan_Application__c appObj = new Loan_Application__c();
                                appObj.Call_Report__c = callReport.Id;
                                appObj.Id = applicationId;
                                loanAppsToUpdate.add(appObj);
                                loanAppsIdSet.add(applicationId);
                        }
                    }
                }
            
            }
        
        update loanAppsToUpdate;
    }
}

added 1581 characters in body
Source Link
Carly
  • 15
  • 1
  • 8

I have an after and before insert/update trigger that on an object called Call_Report__c. The before trigger clears a certain field of another object and the after trigger (upon save) sets the field of the Call_Report__c object. I'm not sure how to test it since I don't know how to make sure the trigger is being fired. I saw something on trailhead Database.Delete Result = Database.delete(acct, false) but can this apply in my situation? Is there one for update and insert? How do I distinguish before/after?

Currently the tests fail saying actual is null.

Trigger Handler:

public with sharing class CallReportTriggerHandler {

    public static String loanApp;

    @AuraEnabled(cacheable=true)
    public static void setFields(object[] aTrigger) {
        List<Loan_Application__c> loanAppsToUpdate = new List<Loan_Application__c>();
        Set<String> loanAppsIdSet = new Set<String>();
        List<Call_Report__c> newTrigger = (List<Call_Report__c>) aTrigger;
        for (Call_Report__c callReport : newTrigger) {
                if (String.isNotBlank(loanApp)) {
                    for (String applicationId : loanApp.split(',')) {
                        if (!loanAppsIdSet.contains(applicationId)) {
                            Loan_Application__c appObj = new Loan_Application__c();
                                appObj.Call_Report__c = callReport.Id;
                                appObj.Id = applicationId;
                                loanAppsToUpdate.add(appObj);
                                loanAppsIdSet.add(applicationId);
                        }
                    }
                }
            
            }
        
        update loanAppsToUpdate;
    }
}

I have an after and before insert/update trigger that on an object called Call_Report__c. The before trigger clears a certain field of another object and the after trigger (upon save) sets the field of the Call_Report__c object. I'm not sure how to test it since I don't know how to make sure the trigger is being fired. I saw something on trailhead Database.Delete Result = Database.delete(acct, false) but can this apply in my situation? Is there one for update and insert? How do I distinguish before/after?

Currently the tests fail saying actual is null.

I have an after insert/update trigger that on an object called Call_Report__c. The after trigger (upon save) sets the field of the Call_Report__c object. I'm not sure how to test it since I don't know how to make sure the trigger is being fired. I saw something on trailhead Database.Delete Result = Database.delete(acct, false) but can this apply in my situation? Is there one for update and insert? How do I distinguish before/after?

Currently the tests fail saying actual is null.

Trigger Handler:

public with sharing class CallReportTriggerHandler {

    public static String loanApp;

    @AuraEnabled(cacheable=true)
    public static void setFields(object[] aTrigger) {
        List<Loan_Application__c> loanAppsToUpdate = new List<Loan_Application__c>();
        Set<String> loanAppsIdSet = new Set<String>();
        List<Call_Report__c> newTrigger = (List<Call_Report__c>) aTrigger;
        for (Call_Report__c callReport : newTrigger) {
                if (String.isNotBlank(loanApp)) {
                    for (String applicationId : loanApp.split(',')) {
                        if (!loanAppsIdSet.contains(applicationId)) {
                            Loan_Application__c appObj = new Loan_Application__c();
                                appObj.Call_Report__c = callReport.Id;
                                appObj.Id = applicationId;
                                loanAppsToUpdate.add(appObj);
                                loanAppsIdSet.add(applicationId);
                        }
                    }
                }
            
            }
        
        update loanAppsToUpdate;
    }
}

Source Link
Carly
  • 15
  • 1
  • 8

How to call a trigger in a Apex Trigger Unit Test?

I have an after and before insert/update trigger that on an object called Call_Report__c. The before trigger clears a certain field of another object and the after trigger (upon save) sets the field of the Call_Report__c object. I'm not sure how to test it since I don't know how to make sure the trigger is being fired. I saw something on trailhead Database.Delete Result = Database.delete(acct, false) but can this apply in my situation? Is there one for update and insert? How do I distinguish before/after?

This is what I have so far for my test:

@isTest
public with sharing class CallReportTriggerTest {

    @isTest static void testSetFieldsMethod() {
        Call_Report__c callReport = new Call_Report__c();
        callReport.Loan_Apps_to_Relate__c = 'a071F00000A99Z4QAJ,a071F00000A99YpQAJ';
        Loan_Application__c loanAppRelate = new Loan_Application__c(Id = 'a071F00000A99Z4QAJ');
        Loan_Application__c loanAppRelate1 = new Loan_Application__c(Id = 'a071F00000A99YpQAJ');
        insert callReport;

        System.assertEquals(callReport.Id, loanAppRelate.Call_Report__c);
        System.assertEquals(callReport.Id, loanAppRelate1.Call_Report__c);
    }
}

Currently the tests fail saying actual is null.