You need to sign in to do that
Don't have an account?
AndrewK87
Apex class task activation
Hi,
New to Apex but I'm looking to ammend a previously built apex class in our org. This creates set tasks for a user upon 'close won' of an Opportunity.
Class is below.
I'm just trying to find how to ammend the core tasks which are being generated when this is run? So I want to add a few and ammend a few.
I just don't know where this 'task list' is being pulled from.
Any advice welcome.
Thanks
public class OpportunityOnBoardingTasksHandler {
private static List<Task> TasksToCreate;
private static Map<Id,Building__c> RelatedBuildings;
private static List<Client_On_boarding_Task__mdt> TasksSettings;
public static void loadRelatedBuildingsAndTasksSettings(Map<Id,Opportunity> old_opportunities, Map<Id,Opportunity> new_opportunities){
Set<Id> buildings = new Set<Id>();
for (Id key: new_opportunities.keySet()){
if (
new_opportunities.get(key).RecordTypeId == RecordTypeUtility.getInstance().getIdByName(RecordTypeUtility.OPPORTUNITY_BUSINESS) &&
(old_opportunities.get(key).IsClosed != new_opportunities.get(key).IsClosed) &&
isClosedWon(new_opportunities.get(key))
){
buildings.add(new_opportunities.get(key).Building__c);
}
}
RelatedBuildings = new Map<Id,Building__c>([SELECT Id, Center_Manager__c FROM Building__c WHERE Id IN :buildings]);
TasksSettings = [SELECT DeveloperName, MasterLabel, Due_In_Days__c FROM Client_On_boarding_Task__mdt];
TasksToCreate = new List<Task>();
}
private static Boolean isClosedWon(Opportunity new_opportunity){
return new_opportunity.IsClosed && new_opportunity.IsWon && String.isNotBlank(new_opportunity.Building__c);
}
public static void createRelatedTasks(Opportunity old_opportunity, Opportunity new_opportunity){
if (
new_opportunity.RecordTypeId == RecordTypeUtility.getInstance().getIdByName(RecordTypeUtility.OPPORTUNITY_BUSINESS) &&
(old_opportunity.IsClosed != new_opportunity.IsClosed) &&
isClosedWon(new_opportunity)
){
Id owner = RelatedBuildings.get(new_opportunity.Building__c).Center_Manager__c;
if (String.isNotBlank(owner)){
for (Client_On_boarding_Task__mdt setting: TasksSettings){
Task new_task = new Task(Subject = setting.MasterLabel, Priority = 'Normal', Status = 'Open',
WhatId = new_opportunity.Id, Main_Property__c = new_opportunity.Building__c,
OwnerId = owner);
if ((setting.Due_In_Days__c != null) && (setting.Due_In_Days__c != 0)){
new_task.ActivityDate = System.today().addDays(Integer.valueOf(setting.Due_In_Days__c));
} else {
new_task.ActivityDate = System.today();
}
TasksToCreate.add(new_task);
}
}
}
}
public static void insertNewTasks(){
if (!TasksToCreate.isEmpty()){
insert TasksToCreate;
}
}
}
New to Apex but I'm looking to ammend a previously built apex class in our org. This creates set tasks for a user upon 'close won' of an Opportunity.
Class is below.
I'm just trying to find how to ammend the core tasks which are being generated when this is run? So I want to add a few and ammend a few.
I just don't know where this 'task list' is being pulled from.
Any advice welcome.
Thanks
public class OpportunityOnBoardingTasksHandler {
private static List<Task> TasksToCreate;
private static Map<Id,Building__c> RelatedBuildings;
private static List<Client_On_boarding_Task__mdt> TasksSettings;
public static void loadRelatedBuildingsAndTasksSettings(Map<Id,Opportunity> old_opportunities, Map<Id,Opportunity> new_opportunities){
Set<Id> buildings = new Set<Id>();
for (Id key: new_opportunities.keySet()){
if (
new_opportunities.get(key).RecordTypeId == RecordTypeUtility.getInstance().getIdByName(RecordTypeUtility.OPPORTUNITY_BUSINESS) &&
(old_opportunities.get(key).IsClosed != new_opportunities.get(key).IsClosed) &&
isClosedWon(new_opportunities.get(key))
){
buildings.add(new_opportunities.get(key).Building__c);
}
}
RelatedBuildings = new Map<Id,Building__c>([SELECT Id, Center_Manager__c FROM Building__c WHERE Id IN :buildings]);
TasksSettings = [SELECT DeveloperName, MasterLabel, Due_In_Days__c FROM Client_On_boarding_Task__mdt];
TasksToCreate = new List<Task>();
}
private static Boolean isClosedWon(Opportunity new_opportunity){
return new_opportunity.IsClosed && new_opportunity.IsWon && String.isNotBlank(new_opportunity.Building__c);
}
public static void createRelatedTasks(Opportunity old_opportunity, Opportunity new_opportunity){
if (
new_opportunity.RecordTypeId == RecordTypeUtility.getInstance().getIdByName(RecordTypeUtility.OPPORTUNITY_BUSINESS) &&
(old_opportunity.IsClosed != new_opportunity.IsClosed) &&
isClosedWon(new_opportunity)
){
Id owner = RelatedBuildings.get(new_opportunity.Building__c).Center_Manager__c;
if (String.isNotBlank(owner)){
for (Client_On_boarding_Task__mdt setting: TasksSettings){
Task new_task = new Task(Subject = setting.MasterLabel, Priority = 'Normal', Status = 'Open',
WhatId = new_opportunity.Id, Main_Property__c = new_opportunity.Building__c,
OwnerId = owner);
if ((setting.Due_In_Days__c != null) && (setting.Due_In_Days__c != 0)){
new_task.ActivityDate = System.today().addDays(Integer.valueOf(setting.Due_In_Days__c));
} else {
new_task.ActivityDate = System.today();
}
TasksToCreate.add(new_task);
}
}
}
}
public static void insertNewTasks(){
if (!TasksToCreate.isEmpty()){
insert TasksToCreate;
}
}
}
Task fields related to calls are exclusive to Salesforce CRM Call Center. Also, query() , delete() , and update() aren't allowed with tasks related to more than one ...
Missing: activation | Must include: activation