Play Games

Search This Blog

Wednesday, December 14, 2016

How to change the column name of related lookup fields of an object in a report in salesforce

Problem: An opportunity report is created using custom report type.
When we are displaying Billing City of Account object in report,its column name is showing as "Account Name: Billing City" as shown in the image below.

We need to change that column name from "Account Name: Billing City" to "Billing City".
Solution : We can change the column names from the edit layout of custom report type created.
Steps :
1) Go to the custom report type created  from setup --> Create --> Report Types.
Click on the label of that particular report type.A screen will appear as shown in the image below.

2) Click on the "Edit Layout" button. The layout will be opened as shown in the image below.


3) Search the column in the layout whose name to be changed.For example "Billing City" as shown in image below.

4)Double click on that particular field,A popup window will be opened as shown in the image below

Now you can change the name in "Display As" column as Shown in the image below.

Click "ok" after changing column names and then save the layout.
Now you can refresh the report and observe that the column names are changed...
Enjoy...

How to display related lookup fields of an object in report Salesforce

Problem : In order to display a report on opportunities,A custom report type "Opportunity Report Type" is created.While creating the report with this custom report type, we were unable to display fields of account record (lookup)which is associated with this opportunity.
Solution : We need to add all the related lookup fields to the custom report type layout.
Steps :
1) Go to the custom report type created  from setup --> Create --> Report Types.
Click on the label of that particular report type.A screen will appear as shown in the image below.

2) Click on the "Edit Layout" button. The layout will be opened as shown in the image below.

3) We can add the related lookup fields by using "Add fields related VIA Lookup" hyperlink which is present on the right side of the layout as shown in image below.

Select "Opportunity Fields" in view and click on "Add fields related VIA Lookup" hyperlink.A popup window opens as shown in image below

From here you can select all related fields which you want to show on report as shown in the image below.

Click on "Ok" after selecting fields and then save the layout by clicking "Save" button.
Now you can refresh the report...You will be able to see all the related fields in the palette.

Friday, December 9, 2016

How to give header and footer while generating pdf using visualforce page in salesforce

Example:
Apex Class :
public class GeneratePdf {
    public List<Account> accList {get;set;}
    public void generateReport() {
        accList = [select id,name,AccountSource,phone,industry from Account];
    }
}
Visualforce Page :
<apex:page renderAs="pdf" applyBodyTag="false" controller="GeneratePdf" action="{!generateReport}" applyHtmlTag="false" showHeader="false">
    <head>
        <style type="text/css" media="print">
            @page {                
                @top-center {                  
                    content: element(header);              
                }
                @bottom-left {
                    content: element(footer);
                }          
                margin-top: 100px;
                margin-bottom:80px;
            }                      

            div.header {              
                padding: 10px;            
                position: running(header);          
            }          
            div.footer {              
                display: block;            
                padding: 5px;              
                position: running(footer);        
            }                      

            .pagenumber:before {              
               content: counter(page);            
            }                      
            .pagecount:before {            
                content: counter(pages);          
            }                  
        </style>          
      </head>
     
      <div class="header">
          <div><center>List Of Accounts</center></div>
       </div>
       <div class="footer">
            <div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
      </div>
          <div class="content">
                <table cellspacing="0" cellpadding="5" width="100%" style="line-height:25px" border="1">
                 
                    <tr width="100%" style="border:1px">
                        <th>Account Name</th>
                        <th>AccountSource</th>
                        <th>Industry</th>
                        <th>Phone</th>
                        </tr>
                    <apex:repeat value="{!accList}" var="acc">
                        <tr width="100%" style="border:1px solid">
                            <td>{!acc.name}</td>
                            <td>{!acc.AccountSource} </td>
                            <td>{!acc.Industry} </td>
                            <td>{!acc.phone} </td>
                       
                        </tr>
                    </apex:repeat>
                </table>
          </div>

</apex:page>
Output:

How to get time from Datetime field in apex salesforce

Solution : Use field.format('h:mm a') to get time from DateTime field
Example:
Apex Class:
public class TimeController {
    public String sTime {get;set;}
    public String sTime1 {get;set;}
    public TimeController (){
        DateTime dtDateTime = system.now();
        sTime = dtDateTime.format('h:mm a');
        sTime1 = dtDateTime.format('h:mm');
    }
}
Visualforce Page :
<apex:page controller="TimeController">
Note The time is getting displayed :<b> {!sTime} </b><br/>
Note The time is getting displayed :<b>{!sTime1} </b>
</apex:page>
Output:

Wednesday, November 9, 2016

How to increase font size in notepadd++

Solution :
Go to Settings --> Style Configurator.

You will find the screen as shown in the image below.
In this screen,You can set the desired font size and make sure to set the Style as "Global Override" and  the "Enable global font size" checkbox as selected and then click "Save & Close" button

Saturday, November 5, 2016

Hover Functionality in Page Block Table Salesforce

Example :
Apex Class :
public class HoverOnPageBockTable {  
    public List<Account> accList {get;set;}
    public HoverOnPageBockTable () {
        accList =[select id,name,phone from Account limit 5];
    }

}  
Visualforce Page:
<apex:page controller="HoverOnPageBockTable">
   <style>
    a:hover {
        background:#ffffff;
        text-decoration:none;
    }
    a.tooltip span {
        display:none;
        padding:2px 3px;
        margin-left:8px;
        width:250px;
    }
    a.tooltip:hover span{
        display:inline;
        position:absolute;
        background:#FFC;
        border:1px solid #cccccc;
        color:#000000;
    }
    </style>
    <apex:form >
        <apex:pageBlock >
        <apex:pageBlockTable value="{!accList}" var="acc" id="pb">
            <apex:column rendered="true">
                <a class="tooltip" target="_blank">{!acc.name}
                <span>
                        {!acc.Name} - {!acc.id}
                </span>
                </a></apex:column>
        </apex:pageBlockTable>
        </apex:pageblock>
    </apex:form>

</apex:page>
Output:

Friday, November 4, 2016

Some Salesforce related tools/apps that ease our work

At First,I would like to say thanks to Benewards for sharing those tools.
I am just sharing the url so that my friends will get benefited from it.
Go through the url : SFDC Tools  where you find some tools that may be helpful to you.

Salesforce Giving Back website Url

Salesforce Giving Back URL : Giving Back 

Thursday, November 3, 2016

How to display hover details in visualforce Page(Pop Over Page)

Solution : Use the below syntax to display hover popover page
<a href="/{!acc.Id}"
id="{!acc.Id}"
position="relative"
onblur="LookupHoverDetail.getHover('{!acc.Id}').hide();"
onfocus="LookupHoverDetail.getHover('{!acc.Id}', '/{!acc.Id}/m?retURL=%2F{!acc.Id}&isAjaxRequest=1').show();"
onmouseout="LookupHoverDetail.getHover('{!acc.Id}').hide();"
onmouseover="LookupHoverDetail.getHover('{!acc.Id}', '/{!acc.Id}/m?retURL=%2F{!acc.Id}&isAjaxRequest=1').show();">
{!acc.name}
</a>
where acc.id will be the id of the object

Example :
Apex Class :
public class HoverDetailController {
    public List<Lead> leadList {get;set;}
    public HoverDetailController () {
        leadList =[select id,name,LeadSource,Status from Lead limit 5];
    }
}
Visualforce Page:
<apex:page controller="HoverDetailController">
    <apex:pageBlock title="Lead Records With Hover Page on hover">
        <apex:pageBlockTable value="{!leadList}" var="lead">
            <apex:column ><a href="/{!lead.Id}" id="{!lead.Id}" position="relative"
                onblur="LookupHoverDetail.getHover('{!lead.Id}').hide();"
                onfocus="LookupHoverDetail.getHover('{!lead.Id}', '/{!lead.Id}/m?retURL=%2F{!lead.Id}&isAjaxRequest=1').show();"
                onmouseout="LookupHoverDetail.getHover('{!lead.Id}').hide();"
                onmouseover="LookupHoverDetail.getHover('{!lead.Id}', '/{!lead.Id}/m?retURL=%2F{!lead.Id}&isAjaxRequest=1').show();">
                {!lead.name}
                </a>
            </apex:column>
            <apex:column value="{!lead.LeadSource}"/>
            <apex:column value="{!lead.Status}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Output :


Important Note : If we want to add/remove some fields from popover page,you can do that in mini page layout.

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.

Thursday, September 22, 2016

Uncaught ReferenceError: angular is not defined

Problem : This error will come when we are referring angular like "var app = angular.module('myApp',[]);" before loading angular.js files.
Sample Code that leads to error:
<script>
var app = angular.module('myApp',[]);

app.directive('myDirective',function(){

return function(scope, element,attrs) {
element.bind('click',function() {alert('click')});
};

});
</script>
<script src="lib/angular/angular.js"></script>
Solution : Just include angular.js files at the top of page before referring it.
Modify above code like this
<script src="lib/angular/angular.js"></script>
<script>
var app = angular.module('myApp',[]);

app.directive('myDirective',function(){

return function(scope, element,attrs) {
element.bind('click',function() {alert('click')});
};

});
</script>

Friday, September 9, 2016

How to find Which edition of Salesforce we are using

Steps :
Step 1: Go to setup --> Click on Administer as shown in image below.

Step 2: On clicking "Administer" link,you will find the screen as shown in image below.

At the top Middle of screen, you will find the edition of salesforce you are using as highlighted in the image above.

Thursday, August 25, 2016

get Sobject name from Sobject in apex - Salesforce Globe For You

Sample Code :
Sobject sObj = (Sobject) new Account();
String sObjName = sObj.getSObjectType().getDescribe().getName();
system.debug('sObjNamesObjName :'+sObjName );

Output :

Monday, August 22, 2016

Dynamically get datatype of a field in apex Salesforce.

Problem : I know sobject name and field api name as well.Now I want to know the datatype of this field dynamically in apex
Solution:
For example :
String sObjName ='contact';
String fieldName = 'Birthdate';
Schema.DisplayType fielddataType =  Schema.getGlobalDescribe().get(sObjName).getDescribe().fields.getMap().get(fieldName).getDescribe().getType();
system.debug('fielddataType fielddataType '+fielddataType );
if(fielddataType == Schema.DisplayType.Date) {
   System.debug('Birthdate Field DataType is : Date');
}
Output :

How to make first letter of a word Capital in apex Salesforce

Use "capitalize() " to make first letter of a word as Capital.
Sample Code :
Run the below piece of code in Apex execute of Workbench
String str ='hello';
str= str.capitalize();
system.debug('Output String : '+str);
Output :


Tuesday, August 9, 2016

How to restrict other picklist values getting saved in particular picklist field other than its predefined values in salesforce?

Solution : By selecting " Strictly enforce picklist values" checkbox, we can enable validation of picklist values against the list of defined values.
we define picklist values when we create the custom picklist field.
However, users can introduce extraneous/new values by loading values through the API.
In order to restrict adding new values to picklist through API's,We need to select "Strictly enforce picklist values" checkbox when creating/updating the custom picklist field as shown in the image below.

Note : Only a new custom picklist field can be a restricted picklist. we can't convert an existing non-restricted picklist to a restricted picklist.

How to use(include) lightning component in visualforce page(salesforce)

Steps :
Step 1: Develop the lightning component which you need to include/display in vf page.
Lightning Component :LightningComponentInVF.cmp
<aura:component >
    <ltng:require styles="{!$Resource.SLDS100 +
         '/assets/styles/salesforce-lightning-design-system-ltng.css'}"/>
    <div class="slds">
         <h1>Lets see how to include this component in visualforce Page</h1>
    </div>
</aura:component>
Note : Replace "SSLDS100" with the static resource which holds lightning files.
Step 2: Create a lightning app to hold this lightning component.
Lightning app : LightningComponentInVFPage.app
<aura:application access="GLOBAL" extends="ltng:outApp">
    <aura:dependency resource="ksk:LightningComponentInVF"/>
</aura:application>
Imp Note : In order to make this app available for vf page ,we need to give global access for this and also need to use "ltng:outApp" interface as shown in the above app code.
Step 3: Create a visualforce page and use this app in it.
Visualforce Page : LightningComponentInVfPage
<apex:page standardStylesheets="false" showHeader="false" sidebar="false">
<!-- include the lightning.out.js file -->
    <apex:includeScript value="/lightning/lightning.out.js" />
<!-- Provide a section/div for lightning component-->
    <div id="lightningComponentDiv" />
    <script>
        $Lightning.use("ksk:LightningComponentInVFPage", function() {
          $Lightning.createComponent("ksk:LightningComponentInVF",
          {},
          "lightningComponentDiv",
          function(cmp) {
          });
        });
    </script>
</apex:page>
Note : Replace "ksk:LightningComponentInVFPage" with your lightning app and also replace "ksk:LightningComponentInVF" with your lightning component in the above vf page code.
Output : Once you run the vf page,the output will be like this.

Monday, August 8, 2016

How to override standard required field validation messages in visualforce page Salesforce.

Steps :
Step 1: First we need to use required="false" for that field as shown in the below piece of code.
<apex:inputField value="{!acc.name}" required="false"/>
Step 2: To make that field required use the sample code below.
<apex:pageBlockSectionItem > Account Name
   <apex:outputPanel layout="block" style="float: left">
 <apex:outputPanel >
<div class="requiredInput"><div class="requiredBlock"/>
 <apex:inputField value="{!acc.name}" required="false" />          
</div>
 </apex:outputPanel>                              
   </apex:outputPanel>
</apex:pageBlockSectionItem>

Example :
Apex Class : StandardErrorOverrideController
public class StandardErrorOverrideController {
    public account acc {get;set;}
    public StandardErrorOverrideController() {
        acc = new Account();
    }
    public void saveData() {

        try {
        insert acc;
        } catch(DMLException e) {
            if(acc.name =='' || acc.name == null) {
                acc.name.addError('Account Name Cannot be Null');
            }
        }      
   }    
}
Visualforce Page :
<apex:page controller="StandardErrorOverrideController">
<apex:form >
    <apex:pageBlock title="My Content" mode="edit">
        <apex:pageBlockButtons >
            <apex:commandButton action="{!saveData}" value="Save"/>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="My Content Section" columns="2">
             <apex:pageBlockSectionItem > Account Name
               <apex:outputPanel layout="block" style="float: left">
                      <apex:outputPanel >
                            <div class="requiredInput"><div class="requiredBlock"/>
                                  <apex:inputField value="{!acc.name}" required="false" />          
                            </div>
                      </apex:outputPanel>                              
               </apex:outputPanel>
            </apex:pageBlockSectionItem>
            <apex:inputField value="{!acc.site}"/>
            <apex:inputField value="{!acc.type}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>
Output :
With out entering value for account name,click save button.The custom error message will appear as shown in the image below.

Standard Error message will be as shown in the image below.

How to create new contact When ever account is created/updated and rating equals to "Hot" using process Builder.

Steps :
Step 1: Go to Setup --> Create --> Workflow & approvals --> process Builder --> Click on "New" button to create a new process as shown in the image below

Step 2: Enter process name,description etc as shown in the image below and click on "Save".

Step 3: Click on "Add Object" ,a screen will appear at the right side as shown in the images below.
Select the object as "Account" and select the checkbox "When a record is created or edited"  in the start the process section.
and then click on "Save" button.


Step 4: Click on "Add Criteria" as shown in the image below. and then enter criteria name.
In the Criteria for Executing Actions,select "Conditions are met".
In the Set Conditions ,we need to add one row to keep condition.
Select rating (Account Rating) in the Field lookup and in the value select "hot" as the value as shown in the image below and then click on "save"


Step 5: Click on "Add Action" in the immediate actions as shown in the image below.

A screen will be displayed at the right side.
Select action type as "Create a record".
Give any name for Action Name
Select contact as record type.
In the set Field Values section,We need to add 2 rows.
1)One is to map contact name with account name.
2)The other is to map the newly created contact with its parent account record.
Add the 2 rows as shown in the image below.

Note : Need to use reference in the type to map contact name with its account name.
Step 6: Click on "Activate" button to activate the flow as shown in the image below.

It will show a popup as shown in the image below.

Click on "Confirm" button to activate the flow.
That's it..Now when we create a new account record With rating as "hot" or update existing account record with "hot" as rating value,New contact will get created as shown in the image below.