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
Ben Kingsley 8Ben Kingsley 8 

Duplicate Detection

I need help on adding some code so it looks for the first letter of the first name and not the full first name.  Below is my code.  Any help would be appreciated. 

 IF(RecordTypeName=='BCIS - Consumer' || RecordTypeName =='Consumer'|| RecordTypeName == 'Wealth'){        
            BCISDupProspectList = [SELECT Id, Name, OwnerID,Primary_Phone__c,Secondary_Phone__c,email__c,Owner.Name,Owner.Email FROM Prospect__c WHERE first_name__c = :Prospect.First_Name__c AND
                               Last_Name__c = :Prospect.Last_Name__c and  RecordType.Name <> 'BCIS - Consumer Prospect'
                        AND ((Email__c = :Prospect.Email__c and Email__c <> null) OR 
                                                 (Primary_Phone__c = :Prospect.Primary_Phone__c and Primary_Phone__c <> null) OR 
                                                 (Secondary_Phone__c = :Prospect.Secondary_Phone__c and Secondary_Phone__c <> null))];
Best Answer chosen by Ben Kingsley 8
CloudGeekCloudGeek
Hello Ben,

I wish this sample could be any help for your requirement:
 
Lead listOfLeads = [SELECT Id,FirstName,LastName FROM LEAD WHERE Id='00Q19000002ENn6'];

String firstChar = listOfLeads.FirstName.substring(0,1);  //Get First Character from FirstName

System.debug('firstChar = '+firstChar);

List<Lead> result = [SELECT Id,FirstName,LastName FROM LEAD WHERE LastName = 'K' AND FirstName LIKE:firstChar+'%' LIMIT 5 ];

System.debug('res = '+result);

So your Code will be like below after modifying :
 
String firstChar = Prospect.First_Name__c.substring(0,1);  //Get First Character from FirstName

System.debug('firstChar = '+firstChar);


IF(RecordTypeName=='BCIS - Consumer' || RecordTypeName =='Consumer'|| RecordTypeName == 'Wealth'){        
            BCISDupProspectList = [SELECT Id, Name, OwnerID,Primary_Phone__c,Secondary_Phone__c,email__c,Owner.Name,Owner.Email FROM Prospect__c 
            
            WHERE first_name__c LIKE:firstChar+'%'  
            
            AND
                Last_Name__c = :Prospect.Last_Name__c and  RecordType.Name <> 'BCIS - Consumer Prospect'
            
            AND ((Email__c = :Prospect.Email__c and Email__c <> null) OR 
                                                 (Primary_Phone__c = :Prospect.Primary_Phone__c and Primary_Phone__c <> null) OR 
                                                 (Secondary_Phone__c = :Prospect.Secondary_Phone__c and Secondary_Phone__c <> null))];


Note: Mark it as Solution if it helps.

 

All Answers

CloudGeekCloudGeek
Hello Ben,

I wish this sample could be any help for your requirement:
 
Lead listOfLeads = [SELECT Id,FirstName,LastName FROM LEAD WHERE Id='00Q19000002ENn6'];

String firstChar = listOfLeads.FirstName.substring(0,1);  //Get First Character from FirstName

System.debug('firstChar = '+firstChar);

List<Lead> result = [SELECT Id,FirstName,LastName FROM LEAD WHERE LastName = 'K' AND FirstName LIKE:firstChar+'%' LIMIT 5 ];

System.debug('res = '+result);

So your Code will be like below after modifying :
 
String firstChar = Prospect.First_Name__c.substring(0,1);  //Get First Character from FirstName

System.debug('firstChar = '+firstChar);


IF(RecordTypeName=='BCIS - Consumer' || RecordTypeName =='Consumer'|| RecordTypeName == 'Wealth'){        
            BCISDupProspectList = [SELECT Id, Name, OwnerID,Primary_Phone__c,Secondary_Phone__c,email__c,Owner.Name,Owner.Email FROM Prospect__c 
            
            WHERE first_name__c LIKE:firstChar+'%'  
            
            AND
                Last_Name__c = :Prospect.Last_Name__c and  RecordType.Name <> 'BCIS - Consumer Prospect'
            
            AND ((Email__c = :Prospect.Email__c and Email__c <> null) OR 
                                                 (Primary_Phone__c = :Prospect.Primary_Phone__c and Primary_Phone__c <> null) OR 
                                                 (Secondary_Phone__c = :Prospect.Secondary_Phone__c and Secondary_Phone__c <> null))];


Note: Mark it as Solution if it helps.

 
This was selected as the best answer
Ben Kingsley 8Ben Kingsley 8
Thanks for your help.  Much appreciated.