Adsense

September 29, 2019

Salesforce - Test Class Best Practice

Before we talk on best practices we should be following while writing a test class, let's discuss what a test class is and why it is needed.
Test class in Salesforce is a kind of framework which provides you a platform to supply data to your apex class and see how your apex is behaving. 
It is needed as testing is an important part of SDLC. So, before deploying your code to production environment, Salesforce requires at least 75% of your code to be covered by your test classes to make sure that your code doesn't break in any situation in Production.

We should be following below points while writing test class:


  1. Use @isTest at the Top for all the test classes.
  2. Always put assert statements for negative and positive tests.
  3. Use the @testSetup method to insert the test data into Test class that will flow all over the test class.
  4. Always use Test.startTest() and Test.stopTest() doing this it will increase the governor limit of Salesforce. We also use this to increase the governor limit.
  5. Use System.runAs() method to test the functionality in user Context.
  6. Do not put (seeAllData = true) in test class otherwise, use it for exceptional cases.
  7. Avoid Using Hard Coding Ids anywhere in test Class or any apex class.
  8. Please make sure that each class has minimum 75% coverage and also the main functionality has been covered. Target 100% code coverage.
  9. All class method must be tested for at least 20 records and keep the real scenarios in mind.
  10. Use the ORDER BY keywords to ensure that the records are returned in the expected order. 

Best Practices for Parallel Test Execution


Tests that are started from the Salesforce user interface (including the Developer Console) run in parallel. Parallel test execution can speed up test run time. Sometimes, parallel test execution results in data contention issues and UNABLE_TO_LOCK_ROW error occur.
When a deadlock occurs in tests that are running in parallel and that try to create records with duplicate index field values. A deadlock occurs when two running tests are waiting for each other to roll back data. Such a wait can happen if two tests insert records with the same unique index field values in different orders.

This can be prevented by turning off parallel test execution in the Salesforce user interface:

  1. From Setup, enter Apex Test.
  2. Click Options...
  3. In the Apex Test Execution Options dialog, select Disable Parallel Apex Testing and then click OK.
Apex test execution option


Test classes annotated with IsTest(isParallel=true) indicate that the test class can run concurrently with more than the default number of concurrent test classes. This annotation overrides default settings.
Read More »

September 25, 2019

Update Anypoint Studio version

This article is for updating your AnypointStudio Version and Syncup with the latest studio release without a fresh download from Mulesoft anypoint studio site.


There are following benefits:


  • We do not need to do a fresh studio download to continue our development.
  • Whatever the existing plugins you have added previously, you do not need to install it again. It will be available after restart.

Steps for updating your AnypointStudio version:


Go to Help--> Select About Anypoint Studio




About Anypoint Studio


Click on Installation Details


Anypoint Studio Version



Select Anypoint Studio and click Update Button


Anypoint Installation Details



Click Next


Anypoint-Update-Remediation-Page

Click Next


Anypoint-Update-Details


Accept licence agreements and click finish


Accept-License


Wait to finish the Update and it will ask for restart--> Click restart now

Anypoint Installation Progress

Restart AnypointStudio


Once your AnypointStudio restarts you will get the updated studio version

AnypointStudio Version Updated



Also you will find the existing plugin there as you can see here it has git plugin after restart Anypoint Studio

AnyPoint Perspective


Happy Learning :)

Read More »

September 15, 2019

Salesforce execution sequence


When a record is saved in salesforce with insert, update or upsert statement, salesforce performs below event in sequence behind the scene.
  1. Runs Client side validations: The browser runs javascript to check if there is any dependent picklist field is present. If yes then it prompts user to fill the value or throws error on UI.
  2. Loading/Initializing: Loads the original record from the database or initializes the record for an upsert statement.
  3. Loads the new record field values from the request and overwrites the old values: Say Account's shipping address is being changed from Pune to Mumbai, then Pune is retrieved from database and its overwritten with value Mumbai
  4. Executes all before triggers.
  5. Runs most system validation steps again: Such as verifying that all required fields have a non-null value, and runs any user-defined validation rules(Say Account's billing country can't be left blank). 
  6. Execute Duplicate rules: Duplicate rules are implemented to reduce the potential insertion of Account with the same name.
  7. Saves the record to the database, but doesn't commit yet: Soft save, not available for SOQL yet.
  8. Executes all after triggers.
  9. Executes assignment rules: Assignment rule is created on Case and Lead object. An assignment rule dictates to whom a lead or case is assigned based on criteria that is specified within Salesforce.
  10. Execute auto-response rules: An auto-response rule is a set of conditions for sending automatic email responses to lead or case submissions based on the attributes of the submitted record.
  11. Executes workflow rules: Workflow lets you automate standard internal procedures and processes to save time across your org. A workflow rule is the main container for a set of workflow instructions. These instructions can always be summed up in an if/then statement.
  12. If there are workflow field updates, updates the record again.
  13. If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.
  14. Executes processes and flows launched via processes and flow trigger workflow actions.
  15. Executes escalation rules: are used to escalate cases automatically when they meet the criteria which are defined in rule entry. We create rule entries where criteria is defined to escalate a case.
  16. Executes entitlement rules.
  17. If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.
  18. Executes Criteria Based Sharing evaluation.
  19. Commits all DML operations: Here the record will be actually saved to database and the transaction will complete.
  20. Executes post logic: Once the record is saved to database, some post logic will be performed like sending mail to customers, updating a formula field etc

Read More »

September 06, 2019

Salesforce Basics

In recent years, we are hearing a buzzword 'Cloud Computing'. There has been a big surge in cloud computing Technologies. Salesforce is one of the front runners among those. In this blog, I will introduce you to Salesforce and will answer:
  • What is Salesforce?
  • Why use Salesforce?
  • Who should use the Salesforce CRM?
  • How it makes your life easy in terms of technology and marketing?

Q: What is Salesforce?

A: Before knowing about Salesforce, lets discuss why it was needed and how it evolved. Prior to Salesforce, Customer Relationship Management(CRM) solutions were hosted on local servers which were established by company itself. It usually took months even years to build the setup which was very costly. Also the results were not that fruitful.
As you all know necessity is the mother of invention, here comes a feasible and affordable CRM solution in the name of Salesforce which is offered as Software as a Service(SaaS), delivered entirely online.

Salesforce is a customer relationship management(CRM) solution that brings companies and customers together. It's one integrated CRM platform that gives all your departments — including marketing, sales, commerce, and service — a single, shared view of every customer.


Q: Why use Salesforce?

A: There are hell lot of reasons you can go for Salesforce, few are jotted below:
  • Ease of Use: This is one of the primary reasons that drive the Salesforce adoption rate. Sales Reps have better visibility into their accounts, contacts, opportunities, tasks, all from a single place. They have a complete 360-degree view of the customer, which in turn helps them to make better business decisions and close deals faster.
  • Customizability: There is always a need to provide more features than out-of-box offers. Salesforce platform provides you Apex, Visualforce  and lightning apparatus to achieve those goals.
  • Scalability: Business is done keeping future perspective open. With Salesforce you can scale up whenever needed in future.
  • Reporting: Reports are the mirror of your business. Sales Reps can create their own reports to see the Accounts they haven’t worked on for a while, Opportunities present in the pipeline, products they have sold, activities performed and tasks completed.
  • Time and cost of Implementation: Being a Cloud Platform, the implementation time for Salesforce is much lesser than standard solutions, thereby lessening the Go-Live time-frame. The feature-rich solution can be configured easily and even if any customization is required, it can be incorporated in a systematic order easily. And cost incurred in this path is also reasonably less in comparison to others.


Q. Who should use the Salesforce CRM?

A. The simple answer is everyone. Salesforce has editions for all variety of users. It offers different editions like Group, Professional, Enterprise and Performance (For Sales Cloud). An organization can select the edition they, according their aims, and the features they require.

Salesforce covers all the areas of customer relationships, ranging from marketing to service. Any organization that wants to manage their customer relationships holistically can come in and use Salesforce without losing time, and wasting money for software development or hardware infrastructure.

Q. How it makes your life easy in terms of technology and marketing?

A. Keeping customer relationship healthy and keep getting business from them is the top priority for a sales representative. Salesforce makes sales reps life easy in this path.

  •  Infrastructure perspective:

    • Don't have to worry about setting up of servers and its installation. You just have to purchase the licenses. Its like plug-n-play.
    • All the patches and latest features are readily available to you when they are released by Salesforce.
    • Most business functionality is achieved via configuration on Salesforce platform.

  • Business perspective:

    • Visibility to leads makes sales reps connect to leads faster and get the business rapidly.
    • Dynamic Reports and dashboard provide you the latest status of the business, which make decision making faster.
    • Ease to Use – It's quite informative and very easy to use, which is also a big plus for sales reps.
Read More »