function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
askmikemaskmikem 

Why are SOQL statements included in CPU time

We are seeing an error in one of our classes where we are exceeding CPU time.  Added some debug statements to the code has determined that a large SOQL statement is to blame.   Any ideas to avoid this?  I was unde the impression that SOQL statements are excluded from the CPU time calculation.

I have included the pertinent section of the log, in case you don't believe me ;)

12:43:48.0 (239206415)|USER_DEBUG|[379]|INFO|mikem4b.Amount of CPU Time: 177
12:43:48.0 (243726579)|SOQL_EXECUTE_BEGIN|[381]|Aggregations:0|SELECT Id,IsDeleted,LineNumber,CurrencyIsoCode,CreatedDate,CreatedById,LastModifiedDate,LastModifiedById,SystemModstamp,QuoteId,PricebookEntryId,Quantity,UnitPrice,Discount,Description,ServiceDate,Product2Id,SortOrder,ListPrice,Subtotal,TotalPrice,BT_Account_Name__c,BT_Contact__c,BT_Address_Usage__c,BT_Contact_First_Name__c,BT_Contact_Last_Name__c,BT_Sales_Channel__c,BT_Country_of_revenue__c,BT_Oracle_customer__c,BT_Bill_to_account_site_ID__c,BT_Address__c,BT_City__c,BT_State__c,BT_Postal_Code__c,BT_Country__c,ST_Account_Name__c,EU_Account_Name__c,Opportunity_Account__c,ST_Address__c,EU_Address__c,ST_Address_Usage__c,EU_Address_Usage__c,ST_Ship_to_account_site_ID__c,FPX_ListPrice__c,EU_End_User_account_site_ID__c,ST_City__c,EU_City__c,ST_Contact__c,EU_Contact__c,ST_Country__c,EU_Country__c,ST_Country_of_revenue__c,EU_Country_of_revenue__c,ST_Oracle_customer__c,EU_Oracle_customer__c,ST_Postal_Code__c,EU_Postal_Code__c,ST_State__c,EU_State__c,ST_Contact_Role__c,BT_Contact_Role__c,EU_Contact_Role__c,Select_Bill_To_Contact__c,Select_Ship_To_Contact__c,Select_Installed_At_Contact__c,Delivery_Instructions_DI__c,Delivery_Contact__c,Primary_Quote_Flag__c,Quote__c,Revision__c,Quote_Name__c,Status__c,Order__c,Order_Status__c,Price_List__c,Active__c,PO_Received__c,PO_Received_By__c,PO_Received_Date__c,Currency__c,Quote_Expiry_Date__c,Comments__c,Requested_Delivery_Date__c,Oracle_Order__c,Install_At_Country__c,CERTS_Sub_Status__c,Total_Gross_Revenue__c,Cost_Center__c,Sent_To_NetSuite__c,Internal_Comments__c,Last_Export_Date__c,Organization__c,Type__c,Select_Bill_To_Address_Usage__c,Action__c,Mode__c,Config_Complete__c,Ext_Qty__c,Asset_S_N__c,Base_S_N__c,Product_List_Price__c,Std_Buy_price__c,Product_Sub_Category__c,Net_Revenue__c,Cost__c,Marketing_Category__c,Gross_Margin__c,Gross_Margin_Percentage__c,Program_Discount_Value__c,Manual_Discount_Percentage__c,Deferred_Maint_Rev__c,Renewal_MMC__c,Current_Model_Version__c,Configured_Model_Version__c,Post_Program_Price__c,Product_Measure__c,Doc_Config__c,WCA_Amount__c,Line_Discount_Percentage__c,Item_Unit__c,Bundle_ID__c,Bundle_Description__c,Bundle_Modified__c,Bundle_Name__c,Solution_Selector__c,Expert_Mode__c,Base_Asset_Serial__c,Install_At_Address_Id__c,Install_At_Address_Name__c,Ship_To_Address_Id__c,Ship_To_Address_Name__c,Standard_Buy_Price__c,License_Type__c,MPD_Flag__c,MPD_Counter__c,Elapsed_Term__c,Product_Sub_Type__c,MPD_Adjustment__c,NS_Adjustment__c,Product_Term__c,Product_Type__c,Manual_Price_Override__c,Quote_SPT_Level__c,Quote_Upgrade_SPT_Level__c,Oracle_GL_Code__c,Unit_Cost__c,Covered_Product__c,Unit_Price_MMC__c,Unit_Net_MMC__c,NS_Flag__c,Product_Life_Cycle_Status__c,Unit_Product_List_Price__c,M_Code__c,Renewal_MMC_Override__c,M_Code_Description__c,ParentQuoteId__c,ParentQuoteLineId__c,IsSelected__c,ExtendedDescription__c,Key__c,BaseSellingPrice__c,UnitSellingPrice__c,TotalOptionsSellingPrice__c,TotalBaseSellingPrice__c,NestedProductsSellingPrice__c,OptionsSellingPrice__c,OptionsListPrice__c,OptionsCost__c,OptionsProfit__c,OptionsMargin__c,TotalCost__c,TotalProfit__c,TotalMargin__c,IncludeInExport__c,Sequence__c,OptionId__c,OptionType__c,ValueType__c,ValueString__c,ValueDate__c,ValueDouble__c,ValueColor__c,Extended_List_Price__c,Total_Post_Program_Discount__c,Standard_Discount__c,Standard_Discount_Value__c,List_Monthly_Maintenance_Charge__c,Quote_Monthly_Maintenance_Charge__c,Contractual_Rev_Rec_Trigger__c,Oracle_Site_Number_for_BillTo__c,Oracle_Site_Number_for_Install__c,Oracle_Site_Number_for_ShipTo__c,Parent_LIC__c,IA_Account_Name__c,IA_Contact__c,IA_Contact_Role__c,IA_Country_of_revenue__c,IA_Oracle_customer__c,IA_Oracle_Site_Number_for_Install__c,IA_End_User_account_site_ID__c,IA_Address_Usage__c,IA_Address__c,IA_City__c,IA_State__c,IA_Postal_Code__c,IA_Country__c,IA_Select_Installed_At_Contact__c,Marketing_Name__c,Pricing_Comments__c,Freight_Terms__c,Solution_Line_Item__c,Warranty_Cost_Accrual__c,Product_Level__c,Cost_Adjustments__c,Revenue_Adjustments__c,Warranty_Cost__c,Unit_of_Measurement__c,CPQ_Line_Number__c,Order_Code__c,Adjust_Lock__c,CPQ_Line_Id__c,S_Level_Line_Item__c,Product_Cost__c,IP_Flag__c,IPSN__c,Email__c,Shipment_Note__c,HW_Gross_Revenue__c,SW_Gross_Revenue__c,HW_Def_Maint_Revenue__c,SW_Def_Maint_Revenue__c,Install_Revenue__c,GSS_Revenue__c,Total_Products_Cost__c,Revenue_Adjustment_Value__c,Cost_Adjustment_Value__c,HW_Term__c,HW_MMC__c,SW_Term__c,SW_MMC__c,Third_Party_HW_Term__c,Third_Party_HW_MMC__c,Third_Party_SW_Term__c,Third_Party_SW_MMC__c,Gross_Revenue__c,SVC_Support_List_Price__c,Pricing_Category__c,Product_Category__c,VSOE_Discount__c,Hidden_Line_Number__c,Unit_List_MMC__c,Unit_Std_Buy_Price__c,Unit_List_Price__c,Select_Ship_To_Address_Usage__c,Select_End_User_Address_Usage__c,Solution_Level_Order_Code__c,S_Level_Order_Code__c,Product_Sequence__c,VSOE_Flag__c,ST_Contact_Email__c,BT_Address_Usage_Site__c,ST_Address_Usage_Site__c,Ref_QuoteLineItem__c,CPQ_Parent_Line_Id__c,Service_Sub_Type__c,Standard_Cost__c,Quote_Id__c,LIC_EXP__c,ELA_Cost__c,ELA_Revenue__c,Covered_Product_Quoteline_Id__c,ENC_R_count__c,CPQ_Parent_Quote_Id__c,BT_LocationNo__c,ST_LocationNo__c,EU_LocationNo__c,CPQ_Root_Line_Id__c,Total_PII__c,Renewal_MMC_List__c,Covered_Product_Quantity__c,Covered_Product_Sequence__c,MPD_Amount__c,Unit_PII__c,Post_Program_Discount_Amt__c,Unit_WCA_Amount__c,WCA_Flag__c,WCA_Term__c,Ref_Quote_Line_Item_Root__c,E_U_Address_Variation1__c,S_T_Address_Variation1__c,Quote_Line_Item_Reporting_Count__c,ECCN__c,Unit_Gross_Revenue__c,Total_Covered_Product_Qty__c,Product_life_Cycle_Status_Test__c,Line_No_Sort__c,Unit_Start_Price__c,S_Product_Family__c,Unit_Post_Program_Price__c,Service_Level__c,Opp_Acct_Formula__c,Pricebook_ID__c,Product_Life_Cycle_Test__c,Gross_Revenue_PCU__c,Net_Revenue_PCU__c,Gross_Margin_PCU__c FROM QuoteLineItem WHERE QuoteId = '0Q055000000ADSOCA4'
12:43:55.115 (7115185345)|SOQL_EXECUTE_END|[381]|Rows:1767
12:43:55.115 (7193873495)|USER_DEBUG|[384]|INFO|mikem1a.Number of Queries: 2
12:43:55.115 (7193919303)|USER_DEBUG|[385]|INFO|mikem2a.Number of rows: 1815
12:43:55.115 (7193967779)|USER_DEBUG|[386]|INFO|mikem3a.Number of script statements: 0
12:43:55.115 (7194014499)|USER_DEBUG|[387]|INFO|mikem4a.Amount of CPU Time: 5352
 
Amit Chaudhary 8Amit Chaudhary 8
CPU time is calculated for all executions on the Salesforce application servers occurring in one Apex transaction. CPU time is calculated for the executing Apex code, and for any processes that are called from this code, such as package code and workflows. CPU time is private for a transaction and is isolated from other transactions. Operations that don’t consume application server CPU time aren’t counted toward CPU time. For example, the portion of execution time spent in the database for DML, SOQL, and SOSL isn’t counted, nor is waiting time for Apex callouts.

Please check below post for same issue
1) https://help.salesforce.com/articleView?id=000232681&language=en_US&type=1
2) http://salesforce.stackexchange.com/questions/18244/how-does-sf-calculate-the-cpu-time
3) https://developer.salesforce.com/blogs/engineering/2013/09/script-limits-begone.html

There is no specific setting that will increase CPU time for bulk api.
What is happening is that when you schedule data load through bulk it put system under stress and it is not able to finish the given task in appropriate time and so throws error Apex CPU time limit exceeded.
To avoid CPU limit you need to optimize your code. Here are few tips:
1) Check the trigger execution and note the required time.
2) With the help of developer console you can figure out where cup time is spent and then target the area which most CUP costly.
3) try and optimize those costly code blocks
4) Note for optimization of trigger you can use anomalous block to fire trigger
here is link that show how to use developer console for code optimization 

Please check below best practice to avoid this
1) https://developer.salesforce.com/page/Apex_Code_Best_Practices

Let us know if this will help you