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
Ryan GreeneRyan Greene 

Methods defined as TestMethod do not support getContent call

I have a seemingly simple Test I wrote but when run it receives the error: Methods defined as TestMethod do not support getContent call. I do not have a .getContent call in my Test. I have narrowed down the error to most likely be the line "conid.add(con.Id);". I'm think the .add() when called acts like a .getContent()? Any thoughts on a way around the call?
Thank you,
Ryan
@isTest
public class Test_EchoSign2 {
    static testmethod void testechosign(){
    	Account ac = new Account(RecordTypeId = [SELECT Id, SobjectType, Name FROM Recordtype WHERE Name = 'Prospect/Client' AND SobjectType = 'Account' LIMIT 1].Id);
    	ac.Name = 'TestAcnt';
    	ac.Type = 'Prospect';
    	insert ac;
    
		Contact con = new Contact(RecordTypeId = [SELECT Id,SObjectType,Name FROM RecordType WHERE Name = 'Prospect/Client' AND SobjectType = 'Contact' LIMIT 1].Id);
		con.LastName = 'testLastName';
    	con.AccountId = ac.Id;
        con.Email = 'ryan.greene@outlook.com';
	    con.LeadSource = 'Unknown';
        insert con;
 
        List<Id> conid = new List<Id>();
        conid.add(con.Id);
		EchoSign.SendPdf(conid);
    }
}

 
Best Answer chosen by Ryan Greene
Alain CabonAlain Cabon
Hi,

The problem should be here: EchoSign.SendPdf(conid);

Have you got the source code of a class named EchoSign ?

You have something like that with a class EchoSign instead of SendAgreementDocument :   https://forums.adobe.com/thread/1699108

You are using a wrapper (provided) to send the agreement and some line of code in Apex in this provided wrapper cannot pass a Salesforce test (perhaps, I don't have seen your class EchoSign)

Example: pdfPage.getContentAsPDF(); cannot work directly for a test so it is replaced by pdfBody = blob.valueOf('Unit.Test'); when a test is running.

That means that you can't test the class as long as the "bad" parts are not isolated and replaced when a test is running.

That is not the test class but the tested class below:
// Build page reference for contract PDF & attach to the contract record		
pageReference pdfPage = Page.ContractPDF;
pdfPage.getParameters().put('ContractId',pContractId);
blob pdfBody;
if(Test.isRunningTest()) { 
  pdfBody = blob.valueOf('Unit.Test');
} else {
  pdfBody = pdfPage.getContentAsPDF();
}
https://developer.salesforce.com/forums/?id=906F0000000BZBmIAO

Regards

All Answers

Alain CabonAlain Cabon
Hi,

The problem should be here: EchoSign.SendPdf(conid);

Have you got the source code of a class named EchoSign ?

You have something like that with a class EchoSign instead of SendAgreementDocument :   https://forums.adobe.com/thread/1699108

You are using a wrapper (provided) to send the agreement and some line of code in Apex in this provided wrapper cannot pass a Salesforce test (perhaps, I don't have seen your class EchoSign)

Example: pdfPage.getContentAsPDF(); cannot work directly for a test so it is replaced by pdfBody = blob.valueOf('Unit.Test'); when a test is running.

That means that you can't test the class as long as the "bad" parts are not isolated and replaced when a test is running.

That is not the test class but the tested class below:
// Build page reference for contract PDF & attach to the contract record		
pageReference pdfPage = Page.ContractPDF;
pdfPage.getParameters().put('ContractId',pContractId);
blob pdfBody;
if(Test.isRunningTest()) { 
  pdfBody = blob.valueOf('Unit.Test');
} else {
  pdfBody = pdfPage.getContentAsPDF();
}
https://developer.salesforce.com/forums/?id=906F0000000BZBmIAO

Regards
This was selected as the best answer
Ryan GreeneRyan Greene
Thanks Alain
All I had to do was modify a line in my controller which did read: pdfBody = pdfPage.getContentAsPDF();
Added in the if test is running, then it worked great. New lines in controller:
        if(Test.isRunningTest()){
            pdfBody = blob.valueOf('Unit.Test');
        }else{
            pdfBody = pdfPage.getContentAsPDF();}
 
Ankit RandhawaAnkit Randhawa
This was very helpful while I'm testing a visualforce page controller for the first time.
Thanks a lot, Alain Cabon