You need to sign in to do that
Don't have an account?
CodeBee
Can we set id to lookup field via trigger ?
Good day,
Could we set the lookup field with id ? for instance, i have a Opportunity product, which have lookup relationship to product, when i save oppty product, it getting value of product's myStoreID field and save it to Opportunity product lookup field.
Thanks in advance !
Yes definitly you can do this with trigger. You need to write a before inser trigger on opportunity product. If you have any problem I can help you in wrtting it, just provide me a bit more information about your requirement. You can check my blog also for writting trigger.
Thanks !
When i try following for before insert trigger, i hit error, what wrong with trigger.oldmap.keyset() ?
In before triggers trigger.oldmap and trigger.old are not available as it is before insert and how would be there a old value.
And another thing is that in before triggers you will not get ID as Ids are generated after insert.
let me ask if any issue in above explaination.
Hi Shashikant Sharma,
What i need to accomplish is , after i inserted a record to OpportunityLineItem , i also need to find out a field that store an id - storeId from other objectA, by getting that value from the store id field , i will need to query it based on the value i get from another OBjectB, so how can i accomplish this ?
What is the raltionship between OpportunityLineItem , ObjectA and ObjectB let me know, you can see this post
http://boards.developerforce.com/t5/Apex-Code-Development/Trigger-not-updating-lookup-field/td-p/306915 please see is it similar to your requirement. If it is not just provide me some more information , relationship , field APIName , Object APIName . I can try to write trigger for you.
Ignore above mentioned object relationship , i get myself confuse and what i need to do is to get productid value from pricebookentry.
Here is what i try to do in "After Insert " trigger, apparently OpportunityLineItem not allow to save it own object. not sure how can i do this with before Insert trigger.
trigger myTrigger on (after insert){
for(OpportunityLineItem opptyLineItem : trigger.new){
opptyLineItem.myProduct__c = opptyLineItem.pricebookentry.product2id;
}
}
after i get the product2Id value, i'll need to update the lookup field call "MyProduct__c" in OpportunityLineItem itself.
try this I hope it will work for you
you were trying to access related object field from trigger.new list's object which will always give null value. Let me know if any issue in above trigger.