You need to sign in to do that
Don't have an account?
trigger isUpdate
I am having scenario some thing like this.. I wanrt to fire trigger on insert if salary less than 1000 and in update salary must be greater than 1300...BUT..BUT BUT.... main thing... during update i dont want to fire the update trigger record when the salary amount does not chnages.. it only get fired when during update the salary amount is being changed..During update if i changes or updates any other field, except salary the before update trigger should not fire ... I done some something like this.. before insert is correct but i am having problem in before update... that when i changes the salary then only it shoul fire.. if old value != new value then fire the trigger
trigger salaryCheck on Teacher__c (before Insert, before Update) { for(Teacher__c tch : trigger.New) { if(trigger.isInsert && tch.Salary__c < 1000) { tch.addError('Must be greater than 1000'); } } List<Teacher__c> oldlstTch = new List<Teacher__c>(trigger.old); for(Teacher__c newLstTch : trigger.new) { if(trigger.isUpdate && newLstTch.Salary__c != oldlstTch.Salary__c ) { if(newLstTch.Salary__c == null ||newLstTch.Salary__c < 1300) { newLstTch.Salary__c.addError('can not be null and greater than 1300'); } } } }Error : Compile Error: Initial term of field expression must be a concrete SObject: List<Teacher__c> at line 14 column 50
Please try with the below code :
Let me know if you have any issue.
Thanks,
Abhishek
All Answers
2. At 14, again, you have to iterate through individual Sobject records to be able to compare the values of individual fields. But you are using, List.FieldValue and thus the error.
3. The dot notation that you use to access elements off of list is List[index].field__c.
4. It is recommended to write the logic in an Apex class and call that class in your trigger.
5. Now try something like this
Please try with the below code :
Let me know if you have any issue.
Thanks,
Abhishek