You need to sign in to do that
Don't have an account?
Vidya Rani
For new records: Copying value from previous record in trigger.
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);
}
}
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);
}
}
Tried with :System.debug('Listvalue' + listaToTrue.get(0)); whereever applicable, still errors.
I think m also missing update command.
Line 40 is showing null values.Any suggestions.