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
Edward Foreaker 2Edward Foreaker 2 

Signature Controller Extension Unit Test. Please Help.

Hello, 

I am an inexperienced admin and could really use some assistance testing any portion of the below code.

Thanks very much.
 
public with sharing class ehsSignatureExtensionController {

private final My_Work_Order__c ehs;

public ehsSignatureExtensionController(ApexPages.StandardController controller) {
    ehs = (My_Work_Order__c)controller.getRecord();
}

@RemoteAction public static RemoteSaveResult saveSignature(Id ehsId, String signatureBody) {
    Attachment a = new Attachment(ParentId=ehsId, name='Signature.png', ContentType='image/png', Body=EncodingUtil.base64Decode(signatureBody));
    Database.saveResult result = Database.insert(a,false);
    RemoteSaveResult newResult = new RemoteSaveResult();
    newResult.success = result.isSuccess();
    newResult.attachmentId = a.Id;
    newResult.errorMessage = result.isSuccess()?'':result.getErrors()[0].getMessage();
    return newResult;
}

public class RemoteSaveResult {
    public Boolean success;
    public Id attachmentId;
    public String errorMessage;
}

public pageReference saveSignature(){
    pageReference page = new PageReference('https://cunning-fox-3wdgx9-dev-ed.lightning.force.com/lightning/r/My_Work_Order__c/'+ehs.id +'/view');
    page.setRedirect(true);
    return page;

}
}

 
PriyaPriya (Salesforce Developers) 
Hi Edward,

Can you please refer the below link similar to your requirement.
https://developer.salesforce.com/forums/?id=906F0000000MKtOIAW
Run the test class to validate .

Hope this is helpful..Please mark this as best answer

Regards,
Ranjan