I'm writing APEX REST API that creates OpportunityLineItem, Product2, Quote objects, updates Opportunity etc. based on data in JSON format received from external system.
During testing I experienced some performance glitches so decided to profile my code and isolate the problems.
I came to conclusion that simple DELETE statement which deletes previously associated Opportunity Line Items takes over 80% of execution time! It takes over 6 seconds to delete 200 rows.
There're no triggers attached to OppLineItem, no Flows, as testing is done in plain development environment.
Is this expected timing on Force.com platform to delete 200 rows? I'm coming from .NET/SQL projects so this looks very slow to me.
Here's my sample code:
public static void deleteOpportunityLineItems(String opportunityId, List<String> messages){
List<OpportunityLineItem> oppLineItems = [select ID from OpportunityLineItem where OpportunityId = :opportunityId];
if(!oppLineItems.isEmpty()){
delete oppLineItems;
messages.add('Line items successfully deleted.');
}
}
Also, here's the screenshot of Developer Console Log view:
Do you have any idea why this operation is performing so slow? Am I missing something?
Thank you!