Skuid records Insert limit

  • 1
  • Question
  • Updated 9 months ago
  • Answered
Hello Skuizards,

I need some design suggestions on how I can proceed with a requirement that I have without hitting any governor limits.

I have an object called Hold Data which contains records that were imported from an external system. I am building a skuid page which allows for users to search the hold data table for a billing code. The maximum number of records this search can return is 11,000. This is the easy part and I have been able to do this so far.

Now the next thing that the user needs to happen is click a button which would then create an account record for each record returned by the search - which means there can be upto 11,000 account records that will need to be inserted. Once the account records are created, the corresponding hold data record will need to be updated with a lookup to the newly created account record.

I initially thought I could do it through a javascript snippet, but considering the magnitude of records that might need to be touched, I fear I will hit the salesforce governor limits. The other thing that came to mind was calling a remote action that would do the insertion. But since I haven't done that before, I wanted to check if that was even possible.

If any of you can suggest any other possible solutions, that would be great as well.
Photo of Ashwat

Ashwat

  • 768 Points 500 badge 2x thumb

Posted 10 months ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Ashwat,

I think you should create an Invocable Batch class.  Skuid can call the invocable class using a data source action.  Pass it the SOQL from your model using merge syntax for example:  {{$Model.OpenTasks.soql}}.
Your batch class should be able to use the SOQL to fetch the same record set and create 1 account per row.  Using the Batch class will keep you out of trouble with any governor limits.
You can do this with a Remote Action, but you'll need a snippet to call the action.  Going with the Invocable class allows you to activate it declarativley in Skuid.

Thanks,
Bill
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Yup. Apex for sure!
Photo of Ashwat

Ashwat

  • 768 Points 500 badge 2x thumb
Thanks a lot Bill. I have never used the apex data source action before so I will surely give it a shot. How does the page respond if I am working in excess of 10000 records? Will it work if I just wrap the action between a block and unblock UI? Will skuid know once the invocable method has been completely executed and promptly unblock the UI? It would be perfect as long as the user is aware that something is happening in the background.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Whoever created the invocable method can add an input for an email address for notification of the process being completed. Working with so many records will take some time for sure. Likely greater then 5 minutes.
Photo of Ashwat

Ashwat

  • 768 Points 500 badge 2x thumb
Thank you Bill & Pat! I will try this approach and let you know how it goes.
Photo of Ashwat

Ashwat

  • 768 Points 500 badge 2x thumb
Hello again - An update on my progress so far with this. Since I was hitting governor limits with the invocable method, I decided to call a batch apex class that would contain all the logic from within theinvocable method.

It all seems to work fine but the problem that I have right now is that the UI unblocks as soon as the invocable method is run. Is there anyway I can freeze the UI until the batch apex class runs?
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Ashwat,

You can write a snippet that loads a model looking for the Job Name and unblocks after finding it.  If you don't really need to block the UI, maybe just popup a table that shows what batch jobs have been submitted.

Here is a model on AsyncApexJobs that shows the jobs queued/running.

Thanks,

Bill

        <model type="" id="BatchJobs" limit="5" query="false" createrowifnonefound="false" adapter="salesforce" sobject="AsyncApexJob" orderby="CreatedDate DESC">
            <fields>
                <field id="MethodName"/>
                <field id="JobItemsProcessed"/>
                <field id="ApexClassId"/>
                <field id="ApexClass.Name"/>
                <field id="CompletedDate"/>
                <field id="CreatedDate"/>
                <field id="NumberOfErrors"/>
                <field id="JobType"/>
                <field id="Status"/>
                <field id="ExtendedStatus"/>
                <field id="TotalJobItems"/>
                <field id="CreatedById"/>
                <field id="CreatedBy.Name"/>
                <field id="CreatedBy.Email"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="nameOfjob" enclosevalueinquotes="true" field="ApexClass.Name" operator="contains"/>
            </conditions>
            <actions/>

        </model>