Posts

Showing posts from 2017

Uploading multiple files as attachments using chaining of actionfunction in single click.

Image
File operations in salesforce are not easy compared to other technologies because of it's governance limits like maximum heap size, maximum string length etc.This post will be explaining how to upload multiple files with single browse by chaining of actionfunction using JavaScript. Limitations of apex : i nputF i le:  1) apex:inputFile cannot be used in conjunction with an action component, apex:commandButton or apex:commandLink that specifies a rerender or oncomplete attribute. So this tag is not useful on complex vf page. 2)This tag can upload only one file at a time. Implementation: In JavaScript function uploadFiles converts attachments body in base-64 encoded string and calls actionFunction saveFileAF(Base64 Encoded attachment body, File Name). In Apex decode base64 string and create attachment. On complete this  again call uploadFiles function in JS for next file. Repeat the same operation for each file. Code:                                                 

Visualforce Componets

Image
Code reuse is one of the best practice in coding.  We reuse code while writing code in Apex by creating functions and calling it wherever required, but how to reuse code when it comes to Visualforce? Well the answer is   Visualforce Component . We can create Visualforce Component , pass parameters to it and use it wherever required. Visualforce Component may or may not have a controller. Component Syntax: <apex:component > <apex:attribute name="ComponentAttributeName" type="String" required="true"/> <apex:outputText   value="{! ComponentAttributeName }"/> <apex:component > Attribute type can be String, Integer, Boolean,  sObject, List or Class                 Syntax to use Component : <c:componentName ComponentAttributeName="Value"/> Visualforce Component can be used in Visualforce page or other Visualforce Component. Let’s implement an application and use Visualforce Compon

Dynamic Visualforce Bindings with Example

Image
This blog will be explaining how to use dynamic Visualforce bindings with example. Sometimes we have to build Visualforce pages based on certain conditions or based on user input, i.e fields on page are determined at run time rather than compile time, In this case rendering based on conditions is not enough to achieve the goal. At this point dynamic Visualforce bindings come into the picture. In dynamic Visualforce bindings along with user input there are methods and properties of the controller that determine how to assemble a new page. Syntax : reference [expression] We can use dynamic binding in formula expression on Visualforce like {!reference [expression]} Where reference can be Sobject or Apex class, expression can be name of the field or object which recursively returns field. In this blog we will be creating Visualforce page for case creation and fields on the form will be decided at run time based on fields selected form will be created. We will show on

Send SMS using Twilio Salesforce Library

Image
SMS is still one of the best way to connect with customer . This blog will be explaining how to use the twilio-salesforce helper library to send SMS. As usual we will implement a small application for it. We will add “Send SMS” button on Account. After clicking “Send SMS” button Salesforce user can type message and send to phone number of that Account. Steps: 1) download the twilio-salesforce library from GitHub.   2) If you don’t have Force.com migration tool install from here . 3) Extract downloaded twilio-salesforce zip file and edit i nstall/build.properties   to insert your Salesforce username and password. append security token to     your password.    Open command line to the install folder, then deploy using Ant:          Command : $ ant deployTwilio 4) Sign up for twilio account by trial pack you can send SMS to verified phone      numbers only.      (If you need you can get paid service so you can send SMS

Component Events in Lightning

Image
This blog will be explaining how to use component event in lightning component by implementing simple search application for Accounts. There are two types of events Component Event : Component event can be handled by any component which is above event firing component in the containment hierarchy. It is best practice to always try to use component event, if possible. Component events can only be handled by components above them in the containment hierarchy so their usage is more localized to the components that need to know about them. Application Event : Application event can be handled by any component where handler is provided. Application event is used where components are different parts of application and there is no containment hierarchy. Lets implement simple searching application with two components and communicate between components by a component event. We have following components and events. 1) eventAccount (event): This is a component eve

Pagination In Lightning Component

Image
This blog is a continuation of ‘Dispalying Data Table in Lightning'.  If you haven't read that blog and want to read click here . In that blog we simply queried Accounts and displayed on lightning component.    The Salesforce Lightning component framework uses a stateful client and stateless server architecture. So we need to take a slightly different approach to do pagination than traditional VF. In order to maintain the value of offset. This is how we are doing. In Server Side Controller: We have a wrapper class AccountWrapper which wraps Accounts need to be displayed in accList, hasNext, hasPrev and offset. Server side action returns instance of AccountWrapper. In Client Side Controller : We have 4 action functions       1)  doinit  : This action function invokes on page load. Querying accounts with default page size.       2)     prev  : This action function invokes after pressing Prev button.       3)     next : This action function invoke

New Way of Pagination

Image
   In salesforce there are 2 ways to achieve pagination. 1) Using StandardSetController (Limitation : To instantiate              StandardSetController we can query up to 10000 records using query     locator.   Querying more than 10000 records causes a LimitException to     be thrown.     However by passing list of more than 10000 records we can instantiate     StandardSetController, again holding more records in the List and instantiate StandardSetController can reach heap size. ) 2) Using OFFSET in SOQL query (Limitation : We can skip max 2000     records using OFFSET which means we cannot do pagination by using     OFFSET if the query skips more than 2000 records. Skipping more than     2000 records causes "Maximum SOQL offset allowed is 2000 error" . )         Here is a new way to achieve it. Hold records you need to display     by   pagination  in List of List of SObjects (i.e List<List<SObject>>).     Where the size of List<SObject>

Dispalying Data Table in Lightning

Image
Lightning is revolutionary change in user interface of Salesforce. This post will be explaining how to use Lightning component to display data in table format by querying data from Sobject, how to use SLDS to format table and call server method from component controller. We have 4 code snippets here. 1. DataTable.cmp - Lightning component to display data. 2. DataTableController.js - Client side controller in Javascript. 3. DataTableController - Server side controller in Apex. 4  DataDisplay.app - Lightning application to where DataTable component will be used. ===================================================================================== 1)  DataTable.cmp <aura:component controller="DataTableController">     <ltng:require styles="{! $Resource.SLDS105 + '/assets/styles/salesforce-lightning-design-system.css'}"/>     <aura:attribute name="accountList" type="Account[]"/>     <aura:handler name="in