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
Arun Sarvan SamArun Sarvan Sam 

Campaign Member AfterAction: System.LimitException: Apex CPU time limit exceeded

I have enabled the error log and pasted the part of log details,

This seems to exceed the time limit at a certain location please check and let me know?


19:31:20.984 (22984272274)|CUMULATIVE_LIMIT_USAGE_END

19:31:20.415 (22985481696)|CODE_UNIT_FINISHED|RichText2 on CampaignMember trigger event BeforeUpdate|__sfdc_trigger/RichText2
19:31:20.415 (23018384339)|WF_TIME_TRIGGERS_BEGIN
19:31:20.415 (23018490779)|WF_ACTIONS_END| Field Update: 14; Flow Trigger: 24;
19:31:20.415 (23018512669)|CODE_UNIT_FINISHED|Workflow:CampaignMember
19:31:21.37 (23037645484)|FLOW_ELEMENT_ERROR|This error occurred when the flow tried to create records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: RichText2: System.LimitException: Apex CPU time limit exceeded. You can look up ExceptionCode values in the <a href='https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm#'>SOAP API Developer Guide</a>.|FlowRecordCreate|myRule_1_A1
19:31:21.37 (23072341721)|FLOW_START_INTERVIEWS_END|1
19:31:21.72 (23072695453)|WF_FLOW_ACTION_ERROR|09L1r000000boUj|300w0000000L9Q4|Error executing flow: Create_Biannual_Booking_Records_2, FlowDefId: 300w0000000L9Q4, FlowVersionId: 301w0000000Czma
19:31:21.72 (23072788855)|WF_FLOW_ACTION_ERROR_DETAIL|This error occurred when the flow tried to create records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: RichText2: System.LimitException: Apex CPU time limit exceeded. You can look up ExceptionCode values in the SOAP API Developer Guide.
19:31:21.72 (23072915584)|WF_FLOW_ACTION_END|09L1r000000boUj
19:31:21.72 (23072942169)|CODE_UNIT_FINISHED|Workflow:CampaignMember
19:31:21.87 (23087199034)|FLOW_ELEMENT_ERROR|This error occurred when the flow tried to create records: CANNOT_EXECUTE_FLOW_TRIGGER: We can't save this record because the “Create Biannual Booking Records (2)” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: RichText2: System.LimitException: Apex CPU time limit exceeded. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 125512612-159369 (-822624496). You can look up ExceptionCode values in the <a href='https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm#'>SOAP API Developer Guide</a>.|FlowRecordCreate|myRule_1_A1
19:31:21.87 (23114618730)|FLOW_START_INTERVIEWS_END|1
19:31:21.114 (23114864321)|WF_FLOW_ACTION_ERROR|09L1r000000boVc|300w0000000L964|Error executing flow: Create_Month_2_Booking, FlowDefId: 300w0000000L964, FlowVersionId: 301w0000000HMxO
19:31:21.114 (23114932896)|WF_FLOW_ACTION_ERROR_DETAIL|This error occurred when the flow tried to create records: CANNOT_EXECUTE_FLOW_TRIGGER: We can't save this record because the “Create Biannual Booking Records (2)” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: RichText2: System.LimitException: Apex CPU time limit exceeded. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 125512612-159369 (-822624496). You can look up ExceptionCode values in the SOAP API Developer Guide.
19:31:21.114 (23115016885)|WF_FLOW_ACTION_END|09L1r000000boVc
19:31:21.114 (23115035563)|CODE_UNIT_FINISHED|Workflow:CampaignMember
19:31:21.130 (23130901025)|FLOW_ELEMENT_ERROR|This error occurred when the flow tried to create records: CANNOT_EXECUTE_FLOW_TRIGGER: We can't save this record because the “Create Biannual Booking Records” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: CANNOT_EXECUTE_FLOW_TRIGGER: We can't save this record because the “Create Biannual Booking Records (2)” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: RichText2: System.LimitException: Apex CPU time limit exceeded. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 125512612-159369 (-822624496). You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 125512612-159370 (-822624496). You can look up ExceptionCode values in the <a href='https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm#'>SOAP API Developer Guide</a>.|FlowRecordCreate|Add_to_campaign
19:31:21.130 (23167519407)|FLOW_ELEMENT_ERROR|This error occurred when the flow tried to create records: CANNOT_EXECUTE_FLOW_TRIGGER: We can't save this record because the “Create Biannual Booking Records” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: CANNOT_EXECUTE_FLOW_TRIGGER: We can't save this record because the “Create Biannual Booking Records (2)” process failed. Give your Salesforce admin these details. This error occurred when the flow tried to create records: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: RichText2: System.LimitException: Apex CPU time limit exceeded. You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 125512612-159369 (-822624496). You can look up ExceptionCode values in the SOAP API Developer Guide. Error ID: 125512612-159370 (-822624496). You can look up ExceptionCode values in the <a href='https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm#'>SOAP API Developer Guide</a>.|FlowScreen|Select_Student
19:31:21.197 (23197418366)|VF_SERIALIZE_VIEWSTATE_BEGIN|066w0000001ZZbR
19:31:21.197 (23200169126)|VF_SERIALIZE_VIEWSTATE_END
19:31:21.203 (23203378612)|CUMULATIVE_LIMIT_USAGE
19:31:21.203 (23203378612)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 5 out of 100
  Number of query rows: 3 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 1 out of 150
  Number of DML rows: 1 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

19:31:21.203 (23203378612)|CUMULATIVE_LIMIT_USAGE_END

19:31:21.197 (23203498936)|CODE_UNIT_FINISHED|VF: /apex/Flow
19:31:21.197 (23204824268)|EXECUTION_FINISHED
 
Arun Sarvan SamArun Sarvan Sam
Hi Frndz,

Error log showing the detail of the process builder issue. how we can resolve this bug pls help?

Find the below error received in mail,

Selected Navigation Button: NEXT
DECISION: Relatedbookingsearch
Outcome executed: Field_is_Blank
Outcome conditions: 
1. {!SearchRelatedBookAccount} () Equals
2. {!OngoingGroup} (true) Equals true
3. {!Registration_Type} (Annual) Does not equal {!Full} (Full)
4. {!OngoingGroup} (true) Does not equal true
5. {!AgentName1} (Lorraine Dougall) Does not equal {!PleaseSelect} (Please Select)
Logic: Advanced Logic ((1 AND ((2 AND 3) OR 4)) AND 5)
GET RECORDS: Discount_Lookup_0_0
Find one Discountc record where:
Expiredc Equals false
Non_Transferc Equals true
Name Equals {!Discount_code2} ()
Result
Failed to find record.
DECISION: ValidYesNo3
Outcome executed: DiscountValid3
Outcome conditions: 
{!DiscountValid} (true) Equals true
CREATE RECORDS: Create_Student_0
Create one Account record where:
BillingCity = {!Billing_City} ()
BillingPostalCode = {!Billing_Postcode} ()
BillingState = {!Billing_County} ()
BillingStreet = {!Billing_Street} ()
Date_of_Birthc = {!Date_of_Birth} (null)
Date_of_Last_Bookingc = {!$Flow.CurrentDate} (09 July 2019)
FirstName = {!First_Name} (arun)
LastName = {!Last_Name} (sam)
PersonEmail = {!Email} (samtestarun@hotmail.com)
Phone = {!Phone} ()
RecordTypeId = 012w0000000Jvw6
Salutation = {!SALUTATIONCHOICE} (Ms.)
Result
Failed to create record.
Error Occurred: This error occurred when the flow tried to create records: DUPLICATE_VALUE: duplicate value found: Student_Email_Uniquec duplicates value on record with id: 0011r00001vuSPZ. You can look up ExceptionCode values in the SOAP API Developer Guide.
Salesforce Error ID: 1653308349-55884 (1626094139)


 
Arun Sarvan SamArun Sarvan Sam
This is my trigger code, Apex CPU time limit exceeded
 
trigger CampaignMember_AfterAction on CampaignMember (before insert, after insert, after update, after delete) {
    list<Campaign> campaignListToUpdate = new list<Campaign>(); 
        
    set<string> campaignIdsSet = new set<string>();
    map<string, integer> campaignIdMap = new map<string, integer>();
    
    //execute before action
    if(trigger.isBefore){
         if(trigger.isInsert || trigger.isUpdate){
            integer index = 0;
            for(CampaignMember member: trigger.new) {
                campaignIdMap.put(member.CampaignID, index);  
                index = index + 1;
            }
            
            for(Campaign camp: [Select Id, Name, Course_Capacity__c, Fully_Booked__c, (Select Id from CampaignMembers where status='Registered') from Campaign where id IN: campaignIdMap.keySet()]) {
                if(camp.CampaignMembers.size() >= camp.Course_Capacity__c){
                    trigger.new[campaignIdMap.get(camp.Id)].addError('The course '+camp.Name + ' is fully booked');
                }
            }
        }
    }
    
    //execute after action
    if(trigger.isAfter){
        
        // Get the affected IDs of all contacts from the campaign members
        Set<Id> contactIDs = new Set<Id>();


        if(trigger.isInsert || trigger.isUpdate){
            for(CampaignMember member: trigger.new) {
                campaignIdsSet.add(member.CampaignID);  
                contactIDs.add(member.ContactId);
            }               

        }else if(trigger.isDelete){    
            for(CampaignMember member: trigger.old) {
                campaignIdsSet.add(member.CampaignID);  
                contactIDs.add(member.ContactId);

            }                
        }
        
        for(Campaign camp: [Select Id, Course_Capacity__c, Fully_Booked__c, (Select Id from CampaignMembers where status='Registered') from Campaign where id IN: campaignIdsSet]) {
            if(camp.Course_Capacity__c == camp.CampaignMembers.size()){
                camp.Fully_Booked__c = true;               
            }else{
                camp.Fully_Booked__c = false;
            }
            campaignListToUpdate.add(camp);
        }
        
        if(campaignListToUpdate.size() > 0){
            update campaignListToUpdate;
        }

        // Update contact summary fields
        ContactSummaryService service = new ContactSummaryService();
        service.UpdateContactSummaries(ContactIds);
    }
}