Reset Password from Developer Console

There are instances where Reset Password option gives trouble and we do not receive the Email Link to reset the password.

Here is the best solution to directly reset the password from Developer Console itself..

Open Execute Anonymous Window and run the below command:

System.setPassword(UserInfo.getUserId(), ‘YourNewPassword’);

This should help in resetting the password instantly.

Chandra V[09-10-2019]

SoqlXplorer

Here, I would like to tell you about a new tool I have been using these days for enhanced querying through all the objects in the environment.

Steps to use this tool and make your querying quick through any field and condition.

Link to download the tool:

https://www.pocketsoap.com/osx/soqlx/

Step 1:

Login into the Sandbox that you would like to query on objects

After logging in, To the left hand side we can see all the objects. Need to double click on the object we want and we can see all the fields present in the object.

As per our requirement, we should enhance the query and add the conditions to get the results on the fields by clicking on query at the bottom.

Hope this tool helps in improving the querying time and checking the values on the fields.

-Chandra [07/28/2019]

Determine whether the Lightning component is in Lightning Console Or Normal App And Adding Icon and label to Tab

<cmp>
<aura:component >
    <!-- Console Api Library -->
     <lightning:workspaceAPI aura:id="workspace" />
    <aura:attribute name="Isconsole" type="Boolean" default="false" />
    
   <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>

Javascript:-
({
	doInit : function(component, event, helper) {
        var workspaceAPI = component.find("workspace");
            workspaceAPI.isConsoleNavigation().then(function(response) {
              console.log('Isconsole'+response);
                component.set("v.Isconsole",response);
                if(response){
                     workspaceAPI.getFocusedTabInfo().then(function(response) {
                        var focusedTabId = response.tabId;
                        workspaceAPI.setTabLabel({
                            tabId: focusedTabId,
                            label: "Edit"
                        });
                        workspaceAPI.setTabIcon({
                                    tabId: focusedTabId,
                                    icon: "utility:edit",
                                    iconAlt: "Edit Tab"
                        });
                    })
                    .catch(function(error) {
                        console.log(error);
                    });
                }
             })
	}
})

Use the Isconsole attribute and Do the Navigations accordingly .

Resource: https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_methods_lightning.htm

Apex Crypto And Decrypto Class

public class EncryptAndDecryptHelper {
    
    public static String encriptString(Blob key, String data){
        try{
            Blob bdata = Blob.valueOf(data);
            Blob encrypted = Crypto.encryptWithManagedIV('AES128', key, bdata);
            return  EncodingUtil.base64Encode(encrypted); 
        }catch(Exception e){
            system.debug('exception'+e.getMessage());
            return '';
        }
        
    }
    public static String decryptString(Blob key, String decryptString){
        try{
            Blob DecodedEncryptedBlob = EncodingUtil.base64Decode(decryptString);
            Blob decryptedB = Crypto.decryptWithManagedIV('AES128',key, DecodedEncryptedBlob);
            return decryptedB.toString();   
        }catch(Exception e){
            system.debug('exception'+e.getMessage());
            return '';
        }
         
    }
    
}

What is the Apex Crypto Class?

As per the Crypto Class documentation in the Apex Developer’s Guide, the Apex Crypto class provides a number of cryptographic functions for creating digests, message authentication codes, and signatures, as well as functions for encrypting and decrypting information. These functions allow you to protect the confidentiality of data as well as allow external systems to verify the integrity of messages and authenticity of the sender.

Scenarios for Using the Apex Crypto Class

The cryptographic capabilities of the Crypto class is normally used in the following scenarios:

  • Confidentiality – the protection of data either at rest or in transit from unauthorized parties
  • Integrity – the data is complete and correct
  • Authenticity – proof of the authenticity of the sender or receiver of the message

Encryption and Decryption

Consists of functions to encrypt and decrypt information using AES128, AES192 and AES256 algorithms. Currently, only symmetric private key encryption using the AES algorithm is supported. Whilst encryption provides for data protection, it does not authenticate the sender (non-repudiation) and nor does it guarantee message integrity.

Creating Hash Digests

In this scenario, the input message of any length is converted using a one-way cryptographic hash function into a compact unique “digest” of fixed length. As the digest is unique, it can then be used by the receiver to ensure integrity of the message by comparing the transmitted digest with a digest calculated from the received message using the same algorithm. Its compact nature also allows for performance and efficient transmission.

The Crypto.generateDigest() function generates a one-way hash digest for this purpose and supports algorithms such as MD5, SHA1, SHA256 and SHA512. As hash digests are one way, compact representations of the original data, the resulting digest cannot be “decrypted” back to its original form.

Hash Based Message Authentication Codes (MAC)

Hash-based MAC functions generate a compact one-way digest using a cryptographic hash function and then uses a private key to encrypt the resulting digest. The combination of the an encrypted hash digest ensures non-repudiation of the message and its sender.

Compared to a hash digests, HMAC functions use a private key that the sender uses to encrypt the MAC and receiver to decrypt the MAC. The unencrypted digest can then verify the message integrity. As the receiver has to decrypt the MAC using the shared private key, you can verify the authenticity of the message sender.

The Crypto.generateMac() method supports the HMACMD5, HMACSHA1, HMACSHA256 and HMAC512 algorithms.

Creating a Digital Signature

Digital signatures guarantee both integrity and authenticity of the message using an asymmetric key. The sender generates a message digest (e.g. using SHA1) and encrypts it using a private key. The receiver then decrypts using a public key and compares the message digest with a digest generated from the received message.

The Crypto.sign() function generates a digital signature using the SHA1 algorithm to create the digest, which is then subsequently encrypted using the RSA algorithm with a PKCS8 formatted private key.

Supported Standards

The following are the various supported standards for each of the Crypto class methods.

Method Supported Standards
Encrypt()
EncryptWithManagedIv()
Decrypt()
DecryptWithManagedIv()
AES128, AES192, AES256 for encryption. 
PCKS#5 padding and Cipher Block Chaining.
generateDigest()
generateMac()
MD5, SHA1, SHA256, SHA512
sign() SHA1 with RSA

Discussion and Sample Code

Encryption

The Crypto class provides the following functions to encrypt and decrypt using the AES algorithm:

  • encrypt()
  • decrypt()
  • encryptWithManagedIV()
  • decryptWithManagedIV()

The following considerations should be noted:

  • The AES128, AES192 and AES256 algorithms are supported
  • A private key can either be generated externally or via the Crypto.generateAESKey(Integer size) method. The length of the private key must match to the specified algorithm.
  • The private key should not be hardcoded in the Apex code. Instead, it should be placed in a protected custom setting.
  • The standard AES algorithm is used with a Cipher Mode of Cipher Block Chaining (CBC) and PKCS#5 padding. Ensure that any applications that you interact with use the same parameters.(Note that PKCS#5 and PKCS#7 are compatible.)
  • The algorithm requires an initialization vector of 16 bytes (128 bits). Use the encryptWithManagedIV() function to have Salesforce generate the IV for you in the first 16 bytes of the cipher text.Third party systems that receive the cipher should extract the IV from the first 16 bits. If third party systems send the IV in the first 16 bytes of the cipher, then use the decryptWithManagedIV() method to decrypt.
  • If you intend to generate your own initialization vector, then use the encrypt() and/or decrypt() methods, in which the IV is sent as a separate argument. Note that the cipher text passed to the decrypt() method should not contain the IV in the first 16 bytes and neither does the encrypt() function place the IV in the first 16 bytes of the generated cipher.

Ranjith T [03/09/2019]

Algorithm to generate the unique id in salesforce using Apex

There might be scenarios where we as a developer needs to generate random unique ID’s to be used for external integrations in Apex.

Here is a simple method which generates the unique code everytime.


public static String getUUID()
{
        Blob b = Crypto.GenerateAESKey(128);
        String h = EncodingUtil.ConvertTohex(b);
        String guid = h.SubString(0,8)+ '-' + h.SubString(8,12) + '-' + h.SubString(12,16) + '-' + h.SubString(16,20) + '-' + h.substring(20);
        system.debug(guid);
        return guid;
    }

Sumanth A [03/08/2019]

Is Lightning Components built on the MVC pattern?

It is a very common question in most of the Interviews.

We know that the component itself is a view. We even know that MVC, or Model-View-Controller, design pattern is so common in web app frameworks. Is Lightning Components built on the MVC pattern?

In a word, no. There are similarities, to be sure, but it would be more correct to say that

Lightning Components is View-Controller-Controller-Model, or perhaps View-Controller-Controller-Database.

Why is “controller” doubled up in that pattern name? Because when interacting with Salesforce, your components will have a server-side controller in addition to the client-side controller. This dual controller design is the key difference between Lightning Components and MVC.

What’s the distinction between “model” and “database”?

In traditional MVC, the model is a programmatic abstraction (usually a class) between the underlying data storage (usually a relational database) and the rest of the application.

In Lightning Components, there’s no Apex class that directly stands in between @AuraEnabledcontroller methods and DML operations. But then again, sObjects are already an abstraction between your Apex code and the underlying storage layer. You can add calculation fields, validation logic, and even add fully programmatic behavior in the form of triggers.

Hope this will help you answer the question better!!

Chandra V [03/07/2019]

Steps to Enable Event Monitoring dashboards in PROD/Sandbox

Hello!!

I am going to produce the steps to Enable Event Monitoring dashboards in Salesforce Sandbox /Production Environment….

Pre-Requisite: >> Enable Analytics >> Setup >> Analytics >> enable Analytics (This is a major step without this you won’t see analytics studio app)

  1. Setup >> Event Monitoring >> Enable Login Forensics and Event Log File Integration with Event Monitoring Analytics App
  • Open Analytics studio app >> Click on that and a new tab will open (FYI., pop up from browser might block this so set it to allow)
  • Create >> Click on it
  • Follow the below screen steps
  • You will see steps 1 to 5 don’t change anything except the no. of days to 30
  • Name the App “Event Monitoring App”
  • The app will run and you will see the below screenshot and an email will be sent once its ready.

Hope you got all the details!

Anil B [03/03/2019]

Email Quick Action missing in Feed Tab

In this post, I am going to provide you with the steps to debug the issue: Email Quick Action missing in the feed Tab…

  1. Login to salesforce Sandbox (www.test.salesforce.com) or Production org
  2. Navigate to the app (ex. Service console) using app launcher
  3. Open Case page and check if the quick action is visible
  4. Follow the below steps only if quick action is not visible
  5. Setup>>Object Manager>>Case object>>Case Page Layouts>>check if the quick action is added to the case page layout
  6. Drag and Drop the quick action into the layout and click save
  7. Even now if the quick action is not visible now then please follow the below steps
  8. Setup>>Administer>>Email Administration>>Deliverability>>Set Access to Send Email (All Email Services) to All Email>>Click Save.
  9. FYI., Screenshot for reference

Anil B[03/03/2019]