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

trigger to update lookup field value from picklist value
i figured this should be pretty simple. I have a custom object called ONSITE_PRODUCT__c
onsite_product__c has a lookup field called product__c which has a lookup relationship to the salesforce products object.
ive created a new picklist field called New_products__c which also has a list of the same products as the product__c lookup field. I want a user to select a product from the New_products__c picklist and have that same product value saved as the product lookup field value.
heres my trigger
trigger UpdateOnsiteProduct on Onsite_Product__c (before insert,before update) {
{
for (Onsite_Product__c a : Trigger.new)
{
a.Product__c = a.New_Products__c;
}
}
}
and this is the error i keep receiving
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UpdateOnsiteProduct caused an unexpected exception, contact your administrator: UpdateOnsiteProduct: data changed by trigger for field Product: id value of incorrect type: XYZ PRODUCT
Thanks.
When dealing with a lookup field, you are going to want to set the value of the field to the Id of the record you are attempting to relate it to. Your trigger should look something like this:
All Answers
When dealing with a lookup field, you are going to want to set the value of the field to the Id of the record you are attempting to relate it to. Your trigger should look something like this:
thanks for this. i think we're real close, im not sure which should be onsite_product__c and which should be product__c
onsite_product__c is the object, product__c is the lookup field
Error: Compile Error: sObject type 'Product__c' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 5 column 24
I think I'm understanding you better now, try this...
the tigger code in the last 2 posts looks the same. is that right?
im bombing out here
Compile error at line 12 column 39
Variable does not exist: New_Products__c
if i change line 12 to
i get
Compile error at line 11 column 9
Illegal assignment from SOBJECT:Product2 to Id