Posts

Showing posts from April, 2019

How to create lighting components in salesforce:full example

Image
In this component we will see how to create a lightning component Steps. 1.Open developer console from setup 2. Create new Lightning Component 3. The lightning bundle will get created 4. Now add the attributes (variables) and markup in the component section Copy this code to the component sections <aura:component controller="ContactController" implements="force:appHostable,flexipage:availableForAllPageTypes"    access="global">     <aura:attribute name="Amount" type="double" default="25000"/>      <aura:attribute name="Tenure" type="double" default="16"/>     <aura:attribute name="Maturity" type="double" default="34"/>     <aura:attribute name="accid"  type="String" default=""/>     <aura:attribute name="accountName" type="String" default=""/>     <aura:attribute name=&

How to expose a salesforce apex class as Rest API

salesforce lightning, 1. Create connected app and generate user secret and key 2. Give Full access for this project under connected app permission 3. Create your apex class and test in  workbench://use this url to call from workbench /services/apexrest/GetCase2/5009000001NxD87 Apex code @RestResource(urlMapping='/GetCase2/*') global with sharing class RestCaseCreatorurl {     @HttpGet     global static Case getCaseById() {         RestRequest request = RestContext.request;         // grab the caseId from the end of the URL         String caseId = request.requestURI.substring(request.requestURI.lastIndexOf('/')+1);        Case result =  [SELECT CaseNumber,Subject,Status,Origin,Priority FROM Case WHERE Id = :caseId];         return result;               }         @HttpPost     global static  String createcase1(String status, String origin){                 Case cs = new Case();         cs.Status = status;         cs.Origin = origin;         insert cs;         return cs.

How to schedule batch class in salesforce

Benefits of batch apex The execution logic of the batch class is called once for each batch of records. The default batch size is 200 records. You can also specify a custom batch size. Furthermore, each batch execution is considered a discrete transaction. With each new batch of records, a new set of governor limits is in effect. In this way, it’s easier to ensure that your code stays within the governor execution limits. Another benefit of discrete batch transactions is to allow for partial processing of a batch of records in case one batch fails to process successfully, all other batch transactions aren’t affected and aren’t rolled back if they were processed successfully. This is a use case that we all come across very often, Schedule a batch class every hour to clean up data or to send out batch emails to case team members (Which I’ll blog about later). There are three main steps involved in this  1.          Write a Batch class with the required logic 2.          Write a Scheduled

What is implicit sharing in salesforce

Implicit Sharing The sharing capabilities of the Force.com platform include a wide variety of features that administrators can use to explicitly grant access to data for individuals and groups. In addition to these more familiar functions, there are a number of sharing behaviors that are built into Salesforce applications. This kind of sharing is called  implicit  because it is not configured by administrators; it is defined and maintained by the system to support collaboration among members of sales teams, customer service representatives, and clients or customers. This table describes the different kinds of implicit sharing built into Salesforce applications and the record access that each kind provides. Type of Sharing Provides Details Parent Read-only access to the parent account for a user with access to a child record ·        Not used when sharing on the child is controlled by its parent ·        Expensive to maintain with many account

Custom settings to enable disable salesforce validation rules

salesforce lightning, How to disable/enable all validation rules for data loading While working on a recruiting application, I found a solution for being able to load data into a SalesForce application without being blocked by validation rules. Validation rules are usually intended to be applied only when a user creates a record and not when data is being imported from an external database. In this recruiting application, candidate records go several stages in a sequence (1-lead, 2-phone, 3-applicant, 4-interview, 5-contract negotiation, etc.) and this validation rule prevented the import process from loading candidate records in a stage higher than lead. So the solution was to create a Custom Setting of type Hierarchy with a flag/checkbox in it that disables validation rules for a given user or profile. That is, all the validation rules will include this flag and only apply when the value of this flag is enabled. To implement it: 1) click Setup, then on the left side, click App Setu

How to call future(asynchronous class in apex) methods from salesforce apex triggers and not run into governor limits

  Use @future Appropriately      As articulated throughout this article, it is critical to write your Apex code to efficiently handle bulk or many records at a time. This is also true for asynchronous Apex methods (those annotated with the @future keyword).           Even though Apex written within an asynchronous method gets its own independent set of higher governor limits, it still has governor limits. Additionally, no more than ten @future methods can be invoked within a single Apex transaction. ·     Here is a list of governor limits specific to the @future annotation: ·     No more than 10 method calls per Apex invocation ·     No more than 200 method calls per Salesforce license per 24 hours. ·     The parameters specified must be primitive dataypes, arrays of primitive  datatypes, or collections of primitive datatypes. ·     Methods with the future annotation cannot take sObjects or objects as arguments. ·     Methods with the future annotation cannot be used in Visualforce con