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
samsam 

Help on test data for this test method

 public static void sendContractExpiryEmail(List<Contract> contractList,Map<Id,Contract> oldContractMap){
        Set<Id> accIds = new Set<Id>();
        List<Account> sentemailAccounts = new List<Account>();
        List<Account> accs2Update = new List<Account>();
        for(Contract con : contractList){
            Contract oldCon = oldContractMap.get(con.Id);
            Decimal consumedPercent;
            if(con.Adjusted_Contract_Amount__c != null
               &&con.Consumed_Amount__c != null
               && con.Adjusted_Contract_Amount__c >0 ){
                   consumedPercent = (con.Consumed_Amount__c / con.Adjusted_Contract_Amount__c)*100; 
               }
            if(con.Business_Type__c == 'ACR'
               && con.Contracted_ACR_Package__c != null
               && consumedPercent >= Decimal.valueOf(Label.ContractExpiryEmailThresholdPercent)
               && consumedPercent != null){
                   accIds.add(con.AccountId);
               }
        }
        Boolean expiryByDate = false;
        
        if(accIds.size() >0){
            for(Account acc : [SELECT AccountNumber,Name,Balance_Amount__c,Point_Of_Contact_Email__c,
                                   Annual_Contract_Balance__c,Active_Contract__c,Consumed_ACR_Amount__c,
                                   Active_Contract__r.of_Contract_Consumption__c,Active_Contract__r.Consumed_Amount__c,
                                   Adjusted_Contract_Amount__c,Contract_Start_Date__c,Contract_Amount__c,
                                   Consumed_Amount__c,Contract_End_Date__c,ST_Total_Consumable_ACR_Amount__c,
                                   (SELECT ContactId,AccountId,Contact.Email,Roles FROM AccountContactRelations WHERE Roles includes ('Finance','Invoice Recepient')),
                                   Email_Sent_at_85_Consumption__c,Email_Sent_at_90_Consumption__c,Email_Sent_at_95_Consumption__c,
                                   Email_Sent_at_98_Consumption__c,Email_Sent_at_100_Consumption__c,of_Contract_Consumption__c
                                   FROM Account 
                                   WHERE Id IN :accIds
                                   AND Contracted_ACR_Package__c != null] ){
                                   if(acc.AccountContactRelations.size() >0){
                                       
                                       if(acc.Active_Contract__r.of_Contract_Consumption__c >=85 && acc.Active_Contract__r.of_Contract_Consumption__c <90 && !acc.Email_Sent_at_85_Consumption__c){
                                           sentemailAccounts.add(acc);
                                           acc.Email_Sent_at_85_Consumption__c = true;
                                           accs2Update.add(acc);
                                       }
                                       
                                       else if(acc.Active_Contract__r.of_Contract_Consumption__c >=90 
                                               && acc.Active_Contract__r.of_Contract_Consumption__c <95 
                                               && !acc.Email_Sent_at_90_Consumption__c){
                                                   sentemailAccounts.add(acc);
                                                   acc.Email_Sent_at_90_Consumption__c = true;
                                                   accs2Update.add(acc);
                                               }
                                       
                                       else if(acc.Active_Contract__r.of_Contract_Consumption__c >=95 
                                               && acc.Active_Contract__r.of_Contract_Consumption__c <98 
                                               && !acc.Email_Sent_at_95_Consumption__c){
                                                   sentemailAccounts.add(acc);
                                                   acc.Email_Sent_at_95_Consumption__c = true;
                                                   accs2Update.add(acc);
                                               }
                                       
                                       else if(acc.Active_Contract__r.of_Contract_Consumption__c >=98 
                                               && acc.Active_Contract__r.of_Contract_Consumption__c <100 
                                               && !acc.Email_Sent_at_98_Consumption__c){
                                                   system.debug('Account 95-98'+acc.name);
                                                   sentemailAccounts.add(acc);
                                                   acc.Email_Sent_at_98_Consumption__c = true;
                                                   accs2Update.add(acc);
                                               }
                                       
                                       else if(acc.Active_Contract__r.of_Contract_Consumption__c >=100 
                                               && !acc.Email_Sent_at_100_Consumption__c){
                                                   sentemailAccounts.add(acc);
                                                   acc.Email_Sent_at_100_Consumption__c = true;
                                                   accs2Update.add(acc);
                                               }
                                       
                                   }
                               }
        }
        if(accs2Update.size() > 0){
            try{
                update accs2Update;
            }catch(Exception ex){
                system.debug('Insert Failed for Consumption Account:::'+ex.getMessage());
            }
        }
        if(sentemailAccounts.size() > 0){
            List<Messaging.SingleEmailMessage> mailingList = SendEmailUtility.ContractExpiryEmailSender(Label.ContractConsumptionExpiryEmailTemplateName ,sentemailAccounts,expiryByDate);
            Messaging.SendEmailResult[] results = Messaging.sendEmail(mailingList);
        }       
    }
    
PriyaPriya (Salesforce Developers) 
Hey Sam,

have you tried wrting any test code for this ?

The developer community recommends providing any attempts/code you've started, any errors you're getting, or where exactly you're struggling in achieving this while posting a question.


Thanks,

Priya Ranjan