+ Start a Discussion
ArjunmcaArjunmca 

Trigger Error: 'Record is read-only'.

Hi,

 

I am getting read only error. How to fix this?

 

 

trigger BankDBSS_Update_Comments on BankDBSS__c (after insert , after update)
{
   Bank_DBSS_Support__c obj= new Bank_DBSS_Support__c();

   for(BankDBSS__c dbssComments: trigger.new)
   {
    
      if(Trigger.isUpdate)
      {

           if(dbssComments.Comments__c !=NULL)
           {
                obj.Analyst_Comments_History__c = dbssComments.Comments__c;
                obj.Analyst_Comments_Date__c = system.now();
           }
           if(dbssComments.Project_Comments__c !=NULL)
           {
                obj.Project_Comments_History__c = dbssComments.Project_Comments__c;
                obj.Project_Comments_Date__c = system.now();
  
           }
           if(dbssComments.Project_War__c !=NULL)
           {
                obj.Project_War_History__c = dbssComments.Project_War__c;
                obj.Project_War_Date__c = system.now();
            }
           insert obj;
       }

  }

 

}

 

kiranmutturukiranmutturu
try with before insert and before update
kiranmutturukiranmutturu
try this
trigger BankDBSS_Update_Comments on BankDBSS__c (before insert , before update)
{
Bank_DBSS_Support__c obj= new Bank_DBSS_Support__c();
list<Bank_DBSS_Support__c> lst = new list<Bank_DBSS_Support__c>();

for(BankDBSS__c dbssComments: trigger.new)
{

if(Trigger.isUpdate)
{

if(dbssComments.Comments__c !=NULL)
{
obj.Analyst_Comments_History__c = dbssComments.Comments__c;
obj.Analyst_Comments_Date__c = system.now();
}
if(dbssComments.Project_Comments__c !=NULL)
{
obj.Project_Comments_History__c = dbssComments.Project_Comments__c;
obj.Project_Comments_Date__c = system.now();

}
if(dbssComments.Project_War__c !=NULL)
{
obj.Project_War_History__c = dbssComments.Project_War__c;
obj.Project_War_Date__c = system.now();
}

lst.add(obj);
//insert obj;
}
}

if(!lst.isempty())
insert lst;

}
Ankit AroraAnkit Arora

 insert obj; is the problem, you are inserting the record which is currently in process by trigger. You can't perform any DML on the record which is in trigger process.

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

 

ArjunmcaArjunmca

kiran_mutturu wrote:
try this
trigger BankDBSS_Update_Comments on BankDBSS__c (before insert , before update)
{
Bank_DBSS_Support__c obj= new Bank_DBSS_Support__c();
list<Bank_DBSS_Support__c> lst = new list<Bank_DBSS_Support__c>();

for(BankDBSS__c dbssComments: trigger.new)
{

if(Trigger.isUpdate)
{

if(dbssComments.Comments__c !=NULL)
{
obj.Analyst_Comments_History__c = dbssComments.Comments__c;
obj.Analyst_Comments_Date__c = system.now();
}
if(dbssComments.Project_Comments__c !=NULL)
{
obj.Project_Comments_History__c = dbssComments.Project_Comments__c;
obj.Project_Comments_Date__c = system.now();

}
if(dbssComments.Project_War__c !=NULL)
{
obj.Project_War_History__c = dbssComments.Project_War__c;
obj.Project_War_Date__c = system.now();
}

lst.add(obj);
//insert obj;
}
}

if(!lst.isempty())
insert lst;

}


Hi,

 

Thanks for the response. with your code i am not getting read only error but data is not inserting into the Bank_DBSS_Support__c table.

 

BankDBSS_C is the main table, Bank_DBSS_Support__c is child table based on ID__C field.

I want to insert BankDBSS__c.comment__c into Bank_DBSS_Support_c.comment__c. That's it.

 

Please remind that i am not inserting comments in the main(same) object, i want to insert comments in the other object after inserting record in the main object.

 

Please let me know how to do that.