• Edward Foreaker 2
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
The saveSignature method is working for desktop only. I am trying to get the saveSignature() redirect to work on the mobile lightning app also. Could you see below and advise if the visualforce script/apex method can be adjusted to redirect to the lightning mobile object(tablet/mobile form factor) as it properly does on desktop? 

ehsSignatureExtensionController Extension - Desktop Page Ref Part of the Apex 
public pageReference saveSignature(){ pageReference page = new PageReference('https://company.lightning.force.com/lightning/r/work_order__c/'+ehs.id +'/view'); page.setRedirect(true); return page; }



Visualforce Page saveSignature() Script
function saveSignature() { 
var image = canvas.toDataURL().split(',')[1];         ehsSignatureExtensionController.saveSignature(ehsId,image,handleResult); } function handleResult(result,event) { if(result.success) { window.top.location.href='/'+ehsId; } else { alert('Error: '+result.errorMessage); } }

 
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;

}
}

 
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;

}
}
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;

}
}