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
Medhanie Habte 37Medhanie Habte 37 

Methods defined as TestMethod do not support Web service when developing trigger/class for echoSign integration

Hi all, I have developed an apex class and trigger to automatically deploy echoSign agreements based on a criteria that is met in the trigger. However, it appears a web service is being called when I design the class, and implement a test class. 

The goal with this trigger is to automate the sending of agreement templates from echoSign to the contact who will sign the agreement. 
With the @future callout the trigger creates the object but does not run. However without it, it does. Needless to say without the @future callout the test class fails with the Methods defined as TestMetod do not support web service.

Are there any steps I should take.

Here's the class
public class AutoSendAdobeSign { 
    public static void sendAgreement(Id temId, Id mteId) { 
    try {
           System.debug('Calling AgreementTemplateService.load: ' + temid + ' - ' + mteid); 
           echosign_dev1.AgreementTemplateService.load( temid , mteid );        
    } catch (Exception E) { System.debug('Exception: ' + e.getStackTraceString());}       

The Trigger with the specified crtieria to run
trigger SendMTEviaAdobeSign on Member_Term_Evaluation__c (after update) {
        //This Class Automatically Sends an Adobe Sign Agreement for the Member_Term_Evaluation Custom Object

        //For the PY17 Member Term Evaluation, this variable can be updated according to Program Year
    String templateId; 
           templateId = [SELECT Id FROM echosign_dev1__Agreement_Template__c WHERE Name = 'Evaluation' ].Id;
    //Only send when the Signed By Supervisor field is checked off
            for(Member_Term_Evaluation__c mte: {
                if(mte.Id != NULL && mte.Date_of_Review__c != NULL && mte.Signed_by_Supervisor__c != Trigger.oldMap.get(mte.Id).Signed_by_Supervisor__c ){
                        String masterId = mte.Id;
                        AutoSendAdobeSign.sendAgreement(templateId, masterId);
                        system.debug(mte.Service_Member__r.FirstName + ' and ' + mte.Lead_Supervisor__r.LastName + ' will be getting their member term evaluation on ' + mte.Date_of_Review__c.format() + ' .');

Here is my Test Class
private class SendMTEviaAdobeSignTest {

static testMethod void insertNewmasterId() {

RecordType servicememberRT = [SELECT Id from RecordType WHERE sObjectType = 'Contact' AND Name = 'Service Member' LIMIT 1];

    Echosign_dev1__SIGN_Merge_Mapping__c adobemm = new Echosign_dev1__SIGN_Merge_Mapping__c();
     adobemm.Name                                = 'masterId';
     adobemm.echosign_dev1__Default__c           = FALSE;
     insert adobemm;                 

    Echosign_dev1__Agreement_Template__c adobeat = new Echosign_dev1__Agreement_Template__c();
     adobeat.Name                                   = 'PY17 Service Member Term Evaluation';
     adobeat.Echosign_dev1__Auto_Send__c            = TRUE;
     adobeat.Echosign_dev1__Name__c                 = 'Adobe Sign Agreement';
     adobeat.Echosign_dev1__Signature_Type__c       = 'e-Signature';
     adobeat.Echosign_dev1__Language__c             = 'English (United States)';
     adobeat.Echosign_dev1__Merge_Mapping__c        =;
     insert adobeat;

    Account servicesite = new Account();
     servicesite.Name                           = 'Cheesy Does It';
     servicesite.Type                           = 'Education';
     servicesite.BillingStreet                  = '704 NE Sample Street';
     servicesite.BillingCity                    = 'Portland';
     servicesite.BillingState                   = 'Oregon';
     servicesite.BillingPostalCode              = '97212';
     servicesite.Organization_Sub_type__c       = 'School';
     servicesite.Service_Site_Status__c         = 'Active';
     servicesite.School_Status__c               = 'Active';
     insert servicesite;

    Contact servicemember = new Contact();
     servicemember.FirstName                    = 'Macaroni';
     servicemember.LastName                     = 'Cheese';
     servicemember.Npe01__HomeEmail__c          = '';
     servicemember.RecordTypeId                 =  servicememberRT.Id;
     insert servicemember;

    Contact leadsupervisor = new Contact();
     leadsupervisor.FirstName                   = 'Head';
     leadsupervisor.LastName                    = 'Cheese';
     leadsupervisor.Npe01__HomeEmail__c         = '';
     leadsupervisor.Service_Site_Supervisor2__c = 'Active, Primary';
     insert leadsupervisor;

    Member_Term__c mt = new Member_Term__c();
     mt.Service_Member__c                       = servicemember.Id;
     mt.Service_Site__c                         = servicesite.Id;
     mt.Lead_Supervisor__c                      = leadsupervisor.Id;
     mt.Date_Contract_Signed__c                 =;
     mt.Date_Enrolled__c                        =;
     mt.School_1__c                             = 'Cheesy Does It';
     mt.Healthy_Progress_Report_Area_1__c       = 'B - Field trips, farmer and chef visits';
     mt.Healthy_Progress_Report_Goal_1__c       = 'Win a Million Bucks';
     mt.Goal_1_Resources_Needed__c              = 'A Million Bucks';
     insert mt;

    Member_Term_Evaluation__c mte = new Member_Term_Evaluation__c();
     mte.Member_Term__c                         = mt.Id;
     mte.Service_Member__c                      = servicemember.Id;
     mte.Lead_Supervisor__c                     = leadsupervisor.Id;
     mte.Date_of_Review__c                      =;
     mte.Signed_by_Service_Member__c            = TRUE;
     mte.Signed_by_Supervisor__c                = FALSE;
     insert mte;

     mte.Signed_by_Supervisor__c                = TRUE;
     update mte;
    echosign_dev1__SIGN_Agreement__c e = new echosign_dev1__SIGN_Agreement__c();
     e.Name                                    = 'Service Member Term Evaluation';
     e.ECHOSIGN_DEV1__AGREEMENTLOCALE__C       = 'English (United States)';
     e.ECHOSIGN_DEV1__SIGNATURETYPE__C           = 'e-Signature';
     e.ECHOSIGN_DEV1__STATUS__C                  = 'Out for Signature';
     insert e; 


Rakesh Kumar SainiRakesh Kumar Saini
There are 2 points : 

1. You can not make synchornous callouts from trigger context. To make callouts from trigger you need to call @future method from trigger and make that callout in that future method.

2. for writing test case for webservice callouts, you need to setmock of WebserviceMock class in between Test.start and Test.stop mehtod.
Check link.