+ Start a Discussion
m@x~W0W~m@x~W0W~ 

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');
}
}
}

}

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

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

souvik9086souvik9086

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

 

This was selected as the best answer
m@x~W0W~m@x~W0W~

Error after implementing the above recommended solution:

Initial term of field object must be a concrete SObject : Integer

m@x~W0W~m@x~W0W~

Sorry, my bad. 

 

Bracket misplacement.

 

BTW thanks for your solution. It worked just fine.