TransWikia.com

How to redirect to standard lead convert page in lightning

Salesforce Asked by Pavan tej on November 8, 2021

Currently, I’m working on lightning migration. So, I’m converting the javascript buttons to related quick actions & quick actions with the vf page respectively.

I’m facing issues with the following custom javascript button.

  1. I need to alert the user based on specific conditions.
  2. If there are no issues i need to redirect the user to standard Lead Convert page.I’m facing issue in this step

My Component:

    <aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global"  controller="JavaScript_migration_controller">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="myText" type="string" default=""/>
     <aura:attribute name="url" type="String" />
    <aura:attribute name="pageReference" type="Object" />
 <lightning:navigation aura:id="navigation"/>
    <div class="slds-notify slds-notify_alert slds-theme_alert-texture slds-theme_error" role="alert" aura:id="alerta">
  <span class="slds-assistive-text">error</span>
  <span class="slds-icon_container slds-icon-utility-error slds-m-right_x-small" title="Description of icon when needed">
  </span>
    
    <ui:outputText value="{!v.myText}"/>
</div>
</aura:component>

Apex Class:

    ({
    doInit : function(component, event, helper) {
        var action = component.get("c.fieldCheker");
        var recordId=component.get("v.recordId");
        action.setParams({
            "recId" : recordId
        });
        action.setCallback(this, function(response){
            var state = response.getState(); 
            if(state == 'SUCCESS') {                
                var returnValue= response.getReturnValue() 
                if(returnValue!=null){
                    if(returnValue.Promo__c==null || returnValue.Promo__c =='undefined'){
                        //alert("To convert this lead, Please specify whether Marketing Promo is applied or not.nnYou can update this information using the 'Promo' field under 'Marketing Information' section.nnThank you for your co-operation.")
                        var toastEvent = $A.get("e.force:showToast");
                        toastEvent.setParams({
                            title: "Error!",
                            message: "To convert this lead, Please specify whether Marketing Promo is applied or not.nnYou can update this information using the 'Promo' field under 'Marketing Information' section.nnThank you for your co-operation.",
                            type: "Error"});
                        //$A.get("e.force:closeQuickAction").fire()
                        //dismissActionPanel.fire();
                        //$A.get("e.force:refreshView").fire();
                        //toastEvent.fire(); 
                        //$A.get("e.force:refreshView").fire();
                        /*var svg = component.find("svg_content");
        var value = svg.getElement().innerText;
        value = value.replace("<![CDATA[", "").replace("]]>", "");
        svg.getElement().innerHTML = value;*/
                        component.set('v.myText','To convert this lead, Please specify whether Marketing 'Promo' is applied or not.nYou can update this information using the Promo field under 'Marketing Information' section.nThank you for your co-operation');
                    }
                    else if(returnValue.Flag_Type__c == 'Related'){
                       component.set('v.myText','You don't have sufficient access to convert a related lead.nPlease swap this lead to master by clicking the swap to master buttonnFor more information contact SMO team.');
                    }
                        else{
                            /*var navLink = component.find("navigation");
                            var pageRef = {
                                type: 'standard__objectPage',
                                attributes: {
                                    actionName: "convert",
                                    objectApiName: 'Lead',
                                    recordId : recordId  
                                },
                            };
                            navLink.navigate(pageRef, true);*/
                            var urlString = window.location.href;
                            var baseURL = 'https://testaz--current.lightning.force.com';
                            //use apex or JS libraries to get the base URL
                            // urlString.substring(0, urlString.indexOf("/lightning"));
                            var urlEvent = $A.get("e.force:navigateToURL");
                            urlEvent.setParams({
                            //ws is the relative url to the redirect screen once lead is converted. right now it will got to account page
                            "url": baseURL + '/lightning/cmp/runtime_sales_lead__convertDesktopConsole?leadConvert__leadId=' + recordId + 'ws=%2Flightning%2F%2FLead%2F'+recordId+'%2Fview'
                            });
                            urlEvent.fire();
                        }
                }
            }
        });
        if(recordId !=null && 'undefined' ){
            $A.enqueueAction(action);
        }
        
    }
})

4 Answers

this url : /lightning/cmp/runtime_sales_lead__convertDesktopConsole?leadConvert__leadId=' + recordId

will be this work if we are opening the same url in mobile browser or from salesforce1 App ? please let me now

Answered by chops on November 8, 2021

enter image description hereYou have to convert your Apex class to AuraEnabled method and use it in Aura to validate and redirect to standard lead convert page

  1. Apex class with the existing validation
  2. Aura to call #1 method on init
  3. Aura to show an error if validation fails Aura method to
  4. subsequently call the convert redirect page if all good

    <aura:attribute name="url" type="String" />
    <aura:attribute name="pageReference" type="Object" />
</aura:component>

controllerJs

    ({
    validate: function (cmp, event, helper) {
        //do apex call to validate and based on outcome call the method below
    },
    convertlead: function (cmp, event, helper) {
        console.log('Here');
        //get lead id dynamically using component .get recordid
        var leadid = '00Q2v00001fIBE6EAO';
        var urlString = window.location.href;
        var baseURL = 'https://contrivergcp-dev-ed.lightning.force.com';
        //use apex or JS libraries to get the base URL
        // urlString.substring(0, urlString.indexOf("/lightning"));
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({
            //ws is the relative url to the redirect screen once lead is converted. right now it will got to account page
            "url": baseURL + '/lightning/cmp/runtime_sales_lead__convertDesktopConsole?leadConvert__leadId=' + leadid + 'ws=%2Flightning%2Fr%2FLead%2F00Q2v00001fIBH0EAO%2Fview'
        });
        urlEvent.fire();
    }

})

Answered by GirishP on November 8, 2021

I understand you want error message in popup in lightning.

We can use platform events + .addError() in trigger to achieve this.

  • Create platform event, keep Publish Behavior = Publish Immediately.
  • You can publish event before just before adderror
  • Create lightning component which listens to events on Lightning record page of Lead.

Let me know if you'd like me to add more detailed steps on this.

Thank you.

Answered by Vitap Ramdevputra on November 8, 2021

Based on the specific conditions in the apex controller, you can achieve same conditions using validation rules on Lead object. This will work both in SF Classic and Lightning via the std button and lead path (so no need for the visualforce page).

E.g validation rule for the first condition on Promo__c field

IsConverted && ISBLANK(Promo__c)

Create other validation rules for conditions on Qualification_Score__c and Flag_Type__c

Make sure that Require Validation for Converted Leads is enabled under Lead settings.

The validation rule will fire after the user clicks on Convert on the lead conversion page.

Answered by Shamina on November 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP