function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Does anyone see a problem with this code?

Hi, am working on a pretty simple code that restricts the Lead duplication.Leads are coming in from web pages, parameters are extracted and checked below if its a duplicate:




// 1. Leads coming in get the parameters extracted.  
// 2. Now checking for duplication based on Record type and Email

List <RecordType> R = [SELECT Id from RecordType WHERE SObjectType =: 'Account' AND Name =: r_name]; if(R.size()>0){ LIST <Account>ifdup = [SELECT Id, OwnerId from Account WHERE PersonEmail =: r_email AND RecrodTypeId =: R[0].Id]; if (ifdup.size()>0){ Task tsk = new Task(); tsk.WhoId = ifdup[0].Id; tsk.OwnerId = ifdup[0].OwnerId; tsk.Status = 'Open'; tsk.Priority = 'High'; insert tsk;
duplicateLead = true; exceptionThrown = true; PageReference p = new PageReference(this.fail_page); p.setRedirect(true); return p; }

// 3. Since not a dupliate, account creation.


In case of duplicate lead, code shall return Failure along with task creation for the existing lead owner. But somehow its not working this way, Leads are getting duplicated. My understanding is when the If condition returns the page P, its the end of the code execution.



Can someone help me fix it please? Thanks