Last active
January 12, 2023 09:35
-
-
Save SalesforceBobLightning/59b032fa832e3156c4be11801b65e549 to your computer and use it in GitHub Desktop.
SOQL Query for finding Duplicate Person Account by Email Address
This file contains hidden or 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
| List<AggregateResult> results = [SELECT Count(ID), PersonEmail | |
| FROM Account | |
| WHERE IsPersonAccount = TRUE | |
| GROUP BY PersonEmail | |
| HAVING Count(ID) > 1 | |
| ORDER BY Count(ID) DESC | |
| LIMIT 2000]; | |
| String report = 'count,PersonEmail\n'; | |
| for(AggregateResult r : results) { | |
| report += r.get('numOf'); | |
| report += ','; | |
| report += r.get('PersonEmail'); | |
| report += ','; | |
| report +='\n'; | |
| } | |
| ContentVersion contentVersion = new ContentVersion( | |
| versionData = Blob.valueOf(report), | |
| title = 'Duplicate Person Accounts Report', | |
| pathOnClient = StringUtils.format('/Duplicate-Person-Accounts-Report-{0}.csv', DateTime.now().getTime()), | |
| FirstPublishLocationId = UserInfo.getUserId()); | |
| insert contentVersion; |
This file contains hidden or 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
| SELECT Count(ID), PersonEmail | |
| FROM Account | |
| WHERE IsPersonAccount = TRUE | |
| GROUP BY PersonEmail | |
| HAVING Count(ID) > 1 | |
| ORDER BY Count(ID) DESC | |
| LIMIT 2000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment