About

all about SFDC

Sunday, 2 June 2019

Using trigger events / context variables with enum System.TriggerOperation

In summer'18 release Salesforce has first introduced enum System.TriggerOperation which consists specific set of trigger context variables AFTER_DELETE, AFTER_INSERT, AFTER_UNDELETE, AFTER_UPDATE, BEFORE_DELETE, BEFORE_INSERT,BEFORE_UPDATE.

This enum makes life easy for developer from using different context variables like triger.isAfter and trigger.isInsert with a bunch of AND statements and IF statements. The new Trigger context variable Trigger.operationType  will returns an enum System.TriggerOperation during trigger context. With this enum we can easily identify the current trigger context and can invoke our logic from handlers. This enum can also be used with in a trigger handler class.

The simple snippet below demonstrates using this enum with a switch statement.

Result in debug logs when updated a record on Account object.








Happy coding, cheers!!!


Resources:
Releases notes Spring'19
TriggerOperation Enum




Sunday, 25 March 2018

Lightning Component for Sending Email for List View Selected Records and using Email Templates

Hi there, At the time of this blog post, There is no standard Lightning component available for Email composer, So I created a custom component for sending Email and mimic of the standard email composer and also for sending Listview selected records.

I assumed sending email for person accounts (person accounts by default not available in salesforce you have to rise a case to enable them) of Opportunities. Please choose different object for sending(from contact List view)  since if you don't have person accounts enabled you will get compile errors.

You also need to create a rich text field in any object since we don't have standard richtext tags in lighting at the time of posting this blog post. We need rich text field to mimic the email composer screen and also to render the text review of template selected.

I have used a List view button of type visualforce in opportunities List view and in visualforce page i have placed Lightning Component.

The list view selected records will be sent to Lightning Component.

Get the snippets below to image.





Visualforce Page:


Controller Extension:
EmailComp:
Controller.js:
Helper.js:
EmailComp Apex Class:



I did not mentioned the snippet for the component "c:reUsableMultiSelectLookup" here. Because it is a custom look up component that can be available from many places like salesforce forums and blogs. All you need to do is to tweak the init section of your look up component by passing the selected items to display them automatically. 

Formula Field to calculate hours from Date Time field in Salesforce

Hey there, This is sample formula field to get difference in hours from date time field to current time.

I have considered Event standard field ActivityDateTime to calculate hours in this example

See formula below screenshot.



formula:




Sunday, 10 December 2017

Salesforce Notes view VF Component

Hello geeks,

This is about a SF Notes display in view only. Actually intended for a specific profile to display notes in View only in Detail Page Layout and removing standard related list and added a custom VF page in Detail section . I came across this scenario in one of my project and i hope it would be useful for someone.

Used an  OFFSET based pagination since ContentNotes doesn't allow standardsetcontroller pagination. And also to display popup used a rerender based to make component simple as possible.




Page:

VF Component:

Apex Cls:

Saturday, 9 December 2017

Salesforce Lightning Compent to Insert Multiple Attachments

Hello there.

This is about a Lighting Component for uploading multiple Attachments for any Object.

It would work for all objects and can also be re usable in SF communities. To get an easy understanding i've used the component in Quick Action / lightning action. Thanks to Manoj for actual idea and support.







The Attachment would be inserted simultaneously  when selected a file and also deleteing would deleted from database.

Component:


Controller JS:

Helper JS:


Styles:


Apex cls:

Sunday, 5 November 2017

Using external Javascript libraries in Lightning / Chart JS in Salesforce Lightning

To reference a JavaScript library that you’ve uploaded as a static resource, use a <ltng:require> tag in your .cmp or .appmarkup.


The afterScriptsLoaded action in the client-side controller is called after the scripts are loaded. Don't use the init event to access scripts loaded by <ltng:require>. These scripts load asynchronously and are most likely not available when the initevent handler is called


Lets have a look at the basic initialization of external chart librarbies in Lightning using  Chart JS





1) Import Chart JS min bundle  or get the latest from chart js site ans save it into static resource

2) Create a lighting component bundle and app as shown below sample code.




Demo App:


Component:


ControllerJS:


ApexClass:




Sunday, 17 April 2016

Search Apex Classes in Your Sandbox

Hello Everybody,  Do you ever had a thought created a page to Search and Display Apexclasses. Please have a look at this snippet and it will works in Every Sandbox and Developer Editions and You can also Create for Pages Search as well except for the Managed packages which comes inbuild isolated body and of the class
Hope you like It! Have fun of Coding!


Search View


View Body



Apex Class:
public without Sharing class ApexControllerSearch {
    Public string inputtext{get;set;}
    Public List ApxLst{get;set;}
    Public boolean flagshow{get;set;}
    public string clsName{get;set;}
    public ApexClass Apxcls{get;set;}
    public boolean pb1{get;set;}
    public boolean pb2{get;set;}
    
    Public ApexControllerSearch(){
    flagshow = false;
    pb1=true;
    ApxLst = new List();
    Apxcls = new ApexClass();
    
    }    
    
    Public void actionSupMethod(){
    
     system.debug('inputtext-->'+inputtext);
     ApxLst.clear();
     Apxcls.clear();
     //string clas = '(hidden)';
    flagshow = true;
    if(inputtext!='')
    {
      
      flagshow = true;
      ApxLst = database.Query('select name,Status from ApexClass where name like '+'\''+'%'+inputtext+'%'+'\''+' limit 20');
    }
    if(String.IsEmpty(inputtext)|| ApxLst.size()==0)
    {
    flagshow = false;
    }

    }

    public void ApxCl()
    {
    getCls();
    
    
    }
    
    public ApexClass getCls()
    {
    pb1=false;
    pb2=true;
    flagshow = false;
    //ids='0039000001WeRlR';
    Apxcls = new ApexClass();
    Apxcls = [select Name,body from ApexClass where name=: clsName limit 1 ];
    system.debug('----------------> ' +Apxcls );
    return Apxcls;
    
    
    }
    Public void Reset()
    {
    inputtext='';
    actionSupMethod();
    }


}
VF Page:


<apex:page controller="ApexControllerSearch" >
  <apex:form id="fm" >
      <apex:pageBlock >
        Type Apex Class Name Here :<apex:inputText value="{!inputtext}" html-placeHolder="Search..." id="Text" >
          <apex:actionSupport action="{!actionSupMethod}" event="onkeyup" reRender="outptText,pb,fm2" />
        </apex:inputtext>
        <apex:commandButton value="Search" action="{!actionSupMethod}" reRender="outptText,pb,fm2" />
        <apex:commandButton value="Reset" action="{!Reset}" reRender="outptText,pb,fm2,fm" />
      </apex:pageBlock>
      </apex:form>
 
<apex:form id="fm2">
    <apex:pageblock rendered="{!flagshow}" id="pb" >
 
      <apex:pageblocktable value="{!ApxLst}" var="Cl" id="outptText" >
      <apex:column >
        <apex:commandlink Value="View" action="{!ApxCl}" status="pageStatus" rerender="fm2" style="color:blue;" >  
        <apex:param value="{!Cl.name}" name="Sel" assignTo="{!clsName}" />
        </apex:commandlink>
        </apex:column>
        <apex:column value="{!Cl.name}"/>
        <apex:column value="{!Cl.Status}"/>
      </apex:pageblocktable>
    </apex:pageblock>
 
<apex:pageblock title="Apex Class" rendered="{!Apxcls.body!=null}" >
<apex:inputTextarea id="newDesc" value="{!Apxcls.body}"/>
<apex:pageBlockButtons >
<apex:commandButton value="Back" action="{!actionSupMethod}" reRender="outptText,pb,fm2"/>
 
</apex:pageBlockButtons>
    </apex:PageBlock>
 
 
 
  </apex:form>
</apex:page>
Powered by Blogger.

Visualforce

Apex

Lightening UI