• DJ Maheshwari
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 18
    Replies
Here is my code, but it won't work. Following are the cases and assume phone numbers are same.
Case 1:
Lead1(Existing Lead) -
Field1 - Null
Field2 - Value 2
Field3 - Null

Lead2(In TriggerList) - 
Field1 - Value1
Field2 - Null
Field3 - Value 3

Lead3(In Same TriggerList as Lead2) - 
Field1 - Value 5
Field2 - Value 6
Field3 - Null

When Lead is merge then Final Lead wil become:
Lead1 -
Field1 - Value 5
Field2 - Value 6
Field3 - Value 3

And Lead2 and Lead3 will delete.
public class MergeLead
{
    Integer i=0;
    Map<String, Schema.SObjectField> schemaFieldMap2 = Schema.SObjectType.Lead.fields.getMap();
    List<Lead> lstLeadToDelete = new List<Lead>();
    public static Boolean runOnce = true;
    public void onInsert(List<Lead> lstInsertLeadTrigger)
    {
        i++;
        System.debug('++++iiiiii'+i);
        if(runOnce)
        {
            InsertLead(lstInsertLeadTrigger);
        }
    }
    private void InsertLead(List<Lead> lstLeadInsert)
    {
        set<String> setPhone = new set<String>();
        Map<String,Lead> mapLead = new Map<String,Lead>();
        for(Lead objLd : lstLeadInsert)
        {
            if(!setPhone.contains(objLd.Phone))
            {
                setPhone.add(objLd.Phone);
            }            
        }
        Set<String> fieldNames = schemaFieldMap2.keySet();
        
        // Build a Dynamic Query String.
        String soqlQuery = ' SELECT ' + string.join (new List<String>(fieldNames), ',') + ' FROM Lead Where Phone =: setPhone';
        System.debug('+++++fieldNames+++++'+string.join (new List<String>(fieldNames),','));
        System.debug('++++setPhone++++'+setPhone);
        List<Lead> lstLeadToCheck = new List<Lead>();
        if(setPhone != null)
        {
            lstLeadToCheck = Database.query(soqlQuery);
        }
        System.debug('++++lstLeadToCheck++++'+ lstLeadToCheck);
        if(lstLeadToCheck.size()>0)
        {
            for(Lead objOldLead : lstLeadToCheck)
            {
                mapLead.put(objOldLead.Phone, objOldLead);
            }
        }
        System.debug('++++mapLead++++'+mapLead);
        for(Lead objLead : lstLeadInsert)
        {
            System.debug('++++mapLead.containsKey(objLead.Phone)++++'+mapLead.containsKey(objLead.Phone));
            if(mapLead.containsKey(objLead.Phone))
            {
                System.debug('+++mapLead.get(objLead.phone).id++++'+mapLead.get(objLead.phone).id);
                System.debug('++++objLead.id+++'+objLead.id);
                if(mapLead.get(objLead.phone).id != objLead.id)
                    lstLeadToDelete.add(objLead); 
                for(String strFields : schemaFieldMap2.keySet())
                {
                    if(mapLead.get(objLead.phone).get(strFields) == null && objLead.get(strFields) != null)
                    {
                        mapLead.get(objLead.phone).put(strFields,objLead.get(strFields));
                    }
                }
                System.debug('++++mapLead++++'+mapLead);
            }
        }
        if(mapLead.size()>0)
        {
            System.debug('+++++mapLead++++'+mapLead);
            update mapLead.values();
        }
        System.debug('++++lstLeadToDelete+++'+lstLeadToDelete);
        if(lstLeadToDelete.size()>0)
        {
            delete lstLeadToDelete;    
        }
        System.debug('++++lstLeadToDelete+++'+lstLeadToDelete);
    }  
}
I created Three Custom Objects.
1. Custom Product
2. Custom Asset
3 Work Order
On all the objects there is custom field, named Description.
And Custon Product have self Lookup. Custom Asset is a child of Custom Product(Lookup relationship). Work Order is Child of Custom asset(lookup relationship).
If I insert Work Order and Select the Asset record then the value of Description is populate while insert if the selected asset record description field is empty then it populates the value of description of custom product of selected asset and if that is also empty then it populates the value of self parent of custom product of selected asset. 
I created Three Custom Objects.
1. Custom Product
2. Custom Asset
3 Work Order
On all the objects there is custom field, named Description.
And Custon Product have self Lookup. Custom Asset is a child of Custom Product(Lookup relationship). Work Order is Child of Custom asset(lookup relationship).
If I insert Work Order and Select the Asset record then the value of Description is populate while insert if the selected asset record description field is empty then it populates the value of description of custom product of selected asset and if that is also empty then it populates the value of self parent of custom product of selected asset. 
I'm stuck on step #2 of Einstein Analytics and Discovery Insights Specialist superbadge.  I'm getting this warning while checking the challenge:
Challenge #2 Not complete
The step "Churn Tenure' is in compact form, so the filter values need to be specifed as a minimum and maximum
The static step that feeds has the following the value:
 
"Tenure_Length": {
                "broadcastFacet": false,
                "label": "Tenure Length",
                "selectMode": "single",
                "type": "staticflex",
                "values": [
                    {
                        "display": "High Risk",
                        "value": "1 to 12 months",
                        "min": 1,
                        "max": 12
                    },
                    ...
                ]
            }


I'm using selection binding for min and max values.  The dashboard is correctly filtering:
User-added image
User-added image
Any ideas? 
I've tried a non-compact form step where I inject a saql fragment into the query, as well as where I inject min/max values using a range filter serialization...All these efforts end in the same challenge failure message.

Any help/suggesitions are welcome!