Wednesday, 23 August 2023

Get URL of List View on Partner Portal

A Salesforce partner portal is an online platform that enables external partners to collaborate with an organization's internal teams using Salesforce tool. It is like a website that can be hosted in the Salesforce Environment.

Looking from development perspective, Salesforce allows most of its features to be hosted on Partner website quite easily. However, certain features such as VisualForce pages (VF Pages for short) do not work on partner portal.

Usage of VF Page is now replaced by its more powerful counterparts such as LWC and Aura. However in Lightning experience (LEX for short), a VF Page specifically can be utilised for creating List View Buttons as it is easier to fetch the URL of list view from it and get the selected records.

In this article, I am going to show you, how you can bring a list view button, that was hosting a VF Page, on a partner portal. Please note that our motive is to get the URL of the current page, we are not required to develop a separate VF page. Just one LWC component would suffice the need of fetching the URL.

The steps are the following:

1. First, get the Page URL on which the list view is hosted. In LEX, VF page was utilised to get the URL. 

2. Create a LWC component to fetch the URL and make it visible on the Partner portal

3. Use URL fetched by LWC to perform your actions such as query on the list view records, get the list view Id etc..

Hope you have a happy learning. Please feel free to comment in case of doubts.

In case of doubts and queries, feel free to drop email on supernovasrm@gmail.com.


Creating the LWC Component


XML File

<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

    <masterLabel>ListViewLWC_partnerportal</masterLabel>

    <description>LWC that can fetch the partner portal URL</description>

    <apiVersion>52.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightningCommunity__Page</target>

        <target>lightningCommunity__Default</target>

    </targets>

    </LightningComponentBundle>



JS File


import { LightningElement, wire} from 'lwc';

import { CurrentPageReference } from 'lightning/navigation';

export default class ListViewLWC_partnerportal extends LightningElement {


// This variable contains all the details of the URL

urlStateParameters ;

strButtonHeader ='Sample Button on Partner Portal';


 @wire(CurrentPageReference)

    getStateParameters(currentPageReference) {

       if (currentPageReference) {

          this.urlStateParameters = currentPageReference.state;

          if(this.urlStateParameters){

           // Perform your logic here

          }

       }

    }

 handleButtonClick(){

        // Add your logic

 }

}

HTML

<template>

  <lightning-button label={strButtonHeader} onclick={handleButtonClick}>

   </lightning-button>

</template>


UI



Happy Learning!!


No comments:

Post a Comment

Get URL of List View on Partner Portal

A Salesforce partner portal is an online platform that enables external partners to collaborate with an organization's internal teams us...