Using certificates
To utilize two-way SSL authentication when making callouts from Apex, you need to use a certificate either generated within Salesforce or signed by a certificate authority (referred to in many places as a CA). Once you have generated or uploaded your signed certificate in Salesforce (see Setup | Certificate and Key Management), you can reference that certificate in the callouts you are making.
If you are working with named credentials, you can simply include the certificate in the setup by populating the Client Certificate field (see Figure 15.4). If you wish to set the certificate in Apex, you can do so on the HttpRequest
object instance using the setClientCertificateName
method, passing in the developer name of the certificate:
request.setClientCertificateName('MyCertificateName');
Wherever possible, you should utilize a certificate and ensure that two-way SSL is enforced on your integrations to improve security.
We have now seen how we can...