You need to sign in to do that
Don't have an account?
prabhat jha
list has no rows for assignment to Sobject in triggers
i have written one trigger to insert a new Account species/consultation record (ZTS_EU_Account_Species_Potential__c) if species name matches the species listed in my custom setting (SpeciesList__c) which has three fields parentspeciesname,childspeciesname and one factor (number field).but my insert statement fails and throws the mentioned error ,i am stuck with this error for previous 24 hrs ,any help would be appreciated.here species is a different object (ZTS_EU_Species__c ) and lookup field of Account consultation records.
here is my trigger:
trigger createChildSpecies on ZTS_EU_Account_Species_Potential__c (before Insert) {
ID accctid;
ID Speciesid;
ID childspeciesid;
String Speciesname;
Double Parentcount;
String CHLDSpeciesname;
String myCCVal ;
ZTS_EU_Species__c test=new ZTS_EU_Species__c ();
ZTS_EU_Species__c childtestforid=new ZTS_EU_Species__c ();
ZTS_EU_Account_Species_Potential__c PARENTRECORD;
ZTS_EU_Account_Species_Potential__c chld=new ZTS_EU_Account_Species_Potential__c();
for(ZTS_EU_Account_Species_Potential__c a:trigger.new)
{
//PARENTRECORD.Account__c=a.Account__c;
Speciesid=a.ZTS_EU_Species_Potential__c;
system.debug('parentspeciesnameeee===='+Speciesid);
test=[SELECT Name FROM ZTS_EU_Species__c WHERE ZTS_EU_Market__c = 'Spain' AND Id =:Speciesid];
Speciesname=test.Name ;
system.debug('speciesname===='+Speciesname);
Map<String, SpeciesList__c> mapStatusCodeCustomSetting = SpeciesList__c.getAll();
for(SpeciesList__c mandatoryRoles : mapStatusCodeCustomSetting.values()){
if (mandatoryRoles .ParentSpeciesName__c==Speciesname)
{
myCCVal = mandatoryRoles .ChildSpeciesName__c;
childtestforid=[SELECT Id FROM ZTS_EU_Species__c WHERE ZTS_EU_Market__c = 'Spain' AND Name =:myCCVal ];
system.debug('myCS1 ===='+myCCVal);
}
}
chld.Account__c=a.Account__c;
childspeciesid=childtestforid.Id;
system.debug('childspeciesid===='+childtestforid);
chld.ZTS_EU_Species_Potential__c=childspeciesid;
chld.ZTS_EU_Animal_Consultations_new__c=10;
insert(chld);
}
}
here is my trigger:
trigger createChildSpecies on ZTS_EU_Account_Species_Potential__c (before Insert) {
ID accctid;
ID Speciesid;
ID childspeciesid;
String Speciesname;
Double Parentcount;
String CHLDSpeciesname;
String myCCVal ;
ZTS_EU_Species__c test=new ZTS_EU_Species__c ();
ZTS_EU_Species__c childtestforid=new ZTS_EU_Species__c ();
ZTS_EU_Account_Species_Potential__c PARENTRECORD;
ZTS_EU_Account_Species_Potential__c chld=new ZTS_EU_Account_Species_Potential__c();
for(ZTS_EU_Account_Species_Potential__c a:trigger.new)
{
//PARENTRECORD.Account__c=a.Account__c;
Speciesid=a.ZTS_EU_Species_Potential__c;
system.debug('parentspeciesnameeee===='+Speciesid);
test=[SELECT Name FROM ZTS_EU_Species__c WHERE ZTS_EU_Market__c = 'Spain' AND Id =:Speciesid];
Speciesname=test.Name ;
system.debug('speciesname===='+Speciesname);
Map<String, SpeciesList__c> mapStatusCodeCustomSetting = SpeciesList__c.getAll();
for(SpeciesList__c mandatoryRoles : mapStatusCodeCustomSetting.values()){
if (mandatoryRoles .ParentSpeciesName__c==Speciesname)
{
myCCVal = mandatoryRoles .ChildSpeciesName__c;
childtestforid=[SELECT Id FROM ZTS_EU_Species__c WHERE ZTS_EU_Market__c = 'Spain' AND Name =:myCCVal ];
system.debug('myCS1 ===='+myCCVal);
}
}
chld.Account__c=a.Account__c;
childspeciesid=childtestforid.Id;
system.debug('childspeciesid===='+childtestforid);
chld.ZTS_EU_Species_Potential__c=childspeciesid;
chld.ZTS_EU_Animal_Consultations_new__c=10;
insert(chld);
}
}
i solved it using Recursion to stop Firing of Recursive Trigger.
Thanks for your help
All Answers
Let us know if this will help you
(Review all error messages below to correct your data.
Apex trigger createChildSpecies caused an unexpected exception, contact your administrator: createChildSpecies: execution of BeforeInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, createChildSpecies: maximum trigger depth exceeded ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new] ZTS_EU_Account_Species_Potential trigger event BeforeInsert for [new]: []: Trigger.createChildSpecies: line 55, column 1)
i solved it using Recursion to stop Firing of Recursive Trigger.
Thanks for your help