Posts

Apex Trigger Framework in Salesforce with best practise

Image
                                                            Trigger framework is not just needed for having single object per trigger guidance but also helps in different other reasons. According to the trigger framework : 1) Create a single trigger for each object. 2) A handler class which will call Action or Apex Interface based Trigger Framework Implementation One Trigger -One Object Policy Framework Implementation Bulkified Code  Avoid SOQL Queries or DML statements inside FOR Loops  Using Collections, Streamlining Queries, and Efficient For Loops   No  Hardcoding IDs Types of Framework available : 1.Handler/Controller Framework 2.Lightweight Apex Trigger Framework (Source:  http://chrisaldridge.com/triggers/lightweight-apex-trigger-framework/ ) Handler Framework Example: trigger ABCTrigger on Account( after insert, after update, before insert, before update) {     ABCHandler handlerFM = new ABCHandler(Trigger.isExecutin

Be a champ in test class. Test classes from start to end.

Image
For  development of robust, error-free code, Apex Code requires the creation and execution of unit tests. Unit tests are class methods that verify whether a particular piece of code is working properly.  Unit tests are written in Apex Code and annotated with the  annotation @testmethod.  The test methods must provide at least 75% code coverage.  Code coverage is calculated by dividing the number of unique Apex code lines executed during your test method execution by the total number of Apex code lines in all of your trigger and classes. Defining a Test Method using the  testMethod  keyword For defining  an Apex method as a 'test method',Define the method as  static  and add the keyword  testmethod.  Classes defined with the  isTest  annotation do not count against your organization limit of 2 MB for all Apex code. Classes annotated with  isTest  can be declared as private or public.  @isTest public class totestClass { static testMethod void myTest(

Apex Classes as REST Web Services in Salesforce

Introduction to Apex REST Salesforce platform is amazing and its lets your create your own lightweight  REST API using Apex. You can use this REST API to access force.com data, by authenticating the caller/consumer of API using standard oAuth and return data format support JSON/XML, purely depends how you want return back the data A few useful bits of information related to these REST APIs: Use standard HTTP verbs: GET, POST, PUT, PATCH, DELETE, and HEAD. You can use either HTTP or HTTPS. Use standard security to authenticate your REST calls via OAuth 2.0. Serialize your data in either XML or JSON format. This is done by defining your Apex class with the  @RestResource  annotation to expose it as a REST resource. Similarly, add annotations to your methods to expose them through REST. For example, you can add the @HttpGet  annotation to your method to expose it as a REST resource that can be called by an HTTP  GET  request.  Apex REST Annotations Six new ann

All about Service Oriented Architecture : SOAP / REST differences and usage

Image
Service Oriented Architecture  with  REST/SOAP in SFDC A service-oriented architecture is essentially a collection of services. These services communicate with each other. The communication can involve either simple data passing or it could involve two or more services coordinating some activity. Some means of connecting services to each other is needed. The technology of Web Services is the most likely connection technology of service-oriented architectures. The following figure illustrates a basic service-oriented architecture. It shows a service consumer at the right sending a service request message to a service provider at the left. The service provider returns a response message to the service consumer.  The request and subsequent response connections are defined in some way that is understandable to both the service consumer and service provider. How those connections are defined is explained in Web Services Explained. A service provider can also be a service con