I am attaching debug log which is showing CPU is all most hit limit.
Number of SOQL queries: 2 out of 100
Number of query rows: 5619 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 3 out of 150
Number of DML rows: 47 out of 10000
Maximum CPU time: 9433 out of 10000 ******* CLOSE TO LIMIT
Maximum heap size: 0 out of 6000000
here is main parts of debug log
35.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
07:39:13.0 (67000)|USER_INFO|[EXTERNAL]|00516000006pG2P|[email protected]|Pacific Standard Time|GMT-07:00
07:39:13.0 (96969)|EXECUTION_STARTED
07:39:13.0 (101392)|CODE_UNIT_STARTED|[EXTERNAL]|06616000002epo1|VF: /apex/CreatingAndMaintaingQuestions
07:39:13.0 (23821501)|METHOD_ENTRY|[8]|01p16000004wQcq|CreatingAndMaintaingQuestionsCtrl.CreatingAndMaintaingQuestionsCtrl()
07:39:13.0 (23888624)|METHOD_EXIT|[8]|CreatingAndMaintaingQuestionsCtrl
07:39:13.0 (53865203)|DML_BEGIN|[317]|Op:Update|Type:Requisition__c|Rows:1
07:39:13.0 (78045441)|CODE_UNIT_STARTED|[EXTERNAL]|Validation:Requisition:a0P1600000BwPBy
07:39:13.0 (79220306)|CODE_UNIT_FINISHED|Validation:Requisition:a0P1600000BwPBy
07:39:13.0 (109513715)|CODE_UNIT_STARTED|[EXTERNAL]|01q16000001MACT|RequisitionTrigger on Requisition trigger event AfterUpdate for [a0P1600000BwPBy]
07:39:13.0 (153755280)|CODE_UNIT_FINISHED|RequisitionTrigger on Requisition trigger event AfterUpdate for [a0P1600000BwPBy]
07:39:13.0 (154314997)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:01I16000002cLv0
07:39:13.0 (176993997)|WF_FLOW_ACTION_BEGIN|09L16000000GqND
07:39:13.177 (177081284)|FLOW_CREATE_INTERVIEW_BEGIN|00DA0000000KKvp|30016000000TzHJ|301160000000NCC
07:39:13.177 (178903917)|FLOW_CREATE_INTERVIEW_END|2674330c60d0fd141f9753e2ecfa15c4531840e-73d0|Update Candidate Status When Requisition Status Changes
07:39:13.179 (179273741)|FLOW_START_INTERVIEWS_BEGIN|1
07:39:13.179 (180204151)|FLOW_START_INTERVIEW_BEGIN|2674330c60d0fd141f9753e2ecfa15c4531840e-73d0|Update Candidate Status When Requisition Status Changes
07:39:13.179 (182823203)|FLOW_START_INTERVIEW_END|2674330c60d0fd141f9753e2ecfa15c4531840e-73d0|Update Candidate Status When Requisition Status Changes
07:39:13.179 (182835114)|FLOW_START_INTERVIEWS_END|1
07:39:13.0 (184834647)|WF_FLOW_ACTION_END|09L16000000GqND
07:39:13.0 (203082844)|CODE_UNIT_FINISHED|Workflow:01I16000002cLv0
07:39:13.0 (204337281)|DML_END|[317]
07:39:13.0 (204551394)|DML_BEGIN|[321]|Op:Upsert|Type:Question__c|Rows:32
07:39:13.0 (623423795)|CODE_UNIT_STARTED|[EXTERNAL]|01q16000001MACS|QuestionTrigger on Question trigger event AfterInsert for [a0O1600000NBNSd, a0O1600000NBNSe, a0O1600000NBNSf, a0O1600000NBNSg, a0O1600000NBNSh, a0O1600000NBNSi, a0O1600000NBNSj, a0O1600000NBNSk, a0O1600000NBNSl, a0O1600000NBNSm, a0O1600000NBNSn, a0O1600000NBNSo, a0O1600000NBNSp, a0O1600000NBNSq, a0O1600000NBNSr, a0O1600000NBNSs, a0O1600000NBNSt, a0O1600000NBNSu, a0O1600000NBNSv, a0O1600000NBNSw, a0O1600000NBNSx, a0O1600000NBNSy, a0O1600000NBNSz, a0O1600000NBNT0, a0O1600000NBNT1, a0O1600000NBNT2, a0O1600000NBNT3, a0O1600000NBNT4, a0O1600000NBNT5, a0O1600000NBNT6, a0O1600000NBNT7, a0O1600000NBNT8]
07:39:13.0 (626408500)|METHOD_ENTRY|[7]|01p16000004wQcz|QuestionTriggerHandler.QuestionTriggerHandler()
07:39:13.0 (626428661)|METHOD_EXIT|[7]|QuestionTriggerHandler
07:39:13.0 (626458396)|METHOD_ENTRY|[9]|01p16000004wQcz|QuestionTriggerHandler.afterInsert(List)
07:39:13.0 (626535199)|METHOD_ENTRY|[10]|01p16000004wQcz|QuestionTriggerHandler.updateAccountQuestionMasterList(List)
07:39:13.0 (630356391)|SOQL_EXECUTE_BEGIN|[24]|Aggregations:2|SELECT Id, (SELECT Id FROM Company_Questions__r), (SELECT Id FROM Requisitions__r WHERE (Open_For_Submission__c = TRUE AND Form_Created__c = TRUE)) FROM Account
07:39:13.0 (908437159)|SOQL_EXECUTE_END|[24]|Rows:479
07:39:16.812 (3918001865)|SOQL_EXECUTE_BEGIN|[48]|Aggregations:0|SELECT Id FROM Requisition__c
07:39:16.812 (4186422097)|SOQL_EXECUTE_END|[48]|Rows:5140
07:39:49.835 (37373727559)|METHOD_ENTRY|[48]||Database.QueryLocatorIterator.next()
07:39:49.835 (37373788041)|METHOD_EXIT|[48]||Database.QueryLocatorIterator.next()
*** Skipped 156024742 bytes of detailed log
07:39:49.835 (37377209166)|VARIABLE_ASSIGNMENT|[49]|ques|{"LastModifiedDate":"2017-05-26T14:39:14.000Z","Question_Text__c":"Location worked","IsDeleted":false,"Display_Dependant_Va (6 more) ...":"Yes","CurrencyIsoCode":"USD","Name":"Q-1035396","SystemModstamp":"2017-05-26T14:39:14.000Z","OwnerId":"00516000006pG2PAAU","CreatedById":"00516000006pG2PAAU","Requisition__c":"a0P1600000BwPByEAN","Type__c":"Multi-line text","Template_Question__c":"a0O1600000p2sPZEAY","RecordTypeId":"012160000014KvOAAU","CreatedDate":"2017-05-26T14:39:14.000Z","Order__c":20,"Id":"a0O1600000NBNSwEAP","LastModifiedById":"00516000006pG2PAAU"}|0x3532e45f
07:39:49.835 (37377217673)|STATEMENT_EXECUTE|[49]
07:39:49.835 (37377240830)|STATEMENT_EXECUTE|[50]
I am thinking following SOQL query is taking longer time..
for(Question__c quest :[SELECT
id, Question_Text__c, Picklist_Options__c , Type__c, Order__c, recordTypeId,
recordType.name, Display_Dependant_Value__c, Display_Dependant_Question__c
FROM
Question__c
WHERE
Template_Question__c = null
AND(
(recordType.name =: System.Label.Record_Type_Standard_Template)
OR(Id IN :compQuesSet AND recordType.name = :System.Label.Record_Type_Custom_Template)
OR (recordType.name = :System.Label.Record_type_Form_Question
AND Requisition__c =: requisition.Id
)
)
ORDER BY
Order__c]){
//...
}
it is causing timeout many times. Could you suggest how to solve problem?
5 CPU time is calculated for all executions
aside about a quarter down the page documenting goverrnor limits . It's much more likely that your issue resides inside thefor
loop that you've provided. Using the analysis perspective in the dev console (open a log, Debug -> Switch Perspective -> Analysis (predefined) ) should help narrow your search.