0

Here is my question: Org's personal account is enabled. The account sharing setting is set to private, sales team members Sales A and Sales B can not access each others' account records. Sales A and Sales B create accounts separately. The requirement is when Sales A is creating a new account, if that account has been created and owned by A, then update the old one with the new one's fields, if that account has been created and owned by B, then update the record with the new one' fields and share that record with A. Records are matched by email address and phone number. I understand I might have to write a trigger for this. But have no clue how to start it. I hope someone can give me some suggestions. Much appreciated.

closed as too broad by Martin Lezer, Vijay Ganji, glls, battery.cord, Pranay Jaiswal Aug 11 at 20:10

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

You cannot do that in a trigger. There's no way to "convert" a DML operation, such as an insert, into another, like an update. Deleting the new Account behind the user's back would produce a very confusing user experience.

Instead, you'd need to build custom UI in Visualforce or Lightning to override the New Account action. Your automation would accept specific parameters to create a new Account, including the phone and email address, and perform a deduplication check before attempting to create the record. Your custom code may then perform any required actions, communicate to the user, and navigate them appropriately. Note that you'll have to run queries in a class declared without sharing; otherwise it won't be able to see the records that are not available to the running user.

This is an expensive, complex solution to duplicate management that will impose ongoing maintenance costs on your organization as your data entry needs evolve. Consider instead discarding some of the complexity of this requirement to allow you to utilize free, out-of-the-box Duplicate Management instead.

Not the answer you're looking for? Browse other questions tagged or ask your own question.