Sunday, September 27, 2020

AWS Greengrass

 AWS IoT Greengrass is software functionality that connects cloud capabilities to local devices. This facilitates devices in data collection and analytics closer to the source (devices on IoT), quicker response time, and secure communication over local networks, even when they are not connected to the cloud. 

These devices are collectively known as a Greengrass group. 

Greengrass groups are configured and defined from the cloud but do not “need” the cloud to connect and communicate with each other.

In AWS IoT Greengrass, devices securely communicate over a local network and exchange data without a connection to the cloud. AWS IoT Greengrass achieves this through a local pub/sub message manager that can buffer messages even while there is no connectivity, thus preserving messages to and from the cloud.

Building an AWS Greengrass:

Step 1: Establish a Greengrass core:

Every group needs a Greengrass core to function. Central to this group is a physical device, on which the Greengrass core software is installed. The core software securely connects the device to the AWS. There can be only one core to a group.

Step 2: Building a group:

Once the core is established, we can continue to add devices to the group that are themselves on the cloud, or other devices which are AWS IoT provisioned, or AWS Lambda functions – which are essentially simple programs that can process or respond to data. Presently, a Greengrass group can contain up to 200 devices. A device can be a member of up to 10 groups.

Step 3: Code, the group:

Once deployed, the core and devices can communicate, even without a connection. IoT vs. AWS IoT Greengrass: The IoT (Internet of things) is a network of connected devices called “Things” that are connected to a cloud server (a fit-bit or a fridge or a thermal sensor could be a “thing”).

 Data aggregated from these things on to the cloud server, data could be monitored in real-time and react/respond immediately.

Friday, September 25, 2020

Salesforce Execution Rules

Salesforce has a bunch of rules that can be defined on objects and fields. For example you can define validation rules, workflow rules, proess builder, flows, assignment rules, escalation rules, auto-response rules, triggers etc.

Whether you are an adminsitrator, consultant, developer or architect – it is important for you to understand the order in which these rules and triggers are executed.

When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in order.





Thursday, September 24, 2020

Best Practices of QA in a DevOps

  • QA and testing teams should be part of technical teams. They have to move beyond manual functional testing and should focus their efforts on automation and testing strategies. QA becomes the enabler of quality across SDLC. 
  • Quality needs to be well-defined in order to meet requirements. Rather than trying to achieve perfection in software, QA should move towards focusing on accomplishing satisfying user experience within the given time frame. 
  • Metrics that measure quality have to be laid down and measured. Such metrics should detect software defects early in the development cycle. 
  • Goals of individual and teams need to be optimized. Organizations need to strengthen necessary behavior and cultural shift by incentivizing quality assurance. 
  • Requirements need to be specific. QA teams should proactively involve in the requirements process to help and guide development teams towards proper direction. 
  • QA & testing should focus more on automated regression testing on critical areas such as key software functionality. 
  • QA & testing has to move towards leveraging automation tools to automate testing wherever possible. 
  • Development, operations, and QA teams should be facilitated and encouraged to communicate, collaborate, and optimize their efforts. 
  • Continuous integration is the key to identifying defects early in the development lifecycle. For continuous integration to be implemented effectively, all the stakeholders have to integrate their work often on a day-to-day basis. 
  • A fully automated continuous testing process needs to be integrated into the SDLC for a successful continuous delivery process that minimizes risks, reduces costs, and accelerates time to market by frequent releases. 

Wednesday, September 23, 2020

Asyncronous Apex

Asynchronous apex is nothing but to run task or processes in a separate thread, at a later time. Without having user to wait for the task to finish.

The advantages of this approach are :

  • High user efficiency
  • High Scalability
  • Increased Governor & Execution Limits

In short, you don't have to wait in a queue to wait for the task to finish and then execute the second task.

Types of Asynchronous Apex :

  • Future Methods
  • Queuable Jobs
  • Scheduled Apex
  • Batch Apex

When you want to use a future method in salesforce we use @future annotation.

Future annotation (@future) :

1. Use the future annotation to specify that these methods that are executed asynchronously.

2. Methods with future annotation must be static methods.

3. Methods with future annotation can only return a void type.

Let's have a look at the syntax :

============================================

global class classname

{

 @future 

static void methodname(parameters)

{

  //body of the method

 }

}



Future method callouts using @future(callout=true)

To allow callout from the future method annotation needs an extra parameter (callout=true) to indicate that callouts are allowed. Here is example

 

 

 


global class FutureMethodExample {

    @future(callout=true)

    public static void getStockQuotes(String acctName){

        // Perform a callout to an external service

    }

}

IMPORTANT NOTE :

·       No more than 10 method calls per Apex invocation

·       You cannot call a method annotated with the future from a method that also has the future annotation, nor you can call trigger from an annotated method that calls another annotated method.

·       All asynchronous calls made after the startTest method are collected by the system. When stopTest is executed, all asynchronous processes are run synchronously.

·       Use when you want to avoid DML exception.

·       It is used for higher governor limits.

·       To avoid mixed DML exception.

 

LIMITATION :

·       No more than 25 lakh Jobs/24 hrs

·       No more than 50 method calls per apex.

·       One future method cannot call another future method.

BEST PRACTICE OF FUTURE METHODS :

·       Do not call future methods inside for loops.

·       Avoid complex calculations in future methods, else use batch apex.

·       Always consider @future limit is equal to 2x SOQL query.

 

Salesforce Apex Access Modifiers

Access Modifiers 

Private: 

  • If you declare a class as a private, it is only known to the block in which it is declared.
  • By default all the inner classes are private.

Public:

  • If you declare a class as a public, this apex class is visible throughout your application and you can access the application anywhere.

Global:

  • If you declare a class as a global, this apex class is visible to all the apex application in the application or outside the application.
  • Note: If a method or a class (inner) is declared as global then the top level class also must be declared as global.

With Sharing:

  • If you declare a class as a With Sharing, sharing rules given to the current user will be taken into consideration and the user can access and perform the operations based on the permissions given to him on objects and fields. (field level security, sharing rules)

Without Sharing:

  • If you declare a class as a Without Sharing then this apex class runs in system mode which means apex code has access to all the objects and fields irrespective of current users sharing rules, fields level security, object permissions.

  • Note: If the class is not declared as With Sharing or Without Sharing then the class is by default taken as Without Sharing.
  • Both inner class and outer classes can be declared as With Sharing.
  • If inner class is declared as With Sharing and top-level class is declared as without sharing, then the entire context will run in With Sharing context.
  • Outer class is declared as With Sharing and inner class is declared as Without Sharing then inner class runs in Without Sharing context only. (Inner classes don't take the sharing properties from outer class).

Virtual:

  • If a class is declared with keyword Virtual then this class can be extended (Inherited) or this class method can be overridden by using a class called overridden.

Abstract:

  • This class contains Abstract methods, which will provide common method implementation to all subclasses.

Salesforce Governor Limits

Governor execution limits ensure the efficient use of resources on the Force.com multitenant platform. It is the limit specified by the Salesforce.com on code execution for efficient processing.

Why Salesforce has Governor Limits?

Because Apex runs in a multitenant environment, the Apex runtime engine strictly enforces limits to ensure that runaway Apex code or processes don’t monopolize shared resources. If some Apex code exceeds a limit, the associated governor issues a runtime exception that cannot be handled.

Type of Governor Limits

  • Per-Transaction Apex Limits
  • Per-Transaction Certified Managed Package Limits
  • Lightning Platform Apex Limits
  • Static Apex Limits
  • Size-Specific Apex Limits
  • Miscellaneous Apex Limit

Here is list of important governor limits in salesforce

  • Total number of SOQL queries issued : 200
  • Total number of SOSL queries issued : 20
  • Total number of DML statements issued : 150
  • Total number of records retrieved by SOQL queries : 50,000
  • Total number of records processed as a result of DML statements : 10,000

Here is full list of governor limits in salesforce

Description

Synchronous Limit

Asynchronous Limit

Total number of SOQL queries issued

100

200

Total number of records retrieved by SOQL queries

50,000

Total number of records retrieved by Database.getQueryLocator

10,000

Total number of SOSL queries issued

20

Total number of records retrieved by a single SOSL query

2,000

Total number of DML statements issued

150

Total number of records processed as a result of DML statements, Approval.process, or database.emptyRecycleBin

10,000

Total stack depth for any Apex invocation that recursively fires triggers due to insert, update, or delete statements

16

Total number of callouts (HTTP requests or Web services calls) in a transaction

100

Maximum cumulative timeout for all callouts (HTTP requests or Web services calls) in a transaction

120 seconds

Maximum number of methods with the future annotation allowed per Apex invocation

50

Maximum number of Apex jobs added to the queue with System.enqueueJob

50

Total number of sendEmail methods allowed

10

Total heap size

6 MB

12 MB

Maximum CPU time on the Salesforce servers

10,000 milliseconds

60,000 milliseconds

Maximum execution time for each Apex transaction

10 minutes

Maximum number of push notification method calls allowed per Apex transaction

10

Maximum number of push notifications that can be sent in each push notification method call

2,000

 Avoiding Governor limits

From a Developer’s perspective, it is important to ensure that our code should be scalable and should not hit the governor limits. Its very important to follow some of best practices so that our code does not hit governor limit.

Friday, September 18, 2020

VisualForce

 Visualforce is a markup language that allows defining user interface components in Salesforce.

This tool which runs o force.com platform. By using page layouts, we can easily configure the User interface. But by using visualforce pages, you can develop your own customized user interface.

Developers define pages through specifying Visualforce markup and a Visualforce controller. The Visualforce tag-based markup language looks and behaves similarly to HTML. 

The markup embeds tags and web-enabled languages like HTML and JavaScript within a single <apex:page> tag.

The Visualforce markup controls what elements appear on the page and how they appear. Visualforce tags correspond to page elements, such as form fields or and images. 

Visualforce can integrate with any standard web technology or JavaScript framework to allow for a more animated and rich user interface. Each page is accessible by a unique URL. 

When someone accesses a page the server performs any data processing required by the page, renders the page into HTML, and returns the results to the browser for display.


Sample Code Used inside the Visualforce Component:

<apex:component >

    <apex:attribute name="height" required="true" type="integer" description="Height for the table"/>

    <table height="{!height}" border="2">

        <tr><td><h1>Infallible Techie</h1></td></tr>

    </table>

</apex:component>

ES12 new Features