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
RajanRajan 

Trigger Problem for Opportunity object

Hi friends,
I am facing problem for writing a trigger. Condition is as below:
This is for Apportunity object. Whenever I am creating an apportunity and saving the record then The Product detail should display with price under Product section of detail page. I have created Price book for all items as below.

Picklist field is --  Business category and values are Product and  Service.
Dependent picklist (on business category) field is - Select product is - Product (BPMS and Lhetto) and for service (Java, Dot Net, salesforce)
For product, there is another field Licence which contains Unit Licence and Enterprise.

After saving the selected items in all these 3 fields, then the respective product or service with price shoud displace in Product section of the record detail page.
Kevin CrossKevin Cross
what is the problem you are facing with the trigger?  i.e., what is the code you have thus far?  If you post what you have and the error you are getting, we can help you sort it out here.
RajanRajan
I am trying general concept like creating any contact with saving any account record. But problem here is 2 dependent picklists. So unable to write exact code for this. Please suggest me to how to write trigger in this case for dependent picklists.
Kevin CrossKevin Cross
Just nest your conditions.

For example, if Business Category is Business_Category__c, Select Product is Select_Prodct__c, and License is License__c, then your code may look something like this.  

if (Business_Category__c == 'Product') {
  // do product-specific code here
  if (Select_Product__c == 'BPMS') {
    // do something else special here
  }
}

if (Business_Category__c == 'Service') {
  // do same thing for services
}

Note: strings also can use string1.equals("Test String") or string1.equalsIgnoreCase("Test STRING") if you run into issues.

Remember at the trigger level you already have the data going to the database, so the fact that the picklists are dependent does not matter as much (if your worry is how to handle when they are visible).  You just care to only check a field if it is proper condition, so you avoid nulls or blanks.

Hope that makes sense.