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
Mathew AbrahamMathew Abraham 

Test class sample for HttpSender Trigger

Could someone please help me write a test class for the attached Trigger?  I am completely lost - nothing I tried is working!!  Thank you for your help.  Appreciate it.
trigger SendUpdatedAccountToMirth on Account (after insert, after update){
    for (Account a : trigger.new){
        if(a.Status__c == 'Screening Scheduled' && a.Status_Detail__c == 'Scheduled'){
            String sendingJsonStr;
            Object sendingJson;
            
            sendingJson =
                new Map<String, String>{
                        'SalesForceId' => a.Id,
                        'CureMdId' => a.CureMD_Account__c,
                        'Title' => a.PersonTitle,
                        'FirstName'  => a.FirstName,
                        'MiddleName' => null,
                        'LastName' => a.LastName,
                        'Gender' => a.Gender__c,
                        'ClinicName' => a.Clinic_Name__c,
                        'BirthDate' => String.valueOf(a.PersonBirthDate),
                        'Status' => a.Status__c,
                        'StatusDetail' => a.Status_Detail__c,
                        'Street' => String.valueOf(a.BillingStreet),
                        'City' => a.BillingCity,                
                        'State' => a.BillingState,
                        'PostalCode' => a.BillingPostalCode,
                        'PhoneContacted' => a.Phone_Contacted__c,
                        'PhoneCell' => a.Phone_Cell__c,
                        'PhoneHome' => a.Phone_Home__c,
                        'PhoneWork' => a.Phone_Work__c,
                        'Email' => a.PersonEmail
                        };
                            
            sendingJsonStr = JSON.serialize(sendingJson);
            System.debug('Sending JSON: ' + sendingJsonStr);
            HttpMirthSender.sendAccount(sendingJsonStr);
        }
    }
}

 
AnudeepAnudeep (Salesforce Developers) 
Hi Matthew, 

You have callouts defined in your code so you need to test the callout with HttpCalloutMock. 

I suggest looking at the example in the section Test a Callout with StaticResourceCalloutMock from this Trailhead Module and write your test class based on that

Anudeep