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
RstrunkRstrunk 

Simple trigger

I need to create(and I have zero apex experience) a simple trigger that will do the following:

 

//psuedo code

if (the new case owner is not in the same case team as the old case owner) {

                       increment a field by 1

}

 

else {

 nothing

}

 

its for the case object

 

Any help would be greatly appreciated

 

Best Answer chosen by Admin (Salesforce Developers) 
ChopaForceChopaForce

Hello Rstrunk,

 

you can go with something like this: (NumberField__c is your field to increment and I assumed that the Team field is located on the User object (Owner.Team__c)

 

trigger CaseTrigger on Case (before update) {
	for(integer i = 0; i < Trigger.new.size(); i++)
	{
		if(Trigger.new[i].Owner.Team__c != Trigger.old[i].Owner.Team__c)
		{
			if(Trigger.new[i].NumberField__c == null)
			{
				Trigger.new[i].NumberField__c = 1;
			}
			else
			{
				Trigger.new[i].NumberField__c++;
			}
		}
	}
}

 

Hope it helps,

 

ChopaForce