2

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.\n\nYou can update this information using the 'Promo' field under 'Marketing Information' section.\n\nThank 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.\n\nYou can update this information using the 'Promo' field under 'Marketing Information' section.\n\nThank 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 button\nFor 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);
        }
        
    }
})
2
  • what's the error message /issue you are facing at #2 you are receiving
    – GirishP
    Commented May 3, 2020 at 11:15
  • @girish i have updated my question with your logic.Could you please check and let me know if i missed anything
    – Pavan tej
    Commented Jul 21, 2020 at 16:57

4 Answers 4

2

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

1

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();
    }

})
6
  • It didn't worked at all
    – Pavan tej
    Commented Jul 21, 2020 at 8:40
  • I can see you are pretty good at marking "the answer is not useful" even if this didn't work for you, Appreciate the efforts if someone puts to solve your problem. if you will do copy paste it won't work for the obvious reason (i have hard coded id). the approach is proof of concept and I know it works coz I did it.
    – GirishP
    Commented Jul 21, 2020 at 12:59
  • Sorry, Girish if you want i will post my updated code. But i don't want intentionally to be hardcoded as the wrong answer.Anyway i will update my code
    – Pavan tej
    Commented Jul 21, 2020 at 13:20
  • I'm not sure maybe it's working for you. I didn't hardcoded any values except my domain & it's opening the convert page with saying internal server error
    – Pavan tej
    Commented Jul 21, 2020 at 13:52
  • Could you please check again because I'm not able to reverse my vote until you have updated the answer
    – Pavan tej
    Commented Jul 21, 2020 at 15:06
0

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.

2
  • Hey I have already tried this but some other issues on the account and opportunity validation rules are firing.so I have created this button and in future if we need to customise further quick action would be the best solution.could you please how to achieve this lightning component or lightning with vf
    – Pavan tej
    Commented Apr 29, 2020 at 5:24
  • The lead convert lightning is a modal window and unlike classic, lightning is not page-centric to redirect to the std lead convert in lightning from a component. Found this idea you might want to upvote.
    – Shamina
    Commented Apr 30, 2020 at 4:53
0

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.

1
  • Please go through my question once.I've already setup error messages respectively My question how to route the component to standard lead convert page in lightning
    – Pavan tej
    Commented Apr 29, 2020 at 16:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .