You need to sign in to do that
Don't have an account?
Please help want regarding Lookup field update problem
Hi,
Help!! Help!! Please help me if anyone knows how to update the lookup field within the Object according to associeted Id from another object..
trigger updateLookup on Sales_Order__c (after insert, before update) {
// Store all changed sales order object
Map<Id,Id> salesOrder = new Map<Id,Id>();
for(Sales_Order__c s : Trigger.new){
salesOrder.put(s.Id, s.OwnerId);
}
// Create a map of all of the log created according to triggered Sales Order.
Map<Id,Id> createdLog = new Map<Id,Id>();
for(ConnectCompiere_Log__c log : [select Id, Name from ConnectCompiere_Log__c where Id in :salesOrder.values()]) {
createdLog.put(log.Id, log.Name);
}
// Update the sales order lookup field.
for (Sales_Order__c sales: Trigger.new){
sales.Lookup_Log__c = createdLog.get(sales.Id);
}
}
I am getting the error like updateLookup: execution of AfterInsert caused by: System.Exception: Record is read-only: Trigger.updateLookup: line 19, column 13
This error is in the last for loop.
:smileymad:
Please help me.
Please help me anyone who knows Lookup field update.
Is that Lookup field is read-only?
Why I can't update the Lookup field with the corresponding Id of the another object?
Thanks in advance.
Hi,
Here is the solution.
Object One :- ParentObject : Contains Ref field of child object : Field API Name :- ChildObjectRef__c
Object Two :- ChildObject
Trigger on ParentObject
ParentObejctClass
All Answers
Hi,
logic is same for both the condition i.e. after insert and before update?
If yes
you can directly put the value in salesOrder field no need to call update on salesOrder.
i.e. salesOrder.ConnectCompiere_Log__c = log.id
I did not get your point. There salesOrder is an object, not a field. As per your suggestion code won't work.
But logic is same for both conditions. Can u suggest me in what way I can update the lookup field. It would be better if you provide some code snippsets.
:smileysad: :smileysad: :smileysad:
Please help me anyone who knows updating the lookup field in one object with associated Id of record in another object.
Thanks in advance.
If I remove the after insert, that will work fine. But still I am not getting the result what I expect. Below I will explain what I need. Please give me the solution.
1) I have to trigger the Sales_Order__c object which contains lookup field with including other field.
2) I have to create the new log records in ConnectCompaiere_Log_C (log custom object) bsed on some field missing conditions in Sales_Order__c . (This process is already done).
3) After that I have to update the newly created log record(Name or Id) to the lookup field in corresponding Sales_Order__c record.
Please provide some details, how I can update the lookup field of Sales_Order__c object.
Thanks for your previous reply.
Please Please Please help me for my above scenario...........
:smileymad: :smileymad: :smileysad::smileysad:
I am keep watching for any kind of suggestion or help........................
Please Please!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hi,
Here is the solution.
Object One :- ParentObject : Contains Ref field of child object : Field API Name :- ChildObjectRef__c
Object Two :- ChildObject
Trigger on ParentObject
ParentObejctClass
Thanks you very very much Naishadh. Since I was trying from Last 4-5 days. But I could not figured out. You have resolved my problem. This will helps lot many peoples. Thanks for your great help!!!!!!!
:smileytongue: :smileyvery-happy: