You need to sign in to do that
Don't have an account?

Apex trigger to check if alternate phone number matches with Mobile number of any of the accounts in Salesforce?
Hi,
I am having a massive confusion,
We have a database of 400,000 records.. which calls for duplication.
I want to check if alternate phone number of any of the account matches with the Primary phone number of any of the account, If it does, there is a checkbox called "Marked For deletion" m that checkbox should get selected and primary phone number of that account should become the alternate phone number of the acount against which it has matched
So lets say ,
Accoount : A Primary No : 1234 Secondary No : 5678
Accoount : B Primary No : 9241 Secondary No : 1234
Accoount : C Primary No : 9241 Secondary No : 1234
Account B and Account C should have marked for deletion checked.
and Account B's primary phone number should become Secondary phone number of Account A.
Please help me in achieving this
I am having a massive confusion,
We have a database of 400,000 records.. which calls for duplication.
I want to check if alternate phone number of any of the account matches with the Primary phone number of any of the account, If it does, there is a checkbox called "Marked For deletion" m that checkbox should get selected and primary phone number of that account should become the alternate phone number of the acount against which it has matched
So lets say ,
Accoount : A Primary No : 1234 Secondary No : 5678
Accoount : B Primary No : 9241 Secondary No : 1234
Accoount : C Primary No : 9241 Secondary No : 1234
Account B and Account C should have marked for deletion checked.
and Account B's primary phone number should become Secondary phone number of Account A.
Please help me in achieving this
Please use the below Batch for your solution. Please try first in staging or dev org before running into Prod
Batch
Test Class
All Answers
1. Seems like you've got a one-time cleanup effort on all 400K accounts, which I would tackle with an export of the data into Excel, then sort and update data, and load back to SF.
2. Going forward it would be best to block the creation of the duplicate accounts before they occur. It seems you could accomplish this in an Account trigger before insert. In the trigger you'll want to query Accounts where Primary Number is equal to the Secondary Number of the Account being created. If the query comes back with a result you can take that Account ID that was found and put it into an Error message, then throw that error message on the top of the page for the user to see.
3. If the account is coming through integration or in way that doesn't allow you to block creation, then you could allow the trigger to go and update the Account it found (assuming it only found one). That makes me a bit nervous. If my secondary number matches your primary number then you loose your secondary number to my primary number.
Good luck!
Validation rule is Ok, but we want to enter records in system right , and validation rule only match for the same record, I wnt it for other records
If you want to check all duplicate record on your org.Write a batch class and run it for once .That solve your problem of duplicate save accounts. Then make a trigger on insert and update so in future when a new account create/update its check for the secoundry number is not present in your save record primary No.
One more thing
Work it like that it help you a lot.
Accoount : A Primary No : 1234 Secondary No : 5678
Accoount : B Primary No : 9241 Secondary No : 1234
Accoount : C Primary No : 9241 Secondary No : 1234
New Value
Accoount : A Primary No : 1234 Secondary No : 5678 ,9241
That way you don't lose any data.
Hope that solve your problem.
Please use the below Batch for your solution. Please try first in staging or dev org before running into Prod
Batch
Test Class
Updated Test Class
Let me know if all that helped
Please mark it best if helped.