0

I have 2 Orgs let's call them A & B. I have a process that queries org A and transfers data into Org B. For simplicity, let's say

OrgA.Id
OrgA.ManagerID

After my upsert I end up with a record in Org B that looks like

OrgB.Id
OrgB.Manager_r
OrgA__c.Id
OrgA__c.ManagerID

Sorry if thats not clear but basically a Contact in Org B has a lookup relationship to Contact object called Manager.

My problem is that lets say this is the first time the process runs. If I were to write a trigger say to update the managerID for a contact

select Id from Contact where OrgA.ID = :ManagerID

where ManagerID is the managerID for the Contact record that fired the trigger.

That Manager contact record may not exist yet until the entire trigger has run.

Now maybe the second time I run it, the manager ID would exist.

How could I wait until all records were created to then run a trigger?

Is a trigger even the right solution? Should this be a process builder process?

I am kind of learning as I go here, any advice would be awesome.

Thanks

  • Are you using Batch Apex to transfer records from Org A to Org B? If so, please post your code. You might be able to leverage the "finish" method for the data cleanup. – John Thompson Mar 11 at 19:57
  • I am using Mulesoft to transfer the records from OrgA to OrgB – Jeremy Ragsdale Mar 11 at 19:58
0

I don't think a trigger is the right solution for this situation, since triggers are effectively invoked after each record is created or updated.

Consider writing a [Batch Apex job][1] instead. These jobs are also written in apex but they can be invoked manually (via the developer console) or they could even be scheduled to run once per day at a particular time.

0

It is difficult to understand your problem from the description you provided. For example, do the normal contacts and manager contacts live on both Org A and Org B? Is it that you are simply syncing data from Org A to Org B? Is it a bi-directional sync?

Either way, if you are doing the sync via MuleSoft, take a look see if their API allows you to add a "hook" invoked when sync has completed (I have no knowledge of their offering here).

If not, it is unclear how else to proceed with the level of detail you have provided and you should update your question accordingly.

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.