You need to sign in to do that
Don't have an account?
Harshi_Pandey
Update Lookup field of a custom object with trigger 'after insert'
Hello All,
I have a custom object SoldProducts__c which is related to its parent object SalesStock_Items__c as a lookup relationship.
I want to update the lookup field
'SalesStock_Item__c' present in SoldProducts__c custom object with the SalesStock_Items__c Item Names i.e., the auto numbers generated like - 'SS-001, SS-002 ' in SalesStock_Items__c parent object whenever a new record is inserted in the SoldProducts__c child object.
I tried the below trigger code:
Can anyone please help me how i can proceed in this case?
I have a custom object SoldProducts__c which is related to its parent object SalesStock_Items__c as a lookup relationship.
I want to update the lookup field
'SalesStock_Item__c' present in SoldProducts__c custom object with the SalesStock_Items__c Item Names i.e., the auto numbers generated like - 'SS-001, SS-002 ' in SalesStock_Items__c parent object whenever a new record is inserted in the SoldProducts__c child object.
I tried the below trigger code:
trigger SoldProduct on SoldProducts__c (after insert) { Map<String,Id> soldp = new Map<String,Id>(); for(SoldProducts__c s : [Select Id, Items__c from SoldProducts__c where Id IN :trigger.new]) { soldp.put(s.Items__c ,s.Id); } SalesStock_Items__c sprod = [Select Id, Name from SalesStock_Items__c where Name IN:soldp.keyset()]; for(SoldProducts__c opp: Trigger.new) { opp.SalesStock_Item__c = sprod.Id ; } }But I am getting the below error :
Can anyone please help me how i can proceed in this case?
Try Below Trigger Please Mark it As best Answer If It Helps
Thank You!
All Answers
Try Below Trigger Please Mark it As best Answer If It Helps
Thank You!