You need to sign in to do that
Don't have an account?
Pranav Chitrans
trigger error while inserting new record
plz help with this error... It perfectly works with the update scenario.. but when i insert any new account it throws error
ERROR : Apex trigger Pranav.CheckboxUpdate caused an unexpected exception, contact your administrator: Pranav.CheckboxUpdate: execution of BeforeInsert caused by: System.StringException: Invalid id: populate: Trigger.Pranav.CheckboxUpdate: line 8, column 1
ERROR : Apex trigger Pranav.CheckboxUpdate caused an unexpected exception, contact your administrator: Pranav.CheckboxUpdate: execution of BeforeInsert caused by: System.StringException: Invalid id: populate: Trigger.Pranav.CheckboxUpdate: line 8, column 1
trigger CheckboxUpdate on Account (before insert,after insert ,after update) { List<Contact> cnlist = new List<Contact>(); if(trigger.isbefore && trigger.isInsert) { for(Account ac : trigger.new) { ac.Contact_Custom_Lookup__c = ac.name; } } if(trigger.isInsert && trigger.isAfter) { for(account ac:trigger.new) { Contact c= new Contact(); c.Accountid=ac.id; c.Lastname=ac.Name; c.Checkbox__c=ac.Checkbox__c; cnlist.add(c); } Insert cnlist; } if(trigger.isupdate) { for(account ac:trigger.new) { List<Contact> cn=[select id from contact Where accountid IN :trigger.new ]; for(integer i=0;i<cn.size();i++) { cn[i].Checkbox__c=ac.Checkbox__c; } cnlist.addall(cn); } update cnlist; } }
ac.Contact_Custom_Lookup__c = ac.name;
Please let us know if this will help you.