You need to sign in to do that
Don't have an account?

I have 2 objects 1 is Trig1__c,second one s Trig2__c......on these 2 objects i have written a trgger to create
I have 2 objects 1 is Trig1__c,second one s Trig2__c......in Trig1__C i have a numberfield called No_of_Trig2__c(Numberfield)....so here what i need is if i enter the 10 in No_of_Trig2__c then 10 records should be created autometically in Trig2__c,......so here is my trrigger
trigger Cretaingrecontrig2 on Trig1__c (after insert) {
List<Trig2__c>Listtri=New List<Trig2__C>();
for(Trig1__c tr:Trigger.new){
if(Trig1__c.No_of_Trig2__c!=null){
for(integer i=0;i<Trig1__C.No_of_Trig2__c;i++){
Trig2__c tri=New List Trig2__c();
tri.id=tr.id;
tri.Name=tr.Name;
Listtri.add(tri);
}
if(!Listtri.Isempty()){
insert Listtri;
}
}
}
}
so here the trigger is saved fine ...but the problem is while saving the record am getting below error
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Cretaingrecontrig2 caused an unexpected exception, contact your administrator: Cretaingrecontrig2: execution of AfterInsert caused by: System.TypeException: Invalid integer: common.apex.runtime.impl.ApexFieldToken@7bce7881: Trigger.Cretaingrecontrig2: line 6, column 1
what may be the problem
trigger Cretaingrecontrig2 on Trig1__c (after insert) {
List<Trig2__c>Listtri=New List<Trig2__C>();
for(Trig1__c tr:Trigger.new){
if(Trig1__c.No_of_Trig2__c!=null){
for(integer i=0;i<Trig1__C.No_of_Trig2__c;i++){
Trig2__c tri=New List Trig2__c();
tri.id=tr.id;
tri.Name=tr.Name;
Listtri.add(tri);
}
if(!Listtri.Isempty()){
insert Listtri;
}
}
}
}
so here the trigger is saved fine ...but the problem is while saving the record am getting below error
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger Cretaingrecontrig2 caused an unexpected exception, contact your administrator: Cretaingrecontrig2: execution of AfterInsert caused by: System.TypeException: Invalid integer: common.apex.runtime.impl.ApexFieldToken@7bce7881: Trigger.Cretaingrecontrig2: line 6, column 1
what may be the problem
sorry here is my trigger .....small change
trigger Cretaingrecontrig2 on Trig1__c (after insert) {
List<Trig2__c>Listtri=New List<Trig2__C>();
for(Trig1__c tr:Trigger.new){
if(Trig1__c.No_of_Trig2__c!=null){
for(integer i=0;i<Integer.valueof(Trig1__C.No_of_Trig2__c);i++){
Trig2__c tri=New List Trig2__c();
tri.id=tr.id;
tri.Name=tr.Name;
Listtri.add(tri);
}
if(!Listtri.Isempty()){
insert Listtri;
}
}
}
}
Put a debug to print this " Integer.valueof(Trig1__C.No_of_Trig2__c) " value before
this Line
for(integer i=0;i<Integer.valueof(Trig1__C.No_of_Trig2__c);i++){
instead of
if(Trig1__c.No_of_Trig2__c!=null)
Choose it as Best Answer if it resolves your issue