I want to populate AccountTeamMember names related to particular account on account object field. As Trigger is not allowed on AccountTeam or AccountTeamMember i think of writing a batch class to update the account field but problem is:

1) Suppose a accountteammember is added and during batch class run its name gets updated on account object field, now after some time it gets deleted. now on deletion i want to remove accountteammember name from account object field in which earlier i captured the value but in soql query id didnt get the deleted accountteammember inspite of using ALL ROWS keyword.

What is the best method to handle situation like i can have the names of all accountteammemebers on account level which are associated to that account.

  • I've known a number of companies recreate the object using their own custom object... – Girbot Dec 12 '15 at 9:45
  • @Girbot What else is the solution? – Pankaj Dec 12 '15 at 9:50
  • As it's a custom object triggers are available, so you can add your logic there. – Girbot Dec 12 '15 at 14:53

One way of handling this if doing it via a batch class using a query is to run your query to determine who should be there and also query to discover who currently is there. Compare the results of the two queries by account (run them as a single query if you wish, I'm just distinguishing between the two results here). If someone is not on the list of who should be there, they get deleted from the list of who is there.

Batch class methods would seem pretty straightforward for what you describe. You can even chain another "clean-up" batch class that runs afterward to check for any records that were modified while the initial class was running. Dan Appleman discusses some of these patterns in book Advanced Apex Programming Ver 3.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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