Last active
May 5, 2018 10:43
-
-
Save veeranjik/d157e31c0a3e438ddb63dc6311ae55c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Purpose: Check the Duplicate Records with custom Address Fields on Custom Object. | |
* Created By: Veera k | |
* Last Modified By: | |
* Current Version: v1.0 | |
* Revision Log: | |
* v1.1 - | |
* v1.0 - | |
*/ | |
public class AddressCheck{ | |
public Static List<CustomObject__c> Comparision(String street,String city,String region,String country,String postalCode) { | |
String queryString='Select ID,name,Street__c,City__c,Region__c,Country__c,Postal_Code__c from CustomObject__c '; | |
List<CustomObject__c> duplicateAddress; | |
List<String> myFilter = new List<String>(); | |
//Check Street is Blank or Not | |
if(!String.isBlank(street)) | |
myFilter.add('Street__c LIKE \'%' + street + '%\' '); | |
//Check City is Blank or Not | |
if(!String.isBlank(city)) | |
myFilter.add('City__c LIKE \'%' + city + '%\' '); | |
//Check Region is Blank or Not | |
if(!String.isBlank(region)) | |
myFilter.add('Region__c LIKE \'%' + region + '%\' '); | |
//Check Country is Blank or Not | |
if(!String.isBlank(country)) | |
myFilter.add('Country__c LIKE \'%' + country + '%\' '); | |
//Check Postal code is Blank or Not | |
if(!String.isBlank(postalCode)) | |
myFilter.add('Postal_Code__c LIKE \'%' + postalCode + '%\' '); | |
if(myFilter.size()>0){ | |
queryString += ' WHERE ' + myFilter[0]; | |
for (Integer i = 1; i < myFilter.size(); i++) | |
queryString += 'AND ' + myFilter[i]; | |
} | |
queryString += 'ORDER BY createdDate ASC'; | |
duplicateAddress = database.query(queryString ); | |
return duplicateAddress; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment