• Jason Elwonger
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 1
    Questions
  • 3
    Replies
Hello, I am trying to write a trigger to update a lookup field, I don't care if the update happens before or after insert, but best practices point me towards a before insert action. I managed to write a trigger and public class to complement it, but now I have 0% code coverage and I cannot seem to get a Test to run using the @isTest method.

Some backstory: I have a custom object called Plan Agent that includes a User lookup. I have another custom object called
Agent/District Assignment that also contains a User lookup. The goal is to dynamically fill a lookup filled called "Agent District Assignment" on the Plan Agent record, either when the record is being created or after it is created.

So my code currently looks like this:
 
Trigger:

trigger UpdateADA on Plan_Agent__c (before insert) {
    if (trigger.isBefore) 
    {
        if (trigger.isInsert) 
        {
            ADA_PlanAgentUpdateService.findADA(trigger.new);
        }
    }
}

Class:

public with sharing class ADA_PlanAgentUpdateService
{
    public static void findADA (List<Plan_Agent__c> records)
    {
        Set<String> planAgents = new Set<String>();
        for (Plan_Agent__c record : records) planAgents.add(record.Agent__c);
        
        Map<String, Agent_District_Assignment__c> dAssignments = new Map<String, Agent_District_Assignment__c>();
        for (Agent_District_Assignment__c dAssignment : [
            SELECT id FROM Agent_District_Assignment__c
            WHERE User__c IN :planAgents
        ]) dAssignments.put(dAssignment.Id, dAssignment);
        
        for (Plan_Agent__c record : records)
            if (dAssignments.containsKey(record.Agent__c))
                record.Agent_District_Assignment__c = dAssignments.get(record.Agent__c).Id;
    }
 }

Test Class:

@isTest
public with sharing class ADA_PlanAgentUpdateService
{
    public static void findADA (List<Plan_Agent__c> records)
    {
        Set<String> planAgents = new Set<String>();
        for (Plan_Agent__c record : records) planAgents.add(record.Agent__c);
        
        Map<String, Agent_District_Assignment__c> dAssignments = new Map<String, Agent_District_Assignment__c>();
        for (Agent_District_Assignment__c dAssignment : [
            SELECT id FROM Agent_District_Assignment__c
            WHERE User__c IN :planAgents
        ]) dAssignments.put(dAssignment.Id, dAssignment);
        
        for (Plan_Agent__c record : records)
            if (dAssignments.containsKey(record.Agent__c))
                record.Agent_District_Assignment__c = dAssignments.get(record.Agent__c).Id;
    }
    ADA_PlanAgentUpdateService.findADA(Trigger.new);
}

Any help would be greatly appreciated, thanks!
I'm getting the following error message when navigating to Task pages and records, only on the latest version of Chrome.  
-1107935461
Uncaught Component class instance initialization error [Definition does not exist on the client for descriptor:markup://runtime_sales_activities:taskCommon]
Callback failed: serviceComponent://ui.force.components.controllers.recordLayoutBroker.RecordLayoutBrokerController/ACTION$getLayout....
Hello, I am trying to write a trigger to update a lookup field, I don't care if the update happens before or after insert, but best practices point me towards a before insert action. I managed to write a trigger and public class to complement it, but now I have 0% code coverage and I cannot seem to get a Test to run using the @isTest method.

Some backstory: I have a custom object called Plan Agent that includes a User lookup. I have another custom object called
Agent/District Assignment that also contains a User lookup. The goal is to dynamically fill a lookup filled called "Agent District Assignment" on the Plan Agent record, either when the record is being created or after it is created.

So my code currently looks like this:
 
Trigger:

trigger UpdateADA on Plan_Agent__c (before insert) {
    if (trigger.isBefore) 
    {
        if (trigger.isInsert) 
        {
            ADA_PlanAgentUpdateService.findADA(trigger.new);
        }
    }
}

Class:

public with sharing class ADA_PlanAgentUpdateService
{
    public static void findADA (List<Plan_Agent__c> records)
    {
        Set<String> planAgents = new Set<String>();
        for (Plan_Agent__c record : records) planAgents.add(record.Agent__c);
        
        Map<String, Agent_District_Assignment__c> dAssignments = new Map<String, Agent_District_Assignment__c>();
        for (Agent_District_Assignment__c dAssignment : [
            SELECT id FROM Agent_District_Assignment__c
            WHERE User__c IN :planAgents
        ]) dAssignments.put(dAssignment.Id, dAssignment);
        
        for (Plan_Agent__c record : records)
            if (dAssignments.containsKey(record.Agent__c))
                record.Agent_District_Assignment__c = dAssignments.get(record.Agent__c).Id;
    }
 }

Test Class:

@isTest
public with sharing class ADA_PlanAgentUpdateService
{
    public static void findADA (List<Plan_Agent__c> records)
    {
        Set<String> planAgents = new Set<String>();
        for (Plan_Agent__c record : records) planAgents.add(record.Agent__c);
        
        Map<String, Agent_District_Assignment__c> dAssignments = new Map<String, Agent_District_Assignment__c>();
        for (Agent_District_Assignment__c dAssignment : [
            SELECT id FROM Agent_District_Assignment__c
            WHERE User__c IN :planAgents
        ]) dAssignments.put(dAssignment.Id, dAssignment);
        
        for (Plan_Agent__c record : records)
            if (dAssignments.containsKey(record.Agent__c))
                record.Agent_District_Assignment__c = dAssignments.get(record.Agent__c).Id;
    }
    ADA_PlanAgentUpdateService.findADA(Trigger.new);
}

Any help would be greatly appreciated, thanks!
I'm getting the following error message when navigating to Task pages and records, only on the latest version of Chrome.  
-1107935461
Uncaught Component class instance initialization error [Definition does not exist on the client for descriptor:markup://runtime_sales_activities:taskCommon]
Callback failed: serviceComponent://ui.force.components.controllers.recordLayoutBroker.RecordLayoutBrokerController/ACTION$getLayout....