Posts

Creating JKS certificate for JWT Bearer flow in Salesforce

JWT stands for Json Web Token. Salesforce supports JWT for authentication however, JWT should be signed using RSA SHA256 algorithm. This algorithm needs private and public key for signature. OpenSSL can be used to create private and public key and the same can be converted to specific certificate format. You can get OpenSSL here . Creating self-signed certificate: Below is the consolidated list of OpenSSL commands to create a self signed certificate. Generate a private key openssl genrsa -des3 -passout pass:<Password> -out server.pass.key 2048 openssl rsa -passin pass:<Password> -in server.pass.key -out server.key Generate a certificate signing request using the server.key file. A challenge password would asked with other information. Keep the passwords same to avoid certificate corruption. openssl req -new -key server.key -out server.csr Generate a self-signed digital certificate from the server.key and server.csr files openssl x509 -req -sha256 -days 365 -in server.csr -

POST - PUT - PATCH

POST - PUT - PATCH methods have very close analogy with Salesforce DML statements. POST <=> INSERT operation PATCH <=> UPDATE operation PUT <=> UPSERT operation Like inserting the same resource twice is allowed, POST method can create duplicate resources.  Resource can be partially updated with PATCH method.  But, there is bit difference in PUT methods. complete resource must passed to even if the resource needs to be updated partially. Lets take an example, Resource: { "id" : 1234 , "day" : 15 , "month" : 10 , "year" : 2020 } Body for POST method: { "id" : 1234 , "day" : 15 , "month" : 10 , "year" : 2020 } Let's update the day from 10 to 15 Body for PUT method: { "id" : 1234 , "day" : 15 , "month" : 10 , "year" : 2020 }

Create File versions from Apex

Image
In Lightning Experience, Salesforce Files unifies your files, documents, and libraries into a single place for easier management. Files can be created from different places like Lightning Components, LWC and integrations i.e. via apex. In majority scenarios, the requirement is around creating a file and associating it with some sObject record.  Below script can be to create a file in Salesforce. HttpRequest req = new HttpRequest () ; req.setEndpoint ( 'https://images.pexels.com/photos/2052217/pexels-photo-2052217.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500' ) ; req.setMethod ( 'GET' ) ; HttpResponse res = new Http () .send ( req ) ; if ( res ! = null ) { Blob imageBlob = res.getBodyAsBlob () ; String fileName = 'Ssshhh' ; // Creates the contentversion and implicitly creates content document ContentVersion cv = new ContentVersion () ; cv.Title = fileName; cv.PathOnClient = fileName

Connecting to Salesforce using Postman

Postman is very handy tool when it comes to test REST APIs. Being it standard APIs exposed by Salesforce or custom services that you have developed. But sometimes it becomes tricky to just get into Salesforce environments due to N number of reasons. Though, Postman provides a variety of ways to login to Salesforce, its good to be aware of a quick and easy way. Let's check it out step by step. Step 1: Get the active Session Id from Salesforce Session Ids can be obtained in variety of ways. But not all retrieved Ids supports the API.  Also, Salesforce has stopped showing the session id in logs (You will see "SESSION_ID_REMOVED" text instead).  Quickest way to get active and valid session id which can be used for API calls is to get it from cookies. Login to saleforce -> switch to classic -> open browser console -> Run document.cookie.match(/(^|;\s*)sid=(.+?);/)[2]; in browser console. St

Arrow Functions

With Lightning Web Component framework and brand new Javascript Developer I certification, its good to be aware of some javascript features intorduced in ES6. Arrow Functions is one of such many features. Let's have a look at it. What are Arrow Functions? Arrow Functions are nothing but a compact alternative to a traditional function expression with some different behavior. Syntax: Depending on the number of arguments and number of lines in function there are different syntax for Arrow Functions No () around arguments, no {} around code and no return statement is required For multiple arguments, () around argument is required and for multiple lines of code {} around code is required and return statement is also required. 1. One argument and one line of code Function Expression: function calculateCircleArea(radius) {      re

Run as different user in Apex

Yes, you read it right; running apex as different user who has higher access levels than logged in user is now possible in Salesforce using Platform Events . Platform events are executed as  Automated Process user . Processing records in system mode or async apex like  batch jobs are the commonly used workarounds for this. However there are few use cases where these workarounds can not help. We are going to see one of such use case. Use Case: If event is created with attendees then, only organizer can edit the event. This is standard Salesforce behavior. And there is business requirement that, attendees should be able to update few fields on event. Solution: Lets first analyze what is event with attendees means. Whenever a event is created with attendees, Salesforce creates separate events for organizer and attendees. These events are linked to each other, any update to organizer event is propogated to all attendee events automatically.  For organizer event IsChild is set to false an

Custom Permissions

Image
C ustom P ermissions are intended for adding declarative permissions which does not impact sharing model of an org but, still enables admins/developers to control features of applications. Salesforce recommends to create Custom Permissions to give users access to custom processes or apps. However, these can be used overcome complex accessibilty issues. Eg. Allow a support representative from group of support representatives having same role & profile, to change the status of case to previous status. This requirement can be easily fulfilled using Custom Permissions . These permissions do not have any impact on Sharing Model/Object Share records i.e. following are not affected by Custom Permissions OWD Object Level Access Field Lev