1

My process -

I have a process in which I send data to outer system - and get a JSON to insert into Salesforce. This is handled by a scheduled class once a week.

The Received JSON: - (Could be ~7K Contact).

{
    "Contact": [{
        "Name": "emxampleName",
        "Email": "[email protected]",
        "Age": 123456789,
        "contact_External_Id":"123456",
        "Courses": [{
            "Name": 12354678,
            "Contact_Person": 2,
            "Exam_Date": 1234567
        }],
        "Scholarship": [{
            "Name": "U",
            "donor_Name": 1234,
            "Total_Sum": "5000"
        }]
    }]
}

For the Scholarship & Courses Objects (Also objects in salesforce which Contact is the parent) I should check if I need to insert or update the Data, base on a few keys For the Contact itself - only with one external field key - so I can use UPSERT.

I thought to Insert all the contacts first - without the Courses and Scholarship - and send to the batch all the Ids of the upserted contact.

After that, inside the batch - for each contact - I will seek the "contact_External_Id" and check if I will need to insert\update the Scholarship & Courses.

My questions -

  1. Until now I used Future method with callout to run the request and get the data - but since I need to push the data to a batch and run the query on the set of the contact Ids - I can't use this method anymore (Can't call Batch from future method). How can I achieve it?

  2. This process solution sounds a bit lame. If you guys have a better solution - It will be much appreciated.

Many Thanks!

1 Answer 1

3

It should be as simple as using a Queueable with Database.AllowsCallouts instead of using a future method. See the product documentation for details.

There are lots of alternatives you could consider in terms of the over-all approach, such as generating platform events with the JSON (as text) in them, but this approach does keep it clean and simple.

1
  • Thank You Phil :)
    – Salvation
    Oct 10, 2019 at 7:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .