How to query DateTime field in Salesforce?

Salesforce stores the DateTime in GMT.

Below SOQL will give the number of accounts that were created between 5 PM to 5.15 PM EST.

Since EST is +5 from GMT, 12 + 5 + 5 = 22 is used in the query.

Sample SOQL:

SELECT COUNT( Id ) FROM Account WHERE CreatedDate >= 2019-03-04T22:00:00Z AND CreatedDate <= 2019-03-04T22:15:00Z

Output:


Advanced PDF to Render Visualforce Page as PDF File

Advanced PDF renders Visualforce pages as PDF files with broader support for modern HTML standards, such as CSS3, JavaScript, and HTML5. This change applies to both Lightning Experience and Salesforce Classic.

To use Advanced PDF, set renderAs="advanced_pdf" in the <apex:page> tag of a Visualforce page with API version 40.0 or later.

Limitations:
  1. If you use inline CSS styles, set the API version to 28.0 or later. Also set <apex:page applyBodyTag="false">, and add static, valid <head> and <body> tags to your page, as in the previous example.
  2. The maximum response size when creating a PDF file must be less than 15 MB before being rendered as a PDF file. This limit is the standard limit for all Visualforce requests.
  3. The maximum file size for a generated PDF file is 60 MB.
  4. The maximum total size of all images included in a generated PDF is 30 MB.
  5. PDF rendering doesn’t support images encoded in the data: URI scheme format.
  6. The following components don’t support double-byte fonts when rendered as PDF.<apex:pageBlock><apex:sectionHeader>
  7. These components aren’t recommended for use in pages rendered as PDF.
  8. If an <apex:dataTable> or <apex:pageBlockTable> has no <apex:column> components that are rendered, rendering the page as PDF fails. To work around this issue, set the table component’s rendered attribute to false if none of its child <apex:column> components are rendered.

Sample Code:


  1. <apex:page readOnly="true"     
  2.            standardController="Account"    
  3.            applyHtmlTag="false"     
  4.            sidebar="false"     
  5.            showHeader="false"     
  6.            cache="true"     
  7.            renderAs="advanced_pdf">    
  8.         
  9.     <head>    
  10.         <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />    
  11.         <style type="text/css">    
  12.             
  13.             @page {    
  14.               
  15.                 size: A4 landscape;    
  16.                 border: 2px solid black;    
  17.                 padding-left: 8px;    
  18.                 padding-right: 8px;      
  19.                   
  20.             }    
  21.                 
  22.             th {    
  23.               
  24.                 text-align: center;    
  25.                 font-weight: bold;    
  26.                   
  27.             }    
  28.                 
  29.                 
  30.             td {    
  31.               
  32.                 text-align: center;    
  33.                 font-size: 14px;    
  34.                   
  35.             }    
  36.                 
  37.         </style>    
  38.           
  39.     </head>    
  40.       
  41.     <center>    
  42.       
  43.         <h3>Testing Advanced PDF = {!Account.Name}</h3>    
  44.           
  45.     </center><br/><br/>    
  46.       
  47.     <table border="1" width="99%">    
  48.       
  49.         <tr>    
  50.           
  51.             <th>First Name</th>    
  52.             <th>Last Name</th>    
  53.               
  54.         </tr>    
  55.         <apex:repeat value="{!Account.Contacts}" var="con">    
  56.           
  57.             <tr>    
  58.               
  59.                 <td>{!con.FirstName}</td>    
  60.                 <td>{!con.LastName}</td>    
  61.                   
  62.             </tr>    
  63.               
  64.         </apex:repeat>    
  65.           
  66.     </table>    
  67.     
  68. </apex:page>    

Output:


Difference between api, track and wire in Lightning Web Component

@api
To expose a public property, decorate it with @api.
Public properties define the API for a component. An owner component that uses the component in its markup can access the component’s public properties. Public properties are reactive. If the value of reactive property changes, the component’s template rerenders any content that references the property.
To expose a public method, decorate it with @api. Public methods are part of a component’s API. You can use a JavaScript method to communicate down the containment hierarchy. For example, an owner calls a method on a child component that it contains.

@track
To track a private property’s value and re-render a component when it changes, decorate the property with @track. Tracked properties are also called private reactive properties.

@wire
To read Salesforce data, Lightning web components use a reactive wire service. When the wire service provisions data, the component rerenders. Components use @wire in their JavaScript class to specify a wire adaptor or an Apex method.

How to invoke Apex Controller from Lightning Web Component?

Apex Class:

  1. public with sharing class AccountController {  
  2.   
  3.     @AuraEnabled( cacheable = true )  
  4.     public static List< Account > fetchAccounts( String searchKey ) {  
  5.       
  6.         String strKey = '%' + searchKey + '%';  
  7.         return [ SELECT Id, Name, Industry FROM Account WHERE Name LIKE: strKey LIMIT 10 ];  
  8.           
  9.     }  
  10.       
  11. }  

Lightning Web Component HTML:


  1. <template>  
  2.       
  3.         <lightning-card title = "Search Accounts" icon-name = "custom:custom63">  
  4.       
  5.             <div class = "slds-m-around_medium">  
  6.       
  7.                 <lightning-input type = "search" onchange = {handleKeyChange} class = "slds-m-bottom_small" label = "Search" >  
  8.                 </lightning-input>  
  9.       
  10.                 <template if:true = {accounts}>  
  11.       
  12.                     <template for:each = {accounts} for:item = "account">  
  13.       
  14.                         <p key = {account.Id}>{account.Name}</p>  
  15.       
  16.                     </template>  
  17.           
  18.                 </template>  
  19.           
  20.                 <template if:true = {error}>  
  21.       
  22.                     {error}>  
  23.                       
  24.                 </template>  
  25.       
  26.             </div>  
  27.       
  28.         </lightning-card>  
  29.       
  30. </template>  

Lightning Web Component JavaScript:


  1. import { LightningElement, track } from 'lwc';  
  2. import fetchAccounts from '@salesforce/apex/AccountController.fetchAccounts';  
  3.   
  4. export default class sample extends LightningElement {  
  5.   
  6.     @track accounts;  
  7.     @track error;  
  8.   
  9.     handleKeyChange( event ) {  
  10.           
  11.         const searchKey = event.target.value;  
  12.   
  13.         if ( searchKey ) {  
  14.   
  15.             fetchAccounts( { searchKey } )    
  16.             .then(result => {  
  17.   
  18.                 this.accounts = result;  
  19.   
  20.             })  
  21.             .catch(error => {  
  22.   
  23.                 this.error = error;  
  24.   
  25.             });  
  26.   
  27.         } else  
  28.         this.accounts = undefined;  
  29.   
  30.     }  
  31.   
  32. }  

Lightning Component:


  1. <aura:component implements="force:appHostable">  
  2.   
  3.     <article class="slds-card">  
  4.   
  5.         <c:sample/>  
  6.            
  7.     </article>  
  8.   
  9. </aura:component>   

Output:

Create a Lightning component tab to view the output.