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
anzar_crmanzar_crm 

APEX Test Class

Hi,

 

I'm new to APEX and i would like to create an APEX test class for my APEX class. This class is triggered by 4 triggers from two ojects. Here is the code for one trigger and APEX class:

 

TRIGGER Example:

 

trigger OptyCountryLookUpBeforeUpdate on Opportunity (before update) {
    
    String keys= '';
    List<Opportunity> Opty= new List<Opportunity>();
    Map<String, List<Opportunity>> OptyMap= new Map <String, List<Opportunity>>();
    // Loop through all records in the Trigger.new collection
    for(Opportunity o: Trigger.new) {
        keys= o.RegionShort__c + o.CountryOfDestination__c + o.PLShort__c;
        Opty.add(o);
        OptyMap.put(keys, Opty);
    }
    if (OptyMap.size() != 0) {
        AP63OpportunityTerangaDimension.updateOptyCountryLookup(OptyMap);
    } else {
        System.Debug('## UpdateOptyLookUpField no country lookup to update for '+Trigger.new.size()+' opportunities');
    }
}

 

 

 APEX Class

public class AP63OpportunityTerangaDimension {
    public static void updateOptyCountryLookup(Map<String, List<Opportunity>> opportunities) {
        for (TerangaDimension__c d: [SELECT Id, CONCAT__c from TerangaDimension__c where CONCAT__c IN :opportunities.keySet()]) {
            for (Opportunity o: opportunities.get(d.CONCAT__c )) {
                o.Country__c = d.Id;
            }
        }
    }
    
    public static void updateTerangaCountryLookup(Map<String, List<Teranga__c>> teranga) {
        for (TerangaDimension__c d: [SELECT Id, CONCAT__c from TerangaDimension__c where CONCAT__c IN :teranga.keySet()]) {
            for (Teranga__c t: teranga.get(d.CONCAT__c )) {
                t.Country__c = d.Id;
            }
        }
    }
}

 Thank you for help,

 

All the best,

 

Anzar,

Jerun JoseJerun Jose
To test you trigger and class you will need to update an opportunity record in a testmethod.