Wednesday 27 April 2016

How to identify or detect a device in Salesforce Lightning Component

Salesforce provides global function called $Browser. By using this, you can dynamically identify or detect a device and display contents based on device.

The $Browser global value provider returns information about the hardware and operating system of the browser accessing the application.

  1. <aura:component >
  2.     <aura:if isTrue="{!$Browser.isTablet}">
  3.         You are running this page from your tablet.
  4.     </aura:if>
  5.    
  6.     <aura:if isTrue="{!$Browser.isAndroid}">
  7.         You are running this page from your andriod device.
  8.     </aura:if>
  9.    
  10.     <aura:if isTrue="{!$Browser.formFactor=='DESKTOP'}">
  11.         You are running this page from your desktop.
  12.     </aura:if>
  13. </aura:component>


Reference:


Tuesday 26 April 2016

AuraEnabled methods must be named with a prefix 'get' in Salesforce

You may received an error as AuraEnabled methods must be named with a prefix 'get'. If yes, check out the below points to resolve the issue,

1. Methods must be static and marked public or global. Non-static methods are not supported.


  1. @AuraEnabled
  2. public static string buildName()
  3. {
  4.    return 'Hi';
  5. }

2. If you are declaring method without any return type then the method name should prefix with  'get'.

  1. @AuraEnabled
  2. public static void getValidName()
  3. {
  4. // Logic here.
  5. }

Monday 25 April 2016

Salesforce official blog is one of the best place to improve technical capability

Here is the official salesforce blog, which will helpful you to improve technical capability in Salesforce,

https://developer.salesforce.com/blogs




You can also navigate and get various topic such as Tech Docs, Developer Relations from side bar.

Wednesday 6 April 2016

How to add or access related object or related list record details in Visualforce email template in Salesforce

          Visualforce Email Template supports to access a related list or related object records by using relatedTo.reationshipObjectName.

In the below example, showed Contact and Opportunity records related the Account object.

Here,
Account --> Parent Object
Contact and Opportunity --> Child Objects

In email template,
Contact records accessed by relatedTo.Contacts
Opportunity records accessed by relatedTo.Opportunities


Sample VF Template:

  1. <messaging:emailTemplate subject="Your Detailed Contact and Opportunities" recipientType="User" relatedToType="Account">
  2.     <messaging:htmlEmailBody >
  3.         <p> Dear {!relatedTo.Name}</p>
  4.         The following customers are waiting for your approval,
  5.        <ul>
  6.             <apex:repeat var="cn" value="{!relatedTo.contacts}">
  7.                 <li>
  8.                      {!cn.Name}
  9.                 </li>
  10.             </apex:repeat>
  11.        </ul>
  12.        The following opportunities are ready to close,
  13.        <ul>
  14.             <apex:repeat var="cn" value="{!relatedTo.opportunities}">
  15.                 <li>
  16.                      {!cn.Name}
  17.                 </li>
  18.             </apex:repeat>
  19.        </ul>
  20.         <p> Thanks, </p>
  21.         <p> Sales Team </p>
  22.     </messaging:htmlEmailBody>
  23. </messaging:emailTemplate>

Tuesday 5 April 2016

How to pass html input field values from visualforce page to apex controller in Salesforce

     The following example code will explain about how to pass html input field values from visualforce page to apex controller in Salesforce.

Apex Class:

  1. public class SubmitFormController
  2. {
  3.     public string username{get;set;}
  4.     public string password{get;set;}
  5.     public void submitForm()
  6.     {
  7.       System.debug('## User name: '+username);  
  8.       System.debug('## Password: '+password);  
  9.     }
  10. }

Visualforce Page:

  1. <apex:page controller="SubmitFormController">
  2.     <script type="text/javascript">
  3.     function submitData() {
  4.         var uname = document.getElementById('username').value;
  5.         var password = document.getElementById('password').value;
  6.         submitActionFunction(uname, password);
  7.     }
  8.     </script>
  9.     <apex:form>
  10.         <apex:actionFunction name="submitActionFunction" action="{!submitForm}"  reRender="actionFun">
  11.             <apex:param name="uname" assignTo="{!username}" value="" />
  12.             <apex:param name="pwd" assignTo="{!password}" value="" />
  13.         </apex:actionFunction>
  14.         <center>
  15.             Username: <input type="text" id="username" value=""/> <br/> <br/>
  16.             Password: <input type="text" id="password" value=""/> <br/> <br/>
  17.             <input type="button" onclick="submitData();" value="Submit From HTML Button"/> &nbsp; &nbsp;
  18.             <apex:commandButton value="Submit From Apex Button" onclick="submitData();" reRender="sapex"/>
  19.         </center>
  20.     </apex:form>  
  21. </apex:page>

What is done on the VF Page?

1. Wrote Javascript function named as submitForm. Input field values are accessed using DOM element and called the actionFunction (submitActionFunction)

2. The above javascript function has been called from button onclick event. actionFunction tag will call an apex method and passed html input field values as parameter.

3. Here i am sending two input text fields, so two apex:param tags are used and assigned the values to the corresponding apex controller variable using assignTo attribute.

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...