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

Query by Product Family?

I wrote a trigger that adds schedule items to opportunity products when they're created, based on which product they are, how many are purchased, and for what duration. Our company has two different types of products right now: enterprise products and services. In my trigger, I need to handle the services differently than the enterprise products. They way I have been handling that is with an if statement that catches them by ID:

ID OnboardingPBE = [select id from PricebookEntry where'Onboarding' LIMIT 1].id;
ID TrainingPBE = [select id from PricebookEntry where'Training' LIMIT 1].id;

if(oli.PricebookEntryId == OnboardingPBE || oli.PricebookEntryId == TrainingPBE)

This logic is broken for some reason, and the above if statement never runs. Furthermore, it would be more efficient if I could figure out a way to just enter the if statement based on whether product family == 'services'...Is there a way I can do this?

If you need to see my whole trigger, I can upload it here. 

I want it to look something like this:

oli is an OpportunityLineItem

if(oli.Product2.Family == 'Services'){
do something