function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shawn ReichnerShawn Reichner 

Case Trigger Not Firing

Hello,

I have created a class and trigger which I will paste below.  These are on the case object and in sandbox at the moment until I can get them to operate correctly.  

What I want to happen is when a certain picklist choice is chosen, I woudl like the trigger to automatically populate another field with a certain value. 

Here is my code currently, can anyone please help with figuring out why this is not updating the field when that picklist value is chosen and the case record is saved?

Thank you,

Class

public class salespersonextraction {
    public static void salesextract(List<Case> Cases){
  
for (Case c:Cases){

    IF (c.AVI_SPL_Rep_Whse_Office_Code_2011__c == 'AB_Calgary_780S_780600_CAD'){
    c.Salesperson_Extraction_Code__c = '780S';


    IF (c.AVI_SPL_Rep_Whse_Office_Code_2011__c == 'AL_Birmingham_120S_120600_AVI'){
    c.Salesperson_Extraction_Code__c = '120S';
  

}}}
}}


Trigger

trigger Salesextract on Case (before insert, before update) {
List<Case> Cases = Trigger.new;
salespersonextraction.salesextract(Cases);

}





Best Answer chosen by Shawn Reichner
KevinPKevinP
well, without seeing the input that fires the trigger, here are some suggestions.

First, let me congradulate you on the use of a class for your trigger logic.

use: System.debug('Some message here'); through out your code so you can see what, if anything is firiing.

but I think there's some syntax issues with the code: Try this

public class salespersonextraction {
	public static void salesextract(List<Case> Cases) {

		for (Case c : Cases) {
			if (c.AVI_SPL_Rep_Whse_Office_Code_2011__c == 'AB_Calgary_780S_780600_CAD') {
				c.Salesperson_Extraction_Code__c = '780S';
			}

			if (c.AVI_SPL_Rep_Whse_Office_Code_2011__c == 'AL_Birmingham_120S_120600_AVI') {
				c.Salesperson_Extraction_Code__c = '120S';
			}
		}
	}
}


// Trigger

trigger Salesextract on Case (before insert, before update) {
	List<Case> Cases = Trigger.new;
	salespersonextraction.salesextract(Cases);
}

Note the ending } after the c.Salesperson_Extraction_Code__c = '780S'; and it's sister if clause.

ps: the little < > symbol on the formatting bar will help you format your code in a nice, easy to read manner.

All Answers

KevinPKevinP
well, without seeing the input that fires the trigger, here are some suggestions.

First, let me congradulate you on the use of a class for your trigger logic.

use: System.debug('Some message here'); through out your code so you can see what, if anything is firiing.

but I think there's some syntax issues with the code: Try this

public class salespersonextraction {
	public static void salesextract(List<Case> Cases) {

		for (Case c : Cases) {
			if (c.AVI_SPL_Rep_Whse_Office_Code_2011__c == 'AB_Calgary_780S_780600_CAD') {
				c.Salesperson_Extraction_Code__c = '780S';
			}

			if (c.AVI_SPL_Rep_Whse_Office_Code_2011__c == 'AL_Birmingham_120S_120600_AVI') {
				c.Salesperson_Extraction_Code__c = '120S';
			}
		}
	}
}


// Trigger

trigger Salesextract on Case (before insert, before update) {
	List<Case> Cases = Trigger.new;
	salespersonextraction.salesextract(Cases);
}

Note the ending } after the c.Salesperson_Extraction_Code__c = '780S'; and it's sister if clause.

ps: the little < > symbol on the formatting bar will help you format your code in a nice, easy to read manner.

This was selected as the best answer
Shawn ReichnerShawn Reichner
Thank you so much!  This works like a charm,,,I was close.

Thanks again,

Shawn