You need to sign in to do that
Don't have an account?

Update a text field based on lookup field using the Trigger??
Hi All,
I have a lookup field Proposal_RRF__c from (Resource_Requirement__c object) in the Custom object i.e. Proposal__c, based on this fields value selection i want to extract RRF_Request_By__c field from Resource_Requirement__c object but i am getting the following error:
RRFDetails: execution of AfterUpdate caused by: System.FinalException: Record is read-only:
Trigger Code:
trigger RRFDetails on Proposal__c (after update)
{
List<Id> proids = new List<Id>();
Map<Id,Id> promap = new Map<Id,Id>();
for(Proposal__c c : Trigger.new) {
proids.add(c.id);
}
List<Resource_Requirement__c> pros = [SELECT id, RRF_Request_By__c from Resource_Requirement__c where ID IN :proids];
for(Resource_Requirement__c o : pros) {
promap.put(o.id,o.RRF_Request_By__c);
}
for(Proposal__c c : Trigger.new) {
//if(c.Proposal_RRF__c != null)
//{
c.RRF_Requested_By__c = promap.get(c.RRF_Requested_By__c);
//}
}
}
You can't change the records in the trigger in an after update trigger, you have to update them anew:
E.g.
Or you could make this a before update trigger, in which case you can change the records.
All Answers
You can't change the records in the trigger in an after update trigger, you have to update them anew:
E.g.
Or you could make this a before update trigger, in which case you can change the records.
but still.. i am not able to fetch the related field from another custom object...
trigger RRFDetails on Proposal__c (after insert,after update)
{
List<Id> proids = new List<Id>();
Map<Id,string> promap = new Map<Id,string>();
for(Proposal__c c : Trigger.new) {
proids.add(c.Proposal_RRF__c);
}
List<Resource_Requirement__c> pros = [SELECT id, RRF_Request_By__c from Resource_Requirement__c where ID IN :proids];
for(Resource_Requirement__c o : pros) {
promap.put(o.id,o.RRF_Request_By__c);
}
List<Proposal__c> toUpdate=new List<Proposal__c>();
for(Proposal__c c : Trigger.new) {
Proposal__c pro=c.clone();
pro.RRF_Requested_By__c = promap.get(c.RRF_Requested_By__c);
toUpdate.add(pro);
}
}
Can you give a little more detail as to which part of the trigger isn't working? I'm assuming you aren't getting an error when it executes, but you aren't seeing the results you expect.