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
sreedharp286sreedharp286 

Trigger code for display error message , when ever trying to case status field updated

 Can any one send trigger code ?

 

Best Answer chosen by Admin (Salesforce Developers) 
jungleeejungleee

You can use the below code to throw error whenever there's a change in the status. But this could have been achieved from a validation itself.

 

trigger caseStatusUpdate on case (before update){
	for(case c: trigger.new){
		if(c.status!= trigger.oldMap.get(c.id).status){
			c.status.addError('you cannot update the status');
		}
	}
}

 

 

All Answers

jungleeejungleee

You can use the below code to throw error whenever there's a change in the status. But this could have been achieved from a validation itself.

 

trigger caseStatusUpdate on case (before update){
	for(case c: trigger.new){
		if(c.status!= trigger.oldMap.get(c.id).status){
			c.status.addError('you cannot update the status');
		}
	}
}

 

 

This was selected as the best answer
Abhi_TripathiAbhi_Tripathi

Hey sreedharp, 

 

In the below link there is a code sample having same thing as in your requirement

 

 

http://abhithetechknight.blogspot.in/2013/09/custom-error-message-on-standard-edit.html 

Pratibha JamadadePratibha Jamadade
I also have same scenario ,if the checkbox field is checked,currency field should not be updated, if it is ,then error should be shown. 
Any one idea about that ?