Wednesday 28 February 2018

One Universal Schedule Class to Execute All Batch Classes In Salesforce

Are you creating schedule class for each batch class if you need to schedule that?

If yes, stop doing like that and start creating a universal (common scheduler class) like below and use it instead of creating multiple schedules.

Step 1: 
Create a universal scheduler class

  1. public class UniversalScheduler implements Schedulable{
  2.   public Database.Batchable<SObject> batchClassName{get;set;}
  3.   public Integer batchScopeSize{get;set;} {batchScopeSize = 200;}
  4.   public void execute(SchedulableContext sc) {
  5.      Database.executebatch(batchClass, batchSize);
  6.     }
  7. }


Step 2:
Let say, You have two batch classes and you want to schedule, then schedule batch class like below using UniversalScheduler class

Batch Class 1:
  1. AccountBatchProcess accBatch = new AccountBatchProcess(); // Batch Class Name
  2. UniversalScheduler scheduler = new UniversalScheduler();
  3. scheduler.batchClass = accBatch;
  4. scheduler.batchSize = 100;
  5. String sch = '0 45 0/1 1/1 * ? *';
  6. System.schedule('Account Batch Process Scheduler', sch, scheduler);


Batch Class 2:
  1. ContactBatchProcess cntBatch = new ContactBatchProcess(); // Batch Class Name
  2. UniversalScheduler scheduler = new UniversalScheduler();
  3. scheduler.batchClass = cntBatch;
  4. scheduler.batchSize = 500;
  5. String sch = '0 45 0/1 1/1 * ? *';
  6. System.schedule('Contact Batch Process Scheduler', sch, scheduler);



What is aura:attribute in lightning components?

What is aura:attribute?
Attributes on components are like instance variables in objects. They’re a way to save values that change, and a way to name those value placeholders. 

Example:
Created Component called AttributeComponent:

  1. <aura:component >
  2.     <aura:attribute name="ProjectName" type="String" required="true"/>
  3.     <aura:attribute name="DefaultView" type="String" default="This is default String"/>
  4.     <aura:attribute name="AccountInfo" type="Account" />
  5.  
  6.     <lightning:card title="Grouped Item">
  7.         <p> Project Name: {!v.ProjectName}</p>
  8.         <p> Default Value: {!v.DefaultView}</p>
  9.         <p> Account Name: {!v.AccountInfo.Name}</p>
  10.         <p> Account Number: {!v.AccountInfo.AccountNumber}</p>
  11.     </lightning:card>
  12.    
  13. </aura:component>

I have created 3 attributes and displayed in the above example.
First Attribute called "ProjectName" and type "String" and required as true.
Second Attribute called "DefaultView" and type "String" with Default value.
Third Attribute called "AccountInfo" and type "Account" (Standard Object).

Created another Component called PassAttributeValue:

  1. <aura:component >
  2.     <c:AttributeComponent ProjectName="My Project" AccountInfo="{'sobjectType': 'Account', 'Name' : 'Test Account', 'AccountNumber' : '322342'}"/>
  3. </aura:component>

In this component, I am passing/assigning values to the attributes. So if I run PassAttributeValue component via lightning app, then output will be as below,



Attribute Data Types:
aura:attribute type supports the following data types,
  • Primitives data types, such as Boolean, Date, DateTime, Decimal, Double, Integer, Long, or String. The usual suspects in any programming language.
  • Standard and custom Salesforce objects, such as Account or MyCustomObject__c.
  • Collections, such as List, Map, and Set.
  • Custom Apex classes.
  • Framework-specific types, such as Aura.Component, or Aura.Component[]. These are more advanced than we’ll get to in this module, but you should know they exist.

Reference:

What is lightning:card in Salesforce?

Lightning:card tag (lightning component) is similar to apex:outputpanel (Visualforce page). It act as a container. 

A lightning:card is used to apply a stylized container around a grouping of information. The information could be a single item or a group of items such as a related list.

A lightning:card contains a title, body, and footer. To style the card body, use the Lightning Design System helper classes.

  1. <aura:component >
  2.     <lightning:card title="Container" iconName="standard:account">
  3.      This is for Testing.
  4.     </lightning:card>
  5. </aura:component>

title attribute is required to use lightning:card.
iconName You can set icon name from this link.

Reference:

Tuesday 27 February 2018

Is My Domain Required to Use Lightning Components in Salesforce?

Is My Domain Required to Use Lightning Components in Salesforce?

YES

Reason:

To use Lightning Components, your organization needs to have a custom domain configured using My Domain.

So what the heck is a custom domain, and why do you need to have one to use Lightning Components? First of all, a custom domain is a way to have your very own Salesforce server…sort of. It’s a way for you to use Salesforce from your own, customized URL, rather than a generic Salesforce instance URL. That is, once you have a custom domain, you’ll use Salesforce at https://yourDomain.my.salesforce.com/, which is reserved exclusively for your org’s use. Let other folks continue to use and share https://na30.salesforce.com/. Your custom domain puts you on your own private Internet island.

Setting up a custom domain has a lot of benefits besides just getting you a cool URL. Among other things, a custom domain lets you:
  • Highlight your business identity with your unique domain URL
  • Brand your login screen and customize right-frame content
  • Block or redirect page requests that don’t use the new domain name
  • Work in multiple Salesforce orgs at the same time
  • Set custom login policy to determine how users are authenticated
  • Let users log in using a social account, like Google and Facebook, from the login page
  • Allow users to log in once to access external services

Reference:
https://trailhead.salesforce.com/modules/lex_dev_lc_basics/units/lex_dev_lc_basics_prereqs

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...