• Kingslee Velu 5
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 0
    Replies
Write an apex method called (leadDuplicateCheck) that will validate if a collection of new leads would create duplicates in the system and returns segregated lists in a map
(True: list of non-duplicates & False: list of duplicates). A duplicate lead is defined as same Email, Territory__r.Region__c (text) and Company (text)
//Code Snippet to get you started


List<Lead> newleads = getNewLeads();
Map<Boolean, List<Lead>> leadResults = leadDuplicateCheck(newLeads)


Below code, snippet throws an error . Please advise how we can write code for the above scenario. Thanks.

Incorrect Code Snippet :
Public List<Lead> searchLeads(){
        List<Lead> searchLeads = [SELECT Email,Company, Status from Lead order by CreatedDate desc Limit 10];
        System.debug(searchLeads);
        return searchLeads;
    }

public Map<Boolean, List<Lead>> leadDuplicateCheck(newleadvalues){
        Map<Boolean, List<Lead>> nodup = new Map<Boolean, List<Lead>>();
        nodup.put(True, [SELECT Email,Company from Lead group by Email,Company having count(Id) > 1]);
        nodup.put(True, [SELECT Email,Company from Lead group by Email,Company having count(Id) = 1]);
        return nodup;
    }
Give an example of why you would use a trigger over a workflow or process builder to accomplish an update to a field?

Is there any pros/cons apart from below, Please share your thoughts.
  • If we need to perform an update on fields by validating the before/after validations of any other fields save to database then Triggers can be used instead of Workflow/Process Builder
  • Workflow/Process Builder cannot handle delete and undelete DML. Whereas Apex triggers can handle all DML operations.
  • Errors reported in Workflow/Process Builder is more generic which makes it difficult to find the origin of the error. With Apex triggers, exception handling can be made more specific.
  • It is all or none in case of Workflow/Process Builder failure. But with Apex triggers partial success is possible
I am getting below error after creating a data model through CSV for the above trailhead challenge. "Session" object is created through "Lightning Object Creator" but got below error. Checked the "Session" object and fields are already there. Not sure what I am missing.
Please share with me the details to resolve this error. Thanks.

Step not yet complete in My Trailhead Playground 2
We can't find the Date and Time fields on the Session object.