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
Corey RitterCorey Ritter 

Can I post here to hire a Apex Class Salesforce Developer?

Here is the code and a link to the page for my org.  https://bodydesignos.my.salesforce.com/01q50000000Gue5


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
trigger EventTrigger on Event (after insert, after update, after delete, before delete) 

    if((trigger.isUpdate||trigger.isInsert)&&trigger.isAfter) EventActions.SetAccountUsedSessions(trigger.new); 
    if((trigger.isDelete)&&trigger.isAfter) EventActions.SetAccountUsedSessions(trigger.old);
    
    Profile sysAdminProfile = [SELECT Id FROM Profile WHERE Name='Corporate' LIMIT 1]; 
    if(UserInfo.getProfileId()!=sysAdminProfile.Id)
    {
        if(trigger.isBefore && trigger.isDelete)
        {
            for(Event event : trigger.old)
            { 
                Datetime endDate = event.EndDateTime;
                if(event.RecurrenceEndDateOnly!=null) endDate = event.RecurrenceEndDateOnly;
                if(endDate != null && endDate.addHours(-5) < system.today().toStartOfWeek())
                {
                    event.addError('Events completed before this week cannot be deleted or edited.');
                }
            }
        }
        if(trigger.isAfter && trigger.isUpdate)
        {
            for(Event event : trigger.new)
            {
                Datetime endDate = trigger.oldMap.get(event.Id).EndDateTime;
                if(event.RecurrenceEndDateOnly!=null) endDate = event.RecurrenceEndDateOnly;
                if(endDate!=null && endDate.addHours(-5) < system.today().toStartOfWeek())
                {
                    event.addError('Events completed before this week cannot be deleted or edited.');
                }
            }
        }
    }
}
The code has stopped totallingall the used sessions (events lableled PT Session) in the field "Used Sessions" on account.



Please let me know if you can figure out why. It's working for some accounts but not all. I also need the "system admin" profile to be added on this line"

#6     Profile sysAdminProfile = [SELECT Id FROM Profile WHERE Name='Corporate' LIMIT 1]; 


Thanks for your help!
 
EstherEsther
It appears that the code is not correctly updating the "Used Sessions" field on all accounts. There could be several reasons for this issue, such as data inconsistencies or errors in the code. To troubleshoot the issue, you may want to try the following steps:
  1. Check the data in the Account and Event objects to ensure that it is accurate and consistent.
  2. Debug the code by using the Apex Debugger or adding debug statements to the code. This can help you identify any errors or issues in the code.
  3. Test the code by creating test records and triggering the trigger events. This can help you verify that the code is working as expected.
  4. Review the code and look for any syntax errors or logical issues that may be causing the problem.

If you need more help with this issue, you may want to consider hiring an Apex developer. You can refer to this article for tips on how to hire an Apex developer: "Hire Apex developer" https://arrify.com/hire-salesforce-apex-developer/.

This article provides information on the skills and experience to look for in an Apex developer, as well as best practices for finding and hiring the right developer for your organization.