Skip to main content
In case of record creation,am trying to copy value in field "Next call Notes" from a previous record (created by same user on same Account). Unbale to create new record saying : Record is read-only: Trigger.CopyCallNotes: line 26, column 1

Below is code piece. Any help will bereally helpful.

trigger CopyCallNotes on Call__c (after insert, after update) {

public String CurrAcc;

public Id CurrCreatedBy;

 for(Call__c c: Trigger.new){

        CurrAcc = c.Account__c;

        CurrCreatedBy = c.CreatedById;

        System.debug('CAccount' + c.Account__c);

        System.debug('CCreatedBy' + c.CreatedById);

        System.debug('CName' + c.Name);

        System.debug('CId' + c.Id);

                      } 

List<Call__c> listaToTrue = new List<Call__c>([select Next_Call_Notes__c from Call__c where Account__c = : CurrAcc and CreatedById = :CurrCreatedBy order by CreatedDate desc LIMIT 2]);

       System.debug('ListSize' + listaToTrue.size());

       System.debug('Listvalue' + listaToTrue.get(1)); 

   String NCN = string.valueOf(listaToTrue.get(1).Next_Call_Notes__c);

   System.debug('NCNvalue' + NCN);

        for(Call__c a: Trigger.new){

         a.Next_Call_Notes__c = NCN;   // line 26

         System.debug('CNCN' + a.Next_Call_Notes__c);

         }                   

                      

}
답변 4개
  1. 2018년 6월 27일 오후 7:17

    I have failed to figure out some aspects of your code. As a result I have not been able to bulkify the trigger. Try this:

    trigger CopyCallNotes on Call__c (before insert, before update) {

    public String CurrAcc;

    public Id CurrCreatedBy;

    for(Call__c c: Trigger.new){

    accountIds.add(c.Account__c);

    CreatedByIds.add(c.CreatedById;);

    CurrAcc = c.Account__c;

    CurrCreatedBy = c.CreatedById;

    System.debug('CAccount' + c.Account__c);

    System.debug('CCreatedBy' + c.CreatedById);

    System.debug('CName' + c.Name);

    System.debug('CId' + c.Id);

    List<Call__c> listaToTrue = new List<Call__c>([select Next_Call_Notes__c from Call__c where Account__c = : CurrAcc and CreatedById = :CurrCreatedBy order by CreatedDate desc LIMIT 2]);

    System.debug('ListSize' + listaToTrue.size());

    System.debug('Listvalue' + listaToTrue.get(0));

    String NCN = string.valueOf(listaToTrue.get(0).Next_Call_Notes__c);

    c.Next_Call_Notes__c = NCN;

    System.debug('CNCN' + c.Next_Call_Notes__c);

    }

    }

     
0/9000