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
cbccbc 

Reference a field in Salesforce Developer Console

Hi ,  I am new to Developer Console and in an installed package the code automatically assigns a file name to an attachment and then saves it. Staff use this when out in the field to gather and save signatures. The line of code is:
att.name = 'eSignature_dtd_' + Datetime.now().format('MM_dd_yyyy_HH_MM_ss'); 

The full code is as follows:
public class ZVFSignaturePadController {
    public ZVFSignaturePadController(ApexPages.StandardController stdController){
        
    }
    
    @RemoteAction
    public static String uploadSignature(String b64SignData, String id){
        returnData ret = new returnData();
        ret.success = true;
        ret.message = 'Signature uploaded successfully';
        try{
            Blob signature = EncodingUtil.base64Decode(b64SignData);
            Attachment att = new Attachment();
            att.body = signature;
            att.ContentType = 'image/png';
            att.name = 'eSignature_dtd_' + Datetime.now().format('MM_dd_yyyy_HH_MM_ss');
            att.IsPrivate = false;
            att.ParentId = id;
            insert att;
        }catch(Exception e){
            ret.success = false;
            ret.message = e.getMessage();
        }    
        
        return JSON.serialize(ret);
    }
    
    
     private class returnData{
        Boolean success {get;set;}
        String message {get;set;}
    }
}

I want to add the client name at the front of the file name. This is stored in a custom object called Client. The field names are Client First Name and Client Last Name and the API names are Client_First_Name__C and Client_Last_Name__C. These are formula fields that look up the Contact record.

I am not sure how to add the first and last names to this line of code. 
I am doing this in a sandbox at the moment.
Any help appreciated.

Sue
Kai Herng LauKai Herng Lau
Hi Sue,

Do you know where is this code get fired? If you need to get the Client info, we need to find out, where can we pass the Client First Name/Last Name into the code. What I suggest is if the uploadSignature metod is fired from a button maybe we can edit the button javascript to include the Client info into it.
cbccbc
Hi Kai, I have found that there is an upgrade to the package, so I am going to look at that. I also need to change the destination to Files and not Notes and Attachments. So I am checking if this has been amended too. 
Kai Herng LauKai Herng Lau
Hi Sue,

ok, thanks for update.