Testing Strategies for Developer
Jun12

Testing Strategies for Developer

Salesforce provides a framework for testing apex code. Testing is the key to successful software development. Before deploying apex code, try to cover as many lines of code as you can. At least 75% of your Apex code must be covered by unit tests else your code will not be deployed to production. Why Test? You should not write test classes by keeping in my mind just to cover 75% of your code but should always try to cover your entire code before deploying to production. Test provides assurance of functionality Test reduce cost of change Test encourage modular and reusable code Test help document expected behavior Test + Code = less likely produce the bug What to Test? Things that should happen to happen (Positive) : Positive testing is a way to test expected behaviour of code that you wrote is suppose to do. Things that should not happen to happen (Negative) : This is the hardest and important thing to test that verify if the error messages are correctly produced along with the positive working of test cases, within the limits cases. User Access : This is basically the manual testing, which we perform by seeing the aspect of end-user test is done when we think of user interaction. This type of test is done by hand via insert, update, delete and undelete the records. Exceptions : Exception testing tests expected behaviour of code when an user with restricted access to sObjects are used in code. Bulk Testing : This test comes in when a class, trigger or any apex code insert and update data in bulk. We need to test the class by creating more than one record in multiple scenarios. Test Structure Principles for Best Practices Principle #1  Use of Asserts : Assert is the method of System Class. It is an important method for test class which is used to check the expected result of test scenario. “A test without assert method isn’t a test, it’s code execution.” There are three in-built assert methods which are as follows: assert(condition, message) assertEquals(expected, actual, message) assertNotEquals(expected, actual, message) Every test method should include at least one assertion. Principle #2   Use startTest() and stopTest() startTest() methods are used to reset governor limits. The code between Test.startTest and Test.stopTest executes in fresh set of governor limits that means your setup code will not interfere and give you false positives (or negatives) surrounding governor limits. stopTest() method focuses on asynchronous code to complete. In general, one should follow these steps while writing test class: Create your test data Start the test Use that test data within your tested...

Read More
SKUID-Scalable Kit for User Interface Development
Jan10

SKUID-Scalable Kit for User Interface Development

SKUID SKUID has always been my favourite since the first time I saw this in Dreamforce 2014. My first interaction was with their team on Dreamforce booth and the after understanding its capabilites I was amazed! SKUID is set of tools that allow you to change almost any element of your Salesforce User Interface, quickly and easily. We can quickly implement any changes as per suggested by your team, across your org and even in Production. It is basically used to build the UI to have a look on the data your company needs. STORY: Salesforce connected Rich (Rich Slack, CFMO of Chrysalis and CEO of Meridian Meds) with a private developer who would charge $300,000 – $500,000 to build out their user interface. It was a non-starter. Rich decided to kill the Salesforce project and hire a team of developers to create their own platform. However, the team hit many roadblocks. Rich realized that Salesforce could do what he needed if he could figure out a way to overcome the gap of user interface. That’s when he found Skuid. Within 2 days, Rich had re-skinned the user interface of his app within Salesforce. He rebuilt his entire system during his nights and weekends in four months.  Let’s get Started with SKUID: Compose your new page from Skuid Central tab in your Salesforce Org Connect your Salesforce objects and external data through models present in Skuid. For each MODEL, choose the standard and custom fields from your Salesforce objects that you want to include in your page, and can even set criteria for the records to get display on your page. You can create as many model as needed. The only thing to know is that they will be loaded the way they are listed. For each model we have: Fields: Fields refer to the fields from the object which we want to show in our page. Conditions: They apply criteria for the records which are to be shown onto the page. Actions: They help us to specify the actions which we want our page to perform after some event. We have two properties for Model which are Basic & Advanced. Basic properties let you define the model Id, data source type, SObject name, model behaviour, number of pages to be displayed etc. Advance properties let you have a look on cloning the data, Query Deleted, Update Salesforce Recently Viewed Info etc. Skuid provides you with pre-built components which can be used to create your own page. Also you can create your own components. There is only the need to drag and drop those pre-built components and you can...

Read More
5 things about Salesforce Certification
Jan03

5 things about Salesforce Certification

This blog is for the Developers who wants to get a Salesforce Developer I Certification . What is Salesforce Certification? Why is it so important for the developers seeking a career in Salesforce? Salesforce certification is vital to the salesforce career path as it differentiates you from other developers, makes you an expert in your field. This Certificate is provided by salesforce.com where people demonstrate and prove their technical Skills in different  areas of Salesforce. It’s a damn good certification, if you are thinking about a career in Salesforce, by enhancing your skills and expertise in respective fields. It is very easy to get hired in an organization with  a salesforce certification in hand. You need to follow these steps  to enroll  for examination : First you have to create your webassessor Account on             https://www.webassessor.com/wa.do?page=createAccount branding=SALESFORCE Secondly Register and schedule your exam Five  things you must know while preparing for salesforce certification:-  Course Content  and their  weightage -: The Salesforce Certified Platform Developer I exam measures a candidate’s knowledge and skills related to the objectives listed below. A candidate should have hands-on experience of developing custom applications on the Force.com platform and have demonstrated the application of each of the features/functions below. 2. Prepare each topic with written practice of programs. Exploring it on trailhead will be a  great start. It will provide huge knowledge for practical implementation. In different areas. Below is the  link to access trailhead: https://trailhead.salesforce.com/ 3. Go through /Solve previous years certification:- Preparing from previous year question papers is always a good strategy to cover frequently asked topics in a short span of time.  4. Practice as many Mock test papers as possible once you think you have a good command on Salesforce syllabus. Mock test papers are available on various websites for free where you can practice them. Do register yourself  if required (as asked by some of the websites)  5. And last but not least, be confident and relaxed while writing the exam and remember the best way to gain confidence is to do more and more practice. According to my exam experience every aspirant must prepare well in the following topics as most of the questions I faced in the exam were from these topics : Validation Rule Workflow Rule Process Builder Object Relationships So all the best guys for exam. The exam is simple and easy. All you need is to do...

Read More
Salesforce Appexchange Checkmarx Major Issues
Dec19

Salesforce Appexchange Checkmarx Major Issues

Every Organization that creates it’s own App faces this huge challenge of getting the clearance from Salesforce Security Review. After completing the checkmarx clearances we submi the app for a final Security Review to Salesforce. This is the step where your app is human tested in testing org as well as in packaging org. This rigorous testing is mostly on the app security and functinality. I have seen several apps not passing this final Salesforce Security review and that too multiple times. Several of my last projects in 2016 have been just to do a line by line code review of the entire app and suggest changes before submitting for final review. Since a final review takes atleast 4-6 weeks most of the intelligent clients strategize this properly and get the code review and indepth analysis done with Salesforce wizards or experts. Now, in this blog I will explain some of the major issues and their solutions which are found in the Salesforce Security Review. Following are the list of major issues found in the app: 1.SOQL SOSL Injection 2.CRUD 3.Stored  XSS 4.Reflected XSS These four are the major as well as the common issues found in the app. I am sure you guys also must have come across these issues if you have worked on the Salesforce app. Now we will discuss one by one about these issues in detail. I will explain you the reason for the occurence of these issues as well as the possible solutions which could help you in overcoming these issues. SOQL and  SOSL Injection So the first major issue that is faced by the developers for developing any Salesforce App is  SOQL SOSL Injection. Reason For Occurrence: The SOQL SOSL Injection issue occurs when there is need for the user supplied input and if this input is being used for the dynamic SOQL query. In such a scenario what happens is if a user provides an unexcepected value which is not validated then it could change the meaning of whole query. Example: String Str= ‘SELECT Id, Name, Employee__c FROM Contact  WHERE  Employee__c= +StrList’  ConList=database.query(Str); Now In this kind of query where special characters are used for fetching data the meaning of whole query changes. SOLUTION: To remove the SOQL-SOSL Injection error from our code. We have to use the String.EscapeSingleQuotes()  method in the dynamic query wherever an user input has been provided in the query. Now we will use the String.EscapeSingleQuotes() method for correcting the above query So that it does not throw the SOQL-SOSL injection Error. ConList=database.query(String.escapeSingleQuotes(Str)); CRUD ISSUE: CRUD issues occurs in Salesforce when we are trying  to insert, update, or...

Read More
Day 4 Assignment (VFpage, JavaScript)
Jan26

Day 4 Assignment (VFpage, JavaScript)

I have created a 5 Days Salesforce based programming and configuration assignments for practice and improving your skills. This blog have the third day assignment. Since all the blogs are related I would recommend beginners to start from Day 2 assignment and not directly jump to this blog.     Requirement: We have a university “St Judes” which wants its salesforce account to get configured by us. Following are the requirement of this client.  1. Create a VF page listing a quick search for all the Professors. A quick search will be a on key press VF page. If the users press “V” in the field all the professors with starting name “V” like Vineet, Vinay .. etc will list down in the page. AJAX Toolkit Developer Guide SOLUTION: VisualForce Page Visual force page code. <apex:page id="page" controller="Basic2SearchProfessorsDynamically" sidebar="false"> <apex:form id="form"> <apex:pageMessages id="errors" /> <apex:pageBlock title="Find Me A Professor!" mode="edit" id="block"> <table width="100%" border="0"> <tr> <td width="200" valign="top"> <apex:pageBlock title="Parameters" mode="edit" id="criteria"> <script type="text/javascript"> function doSearch() { searchServer(document.getElementById("profName").value, document.getElementById("mail").value, document.getElementById("YOE").value ); } </script> <apex:actionFunction name="searchServer" action="{!runSearch}" reRender="results,errors,debug"> <apex:param name="profName" value="" /> <apex:param name="mail" value="" /> <apex:param name="YOE" value="" /> </apex:actionFunction> <table cellpadding="2" cellspacing="2" id="table"> <tr> <td style="font-weight:bold;">Name<br /> <input type="text" id="profName" onkeyup="doSearch();" /> </td> </tr> <tr> <td style="font-weight:bold;">Email<br /> <input type="text" id="mail" onkeyup="doSearch();" /> </td> </tr> <tr> <td style="font-weight:bold;">Year Of Experience<br /> <input type="text" id="YOE" onkeyup="doSearch();" /> </td> </tr> </table> </apex:pageBlock> </td> <td valign="top"> <apex:pageBlock mode="edit" id="results"> <apex:outputPanel id="panel" rendered="true"> <apex:pageBlockTable value="{!profList}" var="prof"> <apex:variable value="{!0}" var="cnt"/> <apex:column headerValue="Action"> <apex:commandButton value="Delete" style="background: red; color: white;" action="{!deleteProf}" rendered="true" reRender="panel"> <apex:param value="{!prof.Id}" name="profToRemove" assignTo="{!rowToRemove}"/> <apex:param name="index" value="{!cnt}"/> </apex:commandButton> <apex:variable var="cnt" value="{!cnt+1}"/> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Professor Name" action="{!toggleSort}" reRender="results"> <apex:param name="sortField" value="Name" assignTo="{!sortField}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!prof.Name}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Professor Email" action="{!toggleSort}" reRender="results"> <apex:param name="sortField" value="Email__c" assignTo="{!sortField}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!prof.Email__c}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Year of Experience" action="{!toggleSort}" reRender="results"> <apex:param name="sortField" value="Year_Of_Experience__c" assignTo="{!sortField}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!prof.Year_Of_Experience__c}" /> </apex:column> </apex:pageBlockTable> </apex:outputPanel> </apex:pageBlock> </td> </tr> </table> <apex:pageBlock title="Debug - SOQL" id="debug"> <apex:outputText value="{!debugSoql}" /> </apex:pageBlock> </apex:pageBlock> </apex:form> </apex:page> 2. The quick search will have a delete button beside each Professor row. This will delete a particular Professor. Once the Professor is deleted all the students from the Professors Course will get de-enrolled(Removed)  SOLUTION: VisualForce Page Controller public with sharing class Basic2SearchProfessorsDynamically { //the soql without the order and limit private String soql {get; set;} //the row to be delete public String rowToRemove{get; set;} //the collection of professors to display public List<Basic2Proffessor__c> profList {get; set;} //Required Professor(Dummy Professor) Basic2Proffessor__c reqProf = [SELECT Id, Name FROM Basic2Proffessor__c WHERE Name = ‘Professor Required’]; //the current sort direction. default...

Read More