You need to sign in to do that
Don't have an account?
Error: Invalid Data.
Review all error messages below to correct your data. Apex trigger stuLimit caused an unexpected exception, contact your administrator: stuLimit: execution of BeforeInsert caused by: System.TypeException: Invalid integer: [Class__c (Number_Of_Students__c:2, Max_Size__c:2, Id:a0190000007tbH3AAI)]: Trigger.stuLimit: line 15, column 1m
trigger stuLimit on Student__c (after insert)
{
//////////////////////////////////////
// Do not allow insert student if class already reached MaxLimit.
// Created 20131009 max
// Modified 20131009
//////////////////////////////////////
if(Trigger.isAfter && Trigger.isInsert)
{
for (Student__c std : Trigger.new)
{
Id cid = std.class__c;
list<Class__c> cls=[SELECT Max_Size__c, Number_Of_Students__c from Class__c where class__c.id = : cid];
if(Integer.Valueof(cls.get(0)) <= Integer.Valueof(cls.get(1)))
{
std.addError('can\'t insert Class has already reached it\'s maximum limit');
}
}
}
}
You didn't mentioned your field name after the get(0). like
if(Integer.Valueof(cls.get(0).YourFieldName) <= Integer.Valueof(cls.get(1).YourFieldName))
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
All Answers
You didn't mentioned your field name after the get(0). like
if(Integer.Valueof(cls.get(0).YourFieldName) <= Integer.Valueof(cls.get(1).YourFieldName))
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Error after implementing the above recommended solution:
Initial term of field object must be a concrete SObject : Integer
Sorry, my bad.
Bracket misplacement.
BTW thanks for your solution. It worked just fine.