ForceChallenges
ProblemsDailyNotesInterview
Sign in

Practice

All problemsSOQL practiceApex trigger challengesDaily challengeOpportunityTrigger.oldMapBefore UpdateBulkificationContactValidationGROUP BYSemi-JoinAccountBefore Insert

Interview questions

All questionsAdminAdministrationApexApex TriggerAsync ApexDevelopmentField ServiceField ServiceIntegrationLwc

By company

DeloitteSalesforceAccentureInfosysPwCCognizant

Learn

Study notes

ForceChallenges

AboutContact usPrivacy PolicyTerms of ServiceFor AI assistants (llms.txt)
© 2026 ForceChallenges · Salesforce SOQL & Apex trigger practice
Development questions84 of 102
DevelopmentMedium 1 min read

When a Case is created with Origin = 'Email' and Priority = 'High', automatically assign it to a specific SLA Queue and create an Entitlement task.

Asked atInfosysWiproHCL

Answer

Use before insert to set the owner to a Queue and after insert to create the Task. Query the Queue once.

apex
trigger CaseTrigger on Case (before insert, after insert) {
    if (Trigger.isBefore) {
        Id qId = [SELECT Id FROM Group WHERE Type = 'Queue' AND DeveloperName = 'High_Priority_SLA' LIMIT 1].Id;
        for (Case c : Trigger.new) if (c.Origin == 'Email' && c.Priority == 'High') c.OwnerId = qId;
    } else {
        List<Task> tasks = new List<Task>();
        for (Case c : Trigger.new) {
            if (c.Origin == 'Email' && c.Priority == 'High') {
                tasks.add(new Task(Subject = 'Review Entitlement / SLA', WhatId = c.Id, ActivityDate = Date.today().addDays(1)));
            }
        }
        insert tasks;
    }
}

Case Assignment Rules or Flow can also route to queues declaratively.

apex-triggertriggercodingscenariocase
Practice SOQL & Apex
PreviousWrite a trigger to find the Maximum and Minimum Salary among all Employee__c child records and populate Max_Salary__c and Min_Salary__c on Department__c.Next Write a trigger to share a custom object record (Project__c) using Apex Managed Sharing (Project__Share) when a Manager__c lookup field is populated or updated.

More Development questions

  • What is reactivity in LWC and when does a field trigger a re-render?
  • What are the best practices to improve LWC performance?
  • How do you unit test an LWC with Jest?
  • How do you use a third-party JavaScript library or static resource in LWC?
  • Why can renderedCallback run multiple times and how do you prevent repeated execution?