Thursday, 28 January 2021

URL Hacking in Lighting Experience

 Hi,

Here we are going to learn how to do URL hacking in Lightning Experience.

1)When we have to navigate to the child new record page with default values from the parent Detail page then we have to follow the below step:

  • Create a detail button URL type with the following url
  • /lightning/o/<child_Object_APIName>/new?defaultFieldValues=<FieldAPIName1>=<value>,<FieldAPIName2>=<Value>
  • Eg:
  • /lightning/o/Contact/new?defaultFieldValues=LastName={!URLENCODE(Account.Name)},AccountId={!Account.Id}

2)When we have to navigate to the child new record page with default values from the parent Related List then we  have to follow the below step:

  • Create a list button URL type with the following url
  • /lightning/o/<child_Object_APIName>/new?defaultFieldValues=<FieldAPIName1>=<value>,<FieldAPIName2>=<Value>&navigationLocation=RELATED_LIST&backgroundContext=/lightning/r/<ParentObjectAPINName>/<ParentObjectRecordId>/view
  • Eg:
  • /lightning/o/Contact/new?defaultFieldValues=LastName={!URLENCODE(Account.Name)},AccountId={!Account.Id}&navigationLocation=RELATED_LIST&backgroundContext=/lightning/r/Acccount/{!Account.Id}/view


Note:

We shouldn't use standard button API Names as Custom Buttton API Names.

Reference:

https://releasenotes.docs.salesforce.com/en-us/spring20/release-notes/rn_general_lex_navigate_to_record_dfv.htm


Sunday, 24 January 2021

How to get Image URL from a RichTextArea field

 Hi,

Here we are going to learn how to get an Image URL from a RichTextArea if someone adds an image in RichTextArea.

String decodedImageUrl;

 Matcher imgMatcher = Pattern.compile( '<img(.+?)>' ).matcher(<RichTextArea_FieldAPIName>);

// iterate each image tag found

        while ( imgMatcher.find() ) {        

            // get the image tag html

            String imageTag = imgMatcher.group();

            System.debug( 'imageTag=' + imageTag );

            String imageURL = imageTag.substringBetween( ' src="', '"' );

            System.debug( 'imageURL=' + imageURL );

            decodedImageUrl= imageURL.unescapeHtml4();

         }  

Reference:

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_pattern_and_matcher_matcher_methods.htm

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_pattern_and_matcher_pattern_methods.htm#apex_classes_pattern_and_matcher_pattern_methods


How to Convert Image URL to Blob Content

 Here,

We are going to learn how we can convert Image URL to Blob Content with the help of PageReference.

Sample Example:

PageReference page = new PageReference(ImageUrl);

Blob body = page.getContent();

Note: getContent() method considers a callout

Smart Search(Auto Complete) in Visualforce using JavaScript Remoting

 Hi,

Here we are going to learn how to prepare values from JavaScript for SmartSearch.

Scenario:

Fill "list" attribute from JavaScript Remoting.

Solution:

When we add  "list" attribute it adds <dataList>  in HTML in background automatically as shown below.


Sample Controller with Remote Method:

public class SmartSearchController {   

    public String selectedName{get;set;}

    @RemoteAction

    public static List<String> getAccounts() {

       List<String> accountNameList = new List<String>();

       for(Account actObj:[select id,name from Account limit 20]){

            accountNameList.add(actObj.Name);

        }

       return accountNameList;

    }

}

Sample Visualforce Page:

<apex:page docType="html-5.0" id="pg" cache="false" sidebar="false" showheader="false" standardStylesheets="false" controller="SmartSearchController">

    <apex:form id="frm">

        <apex:pageBlock title="Smart Search" id="pb">

            <apex:inputText list="" value="{!selectedName}" id="nameList"/>        

        </apex:pageBlock>

    </apex:form>

    <script>

window.onload = function(){

            Visualforce.remoting.Manager.invokeAction(

                    '{!$RemoteAction.SmartSearchController.getAccounts}',                     

                    function(result, event){

                        var options='';

                        if (event.status) {

                                for (var i = 0; i < result.length; i++) {

                                    options += '<option value="' + result[i] + '" />';

                                }

                                document.getElementById('pg:frm:pb:nameList:datalist').innerHTML = options;                              

                        } 

                    }, 

                    {escape: true}

                );

        }

    </script>

</apex:page>

In the above snippet we are using "dataList" id for preparing list of items.

Output:



Reference:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_example.htm

https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_autocomplete



Smart Search in Visualforce page

 Hi,

Here we are going to learn how can we provide smart search with the help of HTML 5 attribute "list" in a visualforce page if your browser supports HTML5.


Sample Controller:

public class SmartSearchController {

    public List<String> accountNameList{get;set;}   

    public String selectedName{get;set;}

        

    public SmartSearchController(){

        accountNameList = new List<String>();

        for(Account actObj:[select id,name from Account limit 20]){

            accountNameList.add(actObj.Name);

        }

    }

}

Sample Visualforce Page:

<apex:page docType="html-5.0" cache="false" sidebar="false" showheader="false" standardStylesheets="false" controller="SmartSearchController">

    <apex:form>

        <apex:pageBlock title="Smart Search">

            <apex:inputText list="{!accountNameList}" value="{!selectedName}"/>        

        </apex:pageBlock>

    </apex:form>

</apex:page>

Note: To use "list" attribute on inputText we should specify docType="html-5.0" or heigher version.

Output:






Reference:

https://www.w3schools.com/howto/howto_js_autocomplete.asp

https://www.w3schools.com/tags/att_input_list.asp




Thursday, 21 January 2021

How to provide navigation in VF Page for lightning and classic

 Hi ,

We are going to discuss that how we can provide navigation when we have to navigate to another VF page from a VF page in lightning and classic.


if('{!$User.UITheme}'=='Theme4d' || '{!$User.UITheme}'=='Theme4u' ||                         '{!$User.UITheme}'=='Theme4t') {              

             //Lightning

              sforce.one.navigateToURL(urlLink);

} else {

           //Classic 

window.location.href = urlLink;

}


References:

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_global_useruitheme.htm

What’s the difference between Einstein Article Recommendations and Suggested Articles?

How Does Einstein Article Recommendations Work? Einstein Article Recommendations helps support agents resolve customer cases efficiently by ...