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'));
        action.setParams({ 'contactstr' : strData});
            if (response.getState() === "SUCCESS") {
                var res = response.getReturnValue();
                    if(res[0].Integrated_lead__c == True && res[1].Integrated_lead__c == True){
                        toastEvt('Selected Leads are integrated Leads and cannot be merged');
                }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');
                    toastEvt('Please select a record to proceed.');
        function toastEvt(msg){
            var toastEvent = $A.get("e.force:showToast");
                "title": "Error!",
                "message": msg
        function redirecttoMerge(conId1, conId2){
            var evt = $A.get("e.force:navigateToComponent");
                componentDef : "c:Merge_leads_component",
                componentAttributes: { id1 : conId1,id2 : conId2 }

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.


1 Answer 1


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');
  • 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 .