function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KB KimKB Kim 

field update to create product

Please, share your trigger and test code if you have simmillar one for this requirement.

When a user select a product picklist from a custom field (product__c) on an opportunity, it should create a opportunity product on its related list.
Also, when a user create a opportunity product from the related list, the product__C field on the opportunity should be updated.

We will have only one product for each opportunity.

Truly, thanks for any comments and helps, in advance.
 
Best Answer chosen by KB Kim
salesforce mesalesforce me
hi check this once...
 
If you created the custom Product Family field on the Opportunity Product object as a Picklist, you'll need to create a rule and action for each value that you have for the Product Family field.  For example, this checks to see if the product family field on the product record is "Services".  If yes, it triggers a field update.
workflow rule formula:
IsPickval( Product2.Family , "Services")  

field update: 
Object = "Opportunity Product"
Field to Update = "Product Family"
New Field Value = "Services"
If you created the custom Product Family field on the Opportunity Product object as a text field, you should only need one rule/action.
workflow rule formula:
 product_family__c = ""    'checking to see if product family field on new opp product record is blank.
field update:
Object = "Opportunity Product"
Field to Update = "Product Family"
Update Formula: if product family field is "Services", opp product family field is "Services". If it's "Products", set the field to "Products".  Otherwise, default it to "Labour".
if( ispickval(Product2.Family, "Services"),"Services",
if(ispickval(Product2.Family, "Products"), "Products",
"Labour"
)
)