How to use the escapeSingleQuotes method?

Code Snippet :

public static String getRowById(String sobjName, Id id) {
    Map<String, Schema.SObjectField> objectFields =
        Schema.getGlobalDescribe().get(sObjName).getDescribe().fields.getMap();

    return 'SELECT ' + String.join( objectFields.keySet(), ', ')
           + ' FROM ' + sObjName
           + ' WHERE Id = \'' + String.escapeSingleQuotes(Id) + '\''
           + ' LIMIT 1';
}

Handling Inline images in Inbound Email Service Salesforce

Apex Code :

global class InboundEmailHandler implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        system.debug('==================');
        system.debug(string.join(email.ccAddresses,','));
        system.debug(email.fromAddress);
        system.debug(email.fromName);
        system.debug(email.inReplyTo);
        system.debug(email.messageId);
        system.debug(email.plainTextBody);
        system.debug(email.references);
        system.debug(email.replyTo);
        system.debug(email.subject);
        system.debug(string.join(email.toAddresses,','));
        //system.debug(email.headers);
        //system.debug(email.htmlBodyIsTruncated);
        //system.debug(string.join(email.textAttachments,','));
        //system.debug(string.join(email.headers,','));
        //system.debug(email.htmlBody);
        //system.debug(string.join(email.binaryAttachments,','));
        system.debug('==================');
       
        Lead lead = new Lead();
        lead.LastName =email.fromName;
        lead.Description = string.join(email.ccAddresses,',') +'\n'+ email.messageId +'\n'+ email.references +'\n'+ email.replyTo +'\n'+ email.htmlBodyIsTruncated +'\n'+ string.join(email.headers,',') +'\n'+ string.join(email.binaryAttachments,',');
        lead.recordtypeId='0120Y0000002qJe';
        lead.Email = email.fromAddress;
        lead.Company = 'N/A';
        lead.HTML_Body__c = email.htmlBody;
        insert lead;
        Map< String, Attachment > mapAttachments = new Map< String, Attachment >();
        for(Messaging.InboundEmail.BinaryAttachment bA : email.binaryAttachments) {
            System.debug('binary attachment :: '+email.binaryAttachments.size());
            System.debug('BA header size attachment :: '+bA.headers.size()+'---'+bA.headers);
            for(integer i = 0; i < bA.headers.size(); i++) {
                String headerValue = bA.headers[i].value;
                System.debug('headerValue  :: '+headerValue);
                if(headerValue.startsWith('ii') || headerValue.startsWith('<image')) {
                    headerValue = headerValue.replaceAll('<', '').replaceAll('>', '');
                    system.debug('final header value :: '+headerValue);
                    mapAttachments.put(headerValue, new Attachment(Name = bA.fileName, body = bA.body,ParentId = lead.Id, ContentType = bA.mimeTypeSubType));
                }
            }
        }
        //system.debug('mapAttachments :: '+mapAttachments);
        insert mapAttachments.values();
        //system.debug('Attachement List :: '+mapAttachments);
        for(String headerValue : mapAttachments.keySet()) {
            //system.debug('headerValue List :: '+headerValue);
            String refLink = '/servlet/servlet.FileDownload?file=' + mapAttachments.get(headerValue).Id;
            //system.debug('refLink  List :: '+refLink);
            lead.HTML_Body__c = lead.HTML_Body__c.replaceAll('cid:' + headerValue, refLink);
            //system.debug('replaceAll List :: '+lead.HTML_Body__c.replaceAll('cid:' + headerValue, refLink));
        }
        update lead;       
        return result;
    }
}

Screenshot :


Featured

What is Cryptography in salesforce and what are all the algorithms provided by them ?

A). It is a security protocal between two systems. Lets say we are integration two systems without any encrytion mechanism then hackers wil...

Popular