0

I have a requirement to merge custom leads. When two leads are selected to merge and if their Integrated_Lead__c (datatype - checkbox) is true, then an error message should be displayed on screen.

Below is the component .js code:

processrecSelected: function(component, event, helper) {
        var action = component.get('c.processSelected');
        var strData = JSON.stringify(component.get('v.contactList'));
        console.log('strData===>'+strData);
        action.setParams({ 'contactstr' : strData});
        action.setCallback(this,function(response){
            
            if (response.getState() === "SUCCESS") {
                var res = response.getReturnValue();
                console.log('res===>'+res.length);
                
                if(res.length==2){
                    if(res[0].Integrated_lead__c == True && res[1].Integrated_lead__c == True){
                        toastEvt('Selected Leads are integrated Leads and cannot be merged');
                    }
                    else{
                    redirecttoMerge(res[0].Id,res[1].Id);
                    }
                }else if(res.length>2){
                    toastEvt('Please select at most two records to proceed');
                }else if(res.length==1){
                    console.log('an error occured==>'+ res[0].Integrated_Lead__c);
                    toastEvt('Please select at most two records to proceed');
                }else{
                    toastEvt('Please select a record to proceed.');
                }
            }
        })
        $A.enqueueAction(action);
        function toastEvt(msg){
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                "title": "Error!",
                "type":"Error",
                "message": msg
            });
            toastEvent.fire();
        }
        function redirecttoMerge(conId1, conId2){
           
             
            var evt = $A.get("e.force:navigateToComponent");
            evt.setParams({
                componentDef : "c:Merge_leads_component",
                componentAttributes: { id1 : conId1,id2 : conId2 }
                
            });
            
            evt.fire();
        }
    }

I am using res[0].Integrated_lead__c == True && res[1].Integrated_lead__c == True condition to fire the error message but even then, I could able to see the error on screen. Can anyone please suggest the changes so that I can get this done.

Thanks!

1 Answer 1

0

You are in controller function which is in Javascript and Javascript is Case-Sensitive.

You are using True, which is not present in javascript.

Try updating this block -

First way

if(res[0].Integrated_lead__c && res[1].Integrated_lead__c ){
    toastEvt('Selected Leads are integrated Leads and cannot be merged');
} 

Second way

if(res[0].Integrated_lead__c === true && res[1].Integrated_lead__c === true){
    toastEvt('Selected Leads are integrated Leads and cannot be merged');
} 
5
  • I tried your given suggestion and when I used the first way, instead of throwing error, the page moved to next step and when I used the second way, I am not seeing any error but the page didnt proceed to next step. To keep it short, both the ways didnt fire the error message. Please suggest
    – SK_112
    Aug 3, 2020 at 8:47
  • i figured it out, when using both res[0] and res[1] with &&, the error isnt firing. but when I use them individually, i could able to see the error. Is there anything wrong with the logic here?
    – SK_112
    Aug 3, 2020 at 11:56
  • may be you can have || part then.
    – Ysr Shk
    Aug 3, 2020 at 12:02
  • but i want both to be checked and the error should be displayed only when both are true. That wont be happening with || isnt it?
    – SK_112
    Aug 3, 2020 at 12:04
  • if both individualy is having true then it should come to the block. May be you check the flow by having console.logs.
    – Ysr Shk
    Aug 3, 2020 at 12:12

You must log in to answer this question.

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