• AndrewK87
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
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;
    }
  }
}
Hi,

We have a critical requirement to iFrame a Lightning Component to an external website. I've read mixed posts about how this is possible.

Just to note, we built it with a lightning frame component not visualforce, to allow easy edits and a scalable solution.

What we want to do is take the component, which is set up to be externally accessed, so no log in and embed it through an iFrame on to our WordPress website to create a smooth UI/UX and drive engagement.

The current work around is just to hyperlink off our website to the Salesforce page but this is against the flow we'd designed for, also for marketing/commercial requirments we want it embedded.

Any solution, feedback or work around would be greatly appreciated.

Thanks in advance.
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;
    }
  }
}