Play Games

Search This Blog

Monday, October 31, 2016

Generate Random Number in Salesforce

Using Math.Random() we can generate random Number
Example :
Apex Class:
public class RandomNumberController {
    public Double randomNumber {get;set;}
    public RandomNumberController() {
        randomNumber = Math.random();  
    }
}
Visualforce Page:
<apex:page controller="RandomNumberController">
  <B>Random Number is:</B>{!randomNumber}
</apex:page>
Output : Everytime you run the vf page,you get different numbers as output as shown in the images below.



Monday, October 24, 2016

How to access Custom Label in Visualforce Page

Solution : using $Label.labelName We can access custom label.
where $Label is the global variable and labelName is the api name of custom label created
Example :
Created the custom label as shown in the image below

Visualforce Page :
<apex:page>
    <b>Custom Label</b> :{!$Label.Custom_Error_Message}  
</apex:page>
Output :

How to access custom label in apex class

Solution : using Label.labelName We can access custom label.
where labelName is the api name of custom label created
Example :
Create the custom label as shown in the image below.

Apex Class:
public class CustomLabel {
    public String labelStr {get;set;}
    public CustomLabel () {
        labelStr = label.Custom_Error_Message;
    }
}
Visualforce Page :
<apex:page controller="CustomLabel">
    <b>Custom Label</b> :{!labelStr}

</apex:page>
Output :

Friday, October 21, 2016

Package.xml file for permission set in salesforce

Sample package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Testing</members>
        <name>PermissionSet</name>
    </types>
    <version>36.0</version>

</Package>

Note: Place all permission sets by adding new row as members.
For eample: Testing is api name of permission set.

Tuesday, October 18, 2016

How to display multiple options for a field to select(Multiple checkboxes)

Problem : I want to design the vf page as shown in the image below.

Apex Class :
public class MultipleCheckboxes {
    public List<MultipleCheckboxWrap> lstRecords {get;set;}
    public MultipleCheckboxes () {
    
        lstRecords = new List<MultipleCheckboxWrap>();
        lstRecords.add(new MultipleCheckboxWrap('English',false,false,false,false));
        lstRecords.add(new MultipleCheckboxWrap('Maths',false,false,false,false));
        lstRecords.add(new MultipleCheckboxWrap('Science',false,false,false,false));
    }
    public class MultipleCheckboxWrap {
        public string fieldLabel {get;set;}
        public boolean isOne {get;set;}
        public boolean isTwo {get;set;}
        public boolean isThree {get;set;}
        public boolean isFour {get;set;}
        public MultipleCheckboxWrap (String l,boolean one,boolean two,boolean three,boolean four) {
            fieldLabel =l;
            isOne = one;
            isTwo = two;
            isThree = three;
            isFour  = four;
            
        }
        
    }
    public void m() {
        List<string> lstpicklist1;
        List<string> lstpicklist2;
        for(MultipleCheckboxWrap s : lstRecords ) {
            if(s.isOne == true) {
                lstpicklist1.add(s.fieldLabel);    
            }
            if(s.isTwo == true) {
                lstpicklist2.add(s.fieldLabel);    
            }
        }
    }
}
Visualforce Page :
<apex:page controller="MultipleCheckboxes">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!lstRecords}" var="a">
            <apex:column value="{!a.fieldLabel}" title="picklist Value" headerValue="picklist Value"/>
            <apex:column headerValue="One"><apex:inputCheckbox value="{!a.isOne}" title="One" /></apex:column>
            <apex:column headerValue="Two"><apex:inputCheckbox value="{!a.isTwo}" title="Two" /></apex:column>
            <apex:column headerValue="Three"><apex:inputCheckbox value="{!a.isTwo}" title="Three" /></apex:column>
            <apex:column headerValue="Four"><apex:inputCheckbox value="{!a.isTwo}" title="Four" /></apex:column>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>

How to display dropdown values in visualforce page

Apex Class:
public class DropDownController {
    public String selectedVal {get;set;}
    public List<SelectOption> getPicklistOptions() {
        List<SelectOption> options = new List<Selectoption>();
        options.add(new selectOption('One', 'One'));
        options.add(new selectOption('Two', 'Two'));
        options.add(new selectOption('Three', 'Three'));
        options.add(new selectOption('Four', 'Four'));
        return options;
    }
}
Visualforce Page:
<apex:page controller="DropDownController">
    <apex:form >
        <b>Numbers DropDown </b>:<apex:selectList value="{!selectedVal}" size="1">
        <apex:selectOptions value="{!PicklistOptions}"/>
        </apex:selectList>
    </apex:form>
</apex:page>
Output: 

Friday, October 7, 2016

ForEach Function in angular JS

HTML Sample Code:
<!DOCTYPE html>
<html ng-app="">  
<head>  
<script SRC="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js">  
</script>  
 
</head>  
<body>
<fieldset>
<legend>ForEach Function in angular JS</legend>
<script>      
 
var peopleList = [{name: 'Ashish', gender: 'male'},{name: 'Vikram', gender: 'male'},{name: 'Geetha', gender: 'Female'}];
document.write("To display Name:</br>");
angular.forEach(peopleList, function(value, key) {
  document.write(value.name);
  document.write("</br>");
});
 document.write("To display Gender:</br>");
angular.forEach(peopleList, function(value, key) {
  document.write(value.gender);
  document.write("</br>");
});
</script>
</fieldset>
</body>  

</html>
Output:


Thursday, October 6, 2016

How to update an object on page load Salesforce

Apex Class:
public class UpdateObjectOnPageLoadController {
    public UpdateObjectOnPageLoadController () {
     
    }
    public void updateUser() {
        List<User> lstUser = [select id,name,Title from user where id=:UserInfo.getUserId()];
        lstUser[0].title ='SFDC King';
        update lstUser[0];
        system.debug('USER UPDATED :'+lstUser[0]);
   
    }
   
}
Visualforce Page :
<apex:page controller="UpdateObjectOnPageLoadController" action="{!updateUser}">
</apex:page>

Output: Once we run the above vf page,The title of currently loggedin user will get updated to 'SFDC King' as shown in the image below.


Monday, October 3, 2016

Salesforce Lightning Input Lookup Custom Component

After spending lot of time googling,I found a package which helped me to get input lookup in lightning component.
At first I would like to thanks "Enreeco" for providing that input lookup component.
I am just sharing his post so that my friends will get benefited from it.
Please install the package from here Lightning Input Lookup Field.

Reference Links : https://github.com/enreeco/inputlookup 

List of Lightning Components in salesforce

Here is a link to find all the available lightning components in app exchange
List of Lightning Components.