You need to sign in to do that
Don't have an account?

Remove profiles
How do I allow all users to use this apex? It's currently restricted to my community users.
public without sharing class EventActions
{
public static void SetAccountUsedSessions(List<Event> events)
{
Set<Id> accountIds = new Set<Id>();
for(Event event : events)
{
if(event.AccountId!=null && !accountIds.contains(event.AccountId)) accountIds.add(event.AccountId);
}
if(accountIds!=null&&accountIds.size()>0)
{
Map<Id, Account> accountsToUpdate = new Map<Id, Account>();
AggregateResult[] countResults = [SELECT AccountId, count(Id)cnt FROM Event WHERE AccountId IN :accountIds AND IsRecurrence=false AND Subject LIKE 'PT%' AND ActivityDate <= TODAY AND EVENT_STATUS1__C <> 'Cancelled WITH 24hr Notice' GROUP BY AccountId];
if(countResults!=null&&countResults.size()>0)
{
for (AggregateResult ar : countResults) {
String accountId = String.ValueOf(ar.get('AccountId'));
String usedSessions = String.ValueOf(ar.get('cnt'));
if(accountId!=null&&accountId!=''&&usedSessions!=null&&usedSessions!='')
{
Account account = new Account(Id=accountId);
account.Used_Sessions__c = integer.valueOf(usedSessions);
accountsToUpdate.put(account.Id, account);
}
}
}
for(Id accountId : accountIds)
{
if(!accountsToUpdate.containsKey(accountId))
{
Account account = new Account(Id=accountId);
account.Used_Sessions__c = 0;
accountsToUpdate.put(accountId, account);
}
}
if(accountsToUpdate!=null&&accountsToUpdate.values().size()>0) update accountsToUpdate.values();
}
}
public static testMethod void Test()
{
List<Event> events = [SELECT Id, WhatId, AccountId FROM Event WHERE AccountId<>null
AND IsRecurrence=true AND Subject LIKE 'PT%' LIMIT 10];
Event events2 = [SELECT Id, WhatId, AccountId FROM Event WHERE AccountId<>null
AND IsRecurrence=false AND EndDateTime > :system.today().toStartOfWeek() LIMIT 1];
Profile sysAdminProfile = [SELECT Id FROM Profile WHERE Name='Corporate' LIMIT 1];
User u = [select Id from User where IsActive = true and UserType = 'Standard'
and ProfileId != :sysAdminProfile.Id limit 1];
System.runAs(u) {
SetAccountUsedSessions(events);
update events2;
delete events2;
}
}
}
public without sharing class EventActions
{
public static void SetAccountUsedSessions(List<Event> events)
{
Set<Id> accountIds = new Set<Id>();
for(Event event : events)
{
if(event.AccountId!=null && !accountIds.contains(event.AccountId)) accountIds.add(event.AccountId);
}
if(accountIds!=null&&accountIds.size()>0)
{
Map<Id, Account> accountsToUpdate = new Map<Id, Account>();
AggregateResult[] countResults = [SELECT AccountId, count(Id)cnt FROM Event WHERE AccountId IN :accountIds AND IsRecurrence=false AND Subject LIKE 'PT%' AND ActivityDate <= TODAY AND EVENT_STATUS1__C <> 'Cancelled WITH 24hr Notice' GROUP BY AccountId];
if(countResults!=null&&countResults.size()>0)
{
for (AggregateResult ar : countResults) {
String accountId = String.ValueOf(ar.get('AccountId'));
String usedSessions = String.ValueOf(ar.get('cnt'));
if(accountId!=null&&accountId!=''&&usedSessions!=null&&usedSessions!='')
{
Account account = new Account(Id=accountId);
account.Used_Sessions__c = integer.valueOf(usedSessions);
accountsToUpdate.put(account.Id, account);
}
}
}
for(Id accountId : accountIds)
{
if(!accountsToUpdate.containsKey(accountId))
{
Account account = new Account(Id=accountId);
account.Used_Sessions__c = 0;
accountsToUpdate.put(accountId, account);
}
}
if(accountsToUpdate!=null&&accountsToUpdate.values().size()>0) update accountsToUpdate.values();
}
}
public static testMethod void Test()
{
List<Event> events = [SELECT Id, WhatId, AccountId FROM Event WHERE AccountId<>null
AND IsRecurrence=true AND Subject LIKE 'PT%' LIMIT 10];
Event events2 = [SELECT Id, WhatId, AccountId FROM Event WHERE AccountId<>null
AND IsRecurrence=false AND EndDateTime > :system.today().toStartOfWeek() LIMIT 1];
Profile sysAdminProfile = [SELECT Id FROM Profile WHERE Name='Corporate' LIMIT 1];
User u = [select Id from User where IsActive = true and UserType = 'Standard'
and ProfileId != :sysAdminProfile.Id limit 1];
System.runAs(u) {
SetAccountUsedSessions(events);
update events2;
delete events2;
}
}
}
Give access to this class to ther profile.
Best Regards,
Vijay
They do have access to that Apex Class but we think the lines:
User u = [select Id from User where IsActive = true and UserType = 'Standard'
and ProfileId != :sysAdminProfile.Id limit 1];
System.runAs(u) {
Are blocking it.
When I go into my full use license and hit edit save on one of the account events it updates the "Available Session" field but it's not working for the community.
Thanks, Corey