About

Edit photo

Thursday, November 9, 2017

Retrieving lightning component tips


How to get Lightning Button label?
<lightning:button label="Get Label" onclick="{!c.getLabel}" aura:id="button1" />  
<aura:attribute name="buttonLabel" aura:id="btn1" type="String"/>

 var BtnLabelWay1 = event.getSource().get("v.label"); -- Used when any Action event occurs, ex: onClick  
 var BtnLabelWay2 = component.find("button1").get("v.label");          -- Can use when auraID exist  

Get and Set Attribute Value
 var att1 = component.get("v.buttonLabel"); -- Getting attribute   
 var att1 = component.find("btn1"); -- Getting attribute using aura:ID  
 component.set(att1,"this is the value for the buttonLabel"); -- Setting attribute with value   

Attribute is empty or not?
 var isEmpty = $A.util.isEmpty(cmp.get("v.label"));  


Wednesday, November 8, 2017

How to get Salesforce Lightning event label to controller?


The below code is a sample component, is having one attribute for message, and has 2 lightning buttons.
Wants to display the button label on Lighting component.

 <aura:component>  
   <aura:attribute name="message" type="String"/>  
   <p>Message of the day: {!v.message}</p>  
   <div>  
     <lightning:button label="You look nice today."  
       onclick="{!c.handleClick}"/>  
     <lightning:button label="Today is going to be a great day!"  
       onclick="{!c.handleClick}"/>  
   </div>  
 </aura:component>  

Controller:
 ({  
   handleClick: function(component, event, helper) {  
     var btnClicked = event.getSource();     // the button  
     var btnMessage = btnClicked.get("v.label"); // the button's label  
     component.set("v.message", btnMessage);   // update our message  
   }  
 })  

Component Displays:


The below code gets Button
 var btnClicked = event.getSource();     // the button  

The below code gets Button label
 var btnMessage = btnClicked.get("v.label"); // the button's label  

The below code updates the attribute named "message"
 component.set("v.message", btnMessage);   // update our message  


Source: trailhead.salesforce.com


Sunday, August 27, 2017

Lightning example, Addition of two numbers in lightning using helper


Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="fname" type="Integer"/>
    <aura:attribute name="lname" type="Integer"/>
    <aura:attribute name="fullname" type="Integer"/>
    
    First name: <ui:inputText value="{!v.fname}"/>
    <br/>
    Last name: <ui:inputText value="{!v.lname}"/>
    <br/>
    <ui:button label="click me to get full name" press="{!c.fullname}" />
    <br/>
    Full name is: {!v.fullname}
</aura:component>


App:
<aura:application >
    <c:basics1/>
</aura:application>


Controller:
({
 fullname : function(component, event, helper) {
  helper.addHelper(component)
 }
})


Helper:
({
 addHelper : function(component, event, helper) {
  console.log("you pressed me buddy!");
        var first = component.get("v.fname");
        var last = component.get("v.lname");
        console.log(first);
        
        var fullname = parseInt(last) + parseInt(first);
        console.log(fullname);
        
        component.set("v.fullname",fullname);
 }
})


Output:

Lightning example, Get FullName



Component:
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    
    <aura:attribute name="fname" type="string"/>
    <aura:attribute name="lname" type="string"/>
    <aura:attribute name="fullname" type="string"/>
    
    First name: <ui:inputText value="{!v.fname}"/>
    <br/>
    Last name: <ui:inputText value="{!v.lname}"/>
    <br/>
    <ui:button label="click me to get full name" press="{!c.fullname}" />
    <br/>
    Full name is: {!v.fullname}
</aura:component>

App:
<aura:application >
    <c:basics1/>
</aura:application>

Controller:
({
 fullname : function(component, event, helper) {
  console.log("you pressed me buddy!");
        var first = component.get("v.fname");
        var last = component.get("v.lname");
        console.log(first);
        
        var fullname = last + ', '+first;
        console.log(fullname);
        
        component.set("v.fullname",fullname);
 }
})

Output:

@SsaiK

Sunday, June 4, 2017

Salesforce Visualforce Pages Beginner component examples


What is Section Header and how to create? 
     If you are creating a new page and each page needs title and description, can be done by Section Header.

Code:

<apex:page >
    <apex:sectionHeader title="Section1" subtitle="Subtitle1" description="Description1" help="http://google.com" rendered="true"/>
</apex:page>

What is Global Data? how can we use it in VF pages in Salesforce?
     Global data is nothing but accessible in globally. we have many Global variables available in salesforce, refer the link to get all types of Global Variables.

https://help.salesforce.com/articleView?id=dev_understanding_global_variables.htm&language=en_US&type=0

Some Commonly used Global variables are
$User
$Label
$ObjectType
$Organization
$Permission
$Profile
$System
$UserRole

Code:

<apex:page controller="calAge">
    <apex:sectionHeader title="Section1" subtitle="Subtitle1" description="Description1" help="http://google.com" rendered="true"/>

    Lastname: <b>{!$User.LastName}</b> <br/>
    Organization: <b>{!$Organization.Name}</b> <br/>
    Profile: <b>{!$Profile.Name}</b>
    
</apex:page>

How to Parse Data from URL?
     {!$CurrentPage.Parameters.parameterName} is used to get Parameters from URL.
Example, Display Name, Age and Gender from URL in VF page.


Code:
<apex:page>
    <apex:sectionHeader title="Section1" subtitle="Subtitle1" description="Description1" help="http://google.com" rendered="true"/>

    Lastname: <b>{!$User.LastName}</b> <br/>
    Organization: <b>{!$Organization.Name}</b> <br/>
    Profile: <b>{!$Profile.Name}</b>
    
    Parameters from URL: -> {! $CurrentPage.Parameters.Name}, {! $CurrentPage.Parameters.Age}, {! $CurrentPage.Parameters.Gender}
    
</apex:page>

What is Controller in VF page?
     There are two type of controllers in the salesforce, named Standard Controller and Custom Controller.
Standard Controller    :-> StandardController = '<Standard Object Name>'
Custom Controller      :-> Controller = '<Apex class name>'
Extension                    :-> Extension = '<Apex class name>'

Example: Get account name, Note: can't get account name until id parameters parsed in URL.
URL?id=0014100000S6O0s

Code:
<apex:page StandardController="Account">
    <apex:sectionHeader title="Section1" subtitle="Subtitle1" description="Description1" help="http://google.com" rendered="true"/>

    Lastname: <b>{!$User.LastName}</b> <br/>
    Organization: <b>{!$Organization.Name}</b> <br/>
    Profile: <b>{!$Profile.Name}</b><br/><br/>
    
    Account name: {! Account.name}
        
</apex:page>

Example 2: Get list of Account names from Account object.
     It's time to use DataTable, if there are nay repetitive records or list of records, DataTable is required.

<!-- Updated soon-->

What are Output Components in VF page?
Output components are used to display the data, it works just like label in HTML.
OutputLabel  ->   Cannot Edit, Read only
OutputText    ->   Connot Edit, Read only
OutputField   ->   Can Edit, if used InlineEditing option.


Code:

<apex:page StandardController="Account">
    <apex:sectionHeader title="Section1" subtitle="Subtitle1" description="Description1" help="http://google.com" rendered="true"/>

    Lastname: <b>{!$User.LastName}</b> <br/>
    Organization: <b>{!$Organization.Name}</b> <br/>
    Profile: <b>{!$Profile.Name}</b><br/><br/>
    
    <apex:form >
        <apex:inlineEditSupport >
            <apex:outputLabel value="{!account.name}"/>   <br/>
            <apex:outputText value="{!account.name}"/>   <br/>
            <apex:outputField value="{!account.name}"/>   <br/>
        </apex:inlineEditSupport>
    </apex:form>
</apex:page>

What are Input components in VF pages? and example.
     Input components are used to input the values to the object, it is like Textbox in VisualStudio, inputField in HTML.

inputText     -> Used to Input text, irrespective to datatype
inputlabel    -> same as inutText, irrespective to datatype
inputField    -> Same as inputText, respective to Datatype
inputSecret  ->  Password type
inputHidden  -> Hidden Mode

What are Select Components in VF page? and Example.
     Used to select multiple/single (Ex: picklist/Radio/checkbox) value from list of options.
SelectList
SelectOption  -> Options in the picklist are created using this components
SelectOptions  -> When list of options are already available in List datatype.



Code:
VF Page:
<apex:page Controller="calAge1">
    <apex:sectionHeader title="Section1" subtitle="Subtitle1" description="Description1" help="http://google.com" rendered="true"/>

    Lastname: <b>{!$User.LastName}</b> <br/>
    Organization: <b>{!$Organization.Name}</b> <br/>
    Profile: <b>{!$Profile.Name}</b><br/><br/>
    
    <apex:form >
        <apex:selectList size="1">
          <apex:selectOption itemLabel="jan" itemvalue="one"/>
          <apex:selectOption itemLabel="feb" itemvalue="two"/>
          <apex:selectOption itemLabel="mar" itemvalue="three"/>
        </apex:selectList>
        
        <apex:selectList size="1">
          <apex:selectOptions value="{! Method1}"/>
        </apex:selectList>
    </apex:form>
</apex:page>

Apex Custom Controller:
public with sharing class calAge1 {
    public List<SelectOption> getMethod1()
    {
        List<Account> lname = [Select name from account limit 10];
        List<SelectOption> ll = new List<SelectOption>();
        for(integer i=0;i<10;i++)
        {
            ll.add(new selectOption(String.valueOf(i),String.valueOf(lname[i].name)));
        }
        return ll;
    }
}

by
SsaiK

Sunday, March 19, 2017

How to install Apache ANT tool on Windows 10



Installing Apache ANT on Windows 10

Download the Apache ANT from http://ant.apache.org/bindownload.cgi
Extract to the C -> Program Files

Now open the system properties, click on environment variables;

do the same as in the screen shot
Set JAVA_HOME:

Set ANT_HOME:


Click on PATH and add the highlighted text


Now restart the system and check whether it is installed succesfully by typing,
ant -version

@SsaiK

Saturday, March 18, 2017

Scheduling Jobs Simple examples


Example1:

Create a task for the opportunity owners who's opportunity is not closed even close date cross the close date.

Note: Schedule and Batch classes always should be Global.

global class RemindOpptyOwners implements Schedulable {

    global void execute(SchedulableContext ctx) {
        List<Opportunity> opptys = [SELECT Id, Name, OwnerId, CloseDate 
            FROM Opportunity 
            WHERE IsClosed = False AND 
            CloseDate < TODAY];
        // Create a task for each opportunity in the list
        TaskUtils.remindOwners(opptys);
    }
    
}
//Code from Salesforce.com - Trailhead


NoteTaskUtils.remindOwners(opptys); is creates a task for the owners.

Now, Autorun the jobs for every Monday at 2 am.

Schedule jobs run as -> Seconds Minutes Hours DaysOfMonth Month DayOfWeek Year

There are also some special characters you can use:

, used to delimit values [hours, day of month, month, day of week, year]
– used to specify a range [hours, day of month, month, day of week, year]
* used to specify all values [hours, day of month, month, day of week, year]
? used to specify no specific value [day of month, day of week]
/ used to specify increments [hours, day of month, month, day of week, year]
L used to specify the end of a range [day of month, day of week]
W used to specify the nearest weekday [day of month]

# used to specify the nth day of the month [day of week]

RemindOpptyOwners reminder = new RemindOpptyOwners();
// Seconds Minutes Hours Day_of_month Month Day_of_week optional_year
String sch = '0 30 8 10 2 ?';
String jobID = System.schedule('Remind Opp Owners', sch, reminder);


Testing:
http://blog.deadlypenguin.com/blog/2012/05/26/scheduled-actions-in-salesforce-with-apex/

I'll write my own test, Coming soon with real time examples.