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.
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.