You need to sign in to do that
Don't have an account?
sairam nama
i'm unable to delete the record it's showing the error as execution of AfterUpdate caused by: System.SObjectException: DML statement cannot operate on trigger.new or trigger.old: Trigger.candidatescheduleforinterview: line 22, column 1 mt trigger is
trigger candidatescheduleforinterview on schedule__c (after update)
{
LIST<schedule__c>lstsch=new list<schedule__c>();
List<Follow_Up_2__c>lstfu2=new list<Follow_Up_2__c>();
for(schedule__c sc : trigger.old)
{
if(sc.Follow_up_1__c=='Answered/Intrested')
{
lstsch.add(sc);
follow_up_2__c fu2= new follow_up_2__c();
fu2.Name=sc.Name;
fu2.Domine__c=sc.Domine__c;
fu2.EMail_ID__c=sc.EMail_ID__c;
fu2.LastName__c=sc.LastName__c;
fu2.Mobile__c=sc.Mobile__c;
lstfu2.add(fu2);
}
}
if(lstsch.size()>0)
{
insert lstfu2;
delete lstsch;
i want delete record in schedule object and insert it in followup2 object can any one help me in it?
{
LIST<schedule__c>lstsch=new list<schedule__c>();
List<Follow_Up_2__c>lstfu2=new list<Follow_Up_2__c>();
for(schedule__c sc : trigger.old)
{
if(sc.Follow_up_1__c=='Answered/Intrested')
{
lstsch.add(sc);
follow_up_2__c fu2= new follow_up_2__c();
fu2.Name=sc.Name;
fu2.Domine__c=sc.Domine__c;
fu2.EMail_ID__c=sc.EMail_ID__c;
fu2.LastName__c=sc.LastName__c;
fu2.Mobile__c=sc.Mobile__c;
lstfu2.add(fu2);
}
}
if(lstsch.size()>0)
{
insert lstfu2;
delete lstsch;
i want delete record in schedule object and insert it in followup2 object can any one help me in it?
add it to list -> lstSh.add(scRec);
and delete this list -> delete lstSh;
Do this in after trigger.
All Answers
If you use After Trigger, then the record which initiated the trigger will be read only until the completion of the Trigger transaction. So you won't be able to perform any DML on that particular record.
If this trigger is running on only Update event then i would suggest you to use Before Trigger instead of After Trigger event. And then try the same code you are using.
Please let me know if it works or you need any more assistance.
Mark this as the solution if it solves your purpose.
Thanks,
Jainam Contractor,
Salesforce Consultant
Varasi LLC
www.varasi.com
add it to list -> lstSh.add(scRec);
and delete this list -> delete lstSh;
Do this in after trigger.
its working