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

Trigger error..
HI this code makes me hell..
This is the trigger code on my opportunity but throwing above exception can you please help me... Let me give you detail explination.
I am new to triggers..the trigger is when I insert an opportunity a new opportunity should be created automatically on the opportunity I write the trigger is below..but it is throwing exception as screen shot..
trigger new_oppy on Opportunity (after insert)
{
if(Trigger.isinsert)
{
opportunity o=new opportunity();
o.name = 'vamshi opportunity';
o.closedate = date.today();
o.StageName='closedwon';
insert o;
}
ERROR:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger wrehoue.new_oppy caused an unexpected exception, contact your administrator: wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: maximum trigger depth exceeded Opportunity trigger event AfterInsert for [0069000000LVsuf] Opportunity trigger event AfterInsert for [0069000000LVsug] Opportunity trigger event AfterInsert for [0069000000LVsuh] Opportunity trigger event AfterInsert for [0069000000LVsui] Opportunity trigger event AfterInsert for [0069000000LVsuj] Opportunity trigger event AfterInsert for [0069000000LVsuk] Opportunity trigger event AfterInsert for [0069000000LVsul] Opportunity trigger event AfterInsert for [0069000000LVsum] Opportunity trigger event AfterInsert for [0069000000LVsun] Opportunity trigger event AfterInsert for [0069000000LVsuo] Opportunity trigger event AfterInsert for [0069000000LVsup] Opportunity trigger event AfterInsert for [0069000000LVsuq] Opportunity trigger event AfterInsert for [0069000000LVsur] Opportunity trigger event AfterInsert for [0069000000LVsus] Opportunity trigger event AfterInsert for [0069000000LVsut] Opportunity trigger event AfterInsert for [0069000000LVsuu]: []: Trigger.wrehoue.new_oppy: line 11, column 1
All Answers
That being said, you're trigger is kicking off an infinite loop anytime you are creating an Opportunity, because the trigger itself creates another opportunity.
We could probably help you more if you provide us some details around what you're trigger is supposed to accomplish.
Hi James,
Thank you for your support,
My requirement is when I created an opportunity a renewal opportunity should be created automatically...
Ex: if I create an Opportunity with the name: singapore_production then a rerewal should be created automatically with Singapore_production_renewal..This is my requirement don't worry about remaining...fileds please paste a sample code...
Vamshi
Denis..
this is the error i'm getting.. I think some where the trigger recursion happens here..
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger wrehoue.new_oppy caused an unexpected exception, contact your administrator: wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, wrehoue.new_oppy: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG, Name: data value too large: nani_renewal_renewal_renewal_renewal_renewal_renewal_renewal_renewal_renewal_renewal_renewal_renewal_renewal_renewal_renewal (max length=120): [Name] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: [] Trigger.wrehoue.new_oppy: line 17, column 1: []: Trigger.wrehoue.new_oppy: line 17, column 1
Awesome...what is happening to my previous code...why we created a custom field...where is my code goes in to recursion..can you please explain..
sorry for eating your time...
So you should add some check to prevent recursion. E.g. as I tell you previously the solution mught be adding new Custom Field ad fill it only in trigger or check Opp's name(edns wtih "_renewal")
Custom field you can create via web interface.
Name check could be like
trigger ContactDescription on Contact (before insert ,before update) {
for(contact myContact : Trigger.new)
{
myContact.Description='Contact Description updated by Contact description trigger';
}
}
/*Test Class*/
@iSTest
public class TestContactDescription {
static testmethod Void ContactDescriptionTest()
{
contact mytestContact =new contact();
mytestContact.LastName='Wangdo';
mytestContact.FirstName='Phunsukh';
insert myTestContact;
system.debug('new contact inserted '+myTestContact.FirstName+' '+MyTestContact.LastName);
system.assertEquals('Contact Description updated by Contact description trigger',MyTestContact.Description);
system.debug('Description updated by trigger');
myTestContact.Description='Not updated from the trigger';
update myTestContact;
system.assertNotEquals('Contact Description updated by Contact description trigger',MyTestContact.Description);
system.debug('Description not updated by trigger');
list<contact>contactList=new list<contact>();
for(Integer i=0;i<200;i++)
{
contact contact_trig=new contact();
contact_trig.LastName='Trigger ' + i;
contactList.add(contact_trig);
}
insert contactList;
system.debug('No of contacts inserted is '+contactList.size());
}
}
Thank you!