There are 2 objects Account(Parent) and Connect(Child) which lookup relationship. When I create an Account, we make a call out where we send the account records to third party application and in response they provide us Party Id and that external id is stamp to Account. So when I create account record, after saving it party id does not update immediately.I have to refresh the page 2 3 times to see the party id.
Now our requirement is whenever we create an account, Connect record should be created automatically and similar to Account, when Connect record is created, we make a call out to third party applications using POST and record gets created to their system and response they provide Party id but condition here is Connect Record gets created to third party applications only when their parent id which is Party Id of account exists in 3rd party applications.
So on After Insert of Account, we have a logic that creates Connect Record. But issue here is When account gets created, party is does not get stamped at the same time as it makes callout and wait for response from 3rd party app and at the same time Connect Record gets created in Salesforce with No party id because Party Id on Account is blank.
On existing Account where party id is present and if I create connect record manually then the child records gets created in 3rd party application because it gets Party Id of Respective Parent.
My concern here is how I control the sequence here? How system will understand while creation of account once party is gets stamped onto then create a child record so that child records gets created in 3rd party app once it gets an Party Is of Account.
Can someone please suggest better solutions to solve the problem?