Deleting Related Records

The delete operation supports cascading deletions. If you delete a parent object, you delete its children automatically, as long as each child record can be deleted.

For example, deleting the account you created earlier (SFDC Account) will delete its related contact too.
Execute this snippet in the Anonymous Apex window of the Developer Console.

Account[] queriedAccounts = [
SELECT Id
FROM Account 
WHERE Name='SFDC Account'
];
delete queriedAccounts;

Check the accounts and contacts in your org.
You’ll see that both the account and its related contact were deleted.

Yeshas K

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]

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]

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]

Connecting Sandbox (Dev) to Visual Studio code For Developing Lightning Web Components(LWC)

Here, I am going to present you the steps to connect the Sandbox to Visual Studio Code for connecting the Lightning web Component…

First step: Install Salesforce Extensions for Visual Studio Code

screenshot for Extensions in VS Code
Lightning Web Components Extension

Login in to Sandbox and Use the below command in the Terminal

sfdx force:auth:web:login –setalias my-hub-org –instanceurl https://test.salesforce.com

After logging in…

  1. Use ctrl+shift+p
  2. Enter Sfdx:create Project
  3. Select the Source where you want to create Project.

To Create Lightning web Component use the Below Command in Terminal

sfdx force:lightning:component:create –type lwc -n myComponent -d force-app/main/default/lwc

AND Finally to deploy use the command below:

sfdx force:source:deploy -p force-app -u  test@example.com(user name of the Sandbox)

Also, Follow the Link below for better experience on Lightning Web Component:

https://trailhead.salesforce.com/content/learn/projects/quick-start-lightning-web-components

-Ranjith T [02/25/2019]

Cron expression for scheduling jobs in Salesforce

In this post, I am going to share the information about Cron expression for scheduling jobs in Salesforce

Cron Expression

Cron Expression syntax :-
“Seconds Minutes Hours Day_of_month Month Day_of_week optional_year”

The following are the values for the expression:

Name Value
Seconds 0–59
Minutes 0-59
Hours 0-23
Day_of_month 1-31
Month 1-12
Day_of_week 1-7
optional_year null or 1970–2099

Cron Expression Examples

Expression Description
0 0 0 ? * * * at 12:00 AM every day
0 0 10 ? * * at 10.00 AM every day
0 0 10 * * ? at 10.00 AM every day
0 0 10 * * ? * at 10.00 AM every day
0 0 15 ? * * * at 3:00 PM every day
0 0-5 15 * * ? Every minute starting at 3:00 PM and ending at 3:05 PM, every day
0 15 17 ? * MON-FRI at 5:15 PM every Monday, Tuesday, Wednesday, Thursday and Friday
0 15 10 15 * ? at 5:15 PM on the 15th day of every month
0 15 17 ? * 6#3 at 5:15 PM on the third Friday of every month
0 0 18 ? * 6L runs the last Friday of every month at 6:00 PM.
‘0 30 * * * *’; every 30 minutes
0 0 12 * * ? at 12:00 PM every day
0 0 23 * * ? 2016 runs every day at 11:00 PM during the year 2016.
? – No Value
* – All Values
L – Last
– Chandra V [01/12/2019]

Validation Rule Requiring Lead Fields Prior to Conversion

In this post I am writing a validation rule that requires all of these fields prior to Lead conversion.

Need is a checkbox, Languages and propsepct role are picklists, Notes and SDR are text…

Below is the successful Formula that works for the above criteria:

Also, If the  Notes__c a Rich Text area field, then you need to use this:

 

If the above don’t work either, then check the following:
This Lead Settings should be checked in order for the Validation Rule to Fire.
Hope this information helps you!
– Chandra V [01/12/2019]

 

EINSTEIN ANALYTICS

In this Post, I would like to get the most important points on the Einstein Analytics to this Blog, through which one can understand it’s significance in improving the Business.

  1. Work with a platform you can trust
  2. Save on expenses
  3. Get set up quickly
  4. Cut out the fluff
  5. Customize your solution
  6. Enjoy built-in support
  7. Integrate your data
  8. Integrate with the entire Salesforce ecosystem
  9. Easily explore customer data from every source
  10. Bring your people together
  11. Unify your goals
  12. Collaborate from the dashboard
  13. Generate presentation-worthy visuals
  14. Be a part of the conversation
  15. Put it all into context
  16. Never be out of reach
  17. See team performance
  18. Access relevant KPIs
  19. Track call-center efficiency
  20. Chart changes
  21. Become a better coach
  22. Empower your teams to analyze themselves
  23. Eliminate the holes in your campaigns
  24. See the big picture
  25. Eliminate borders
  26. Find the devil in the details
  27. Predict the future
  28. Reduce churn
  29. Focus on the right leads
  30. Evaluate your lead sources
  31. Recognize your biggest wins
  32. Optimize the customer experience
  33. Dive deeper
  34. Present the right message
  35. Be your own data analyst
  36. Take instant action
  37. Make B2B marketing your speciality
  38. Understand the brand experience
  39. Set your priorities
  40. Evaluate your accounts
  41. Connect with your agents
  42. Review your service backlog
  43. Integrate with third-party applications
  44. Go mobile
  45. Optimize your pipelines
  46. Automate your analysis efforts
  47. Enjoy the highest level of data security
  48. Push the limits
  49. Gain deeper visibility into your business
  50. Keep up the pace                                                                                                                                                                                         – Sumanth A[01/04/19]