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
John BraunJohn Braun 

Creating a trigger...

Hi there,

 

I just recently posted a question regarding accomplishing a scenario with an Onclick Javascript custom button. After thinking it through further, I've decided that it may not be the best route to take.

 

The scenario is as follows:

 

We are re-designing the request a quote process from our opportunity record. My original idea was that we could really make this easy for the sales team by doing the following:

 

1. Create a custom button (either visualforce button that called a custom controller, or an Onclick Javascript button)

2. Pressing the button would update fields on the opportunity and also create a new related quote record.

3. Based on the actions from #2, we could create workflow that would alert the appropriate people, track date stamps, etc.

 

The problem with this method is that our validation requirements are too great, there are mutiple things that need to be true or populated on the opportunity record before a quote can be requested.

 

So, to me, that rules out the following:

 

1. Onclick Javascript button - we can't do this, because we really need to highlight the fields for the user so they can quickly figure out what they need to do to successfully request a quote. The prompt that you can make show up with the javascript button is not as intutive as highlighting each field in red.

2. If we created a Visualforce button that called a custom controller that did all of the same actions as described above, we run into the same issue, because this would occur before any validation rules could fire, and we need the validation rules to highlight any required fields that the user failed to populate before making the quote request. My understanding is that you could do this, but you would have to rebuild the entire opportunity page in visualforce, but we don't want that level of effort of maintenance (please correct me if i'm wrong on this one)

 

With that said, it sounds like we really only have one option:

 

1. Create a checkbox called, "Request a Quote"

2. Enforce that all criteria is met with validation rules before save

3. Have a trigger that upon save, creates the related quote record

 

 

So, I'm looking for confirmation on all that I've stated above. It would be really nice to make a "Request a Quote" button that the user could just press and it perform all the actions described - but from what I've read, there's no way to use salesforce.com validation rules when doing that. And the only way to mimic the validation rule functionality would be to rebuild the opportunity page as a visualforce page.

 

Finally, If all of the above can be confirmed, I was hoping to get help on how to write this trigger, as I am a complete newbie. The trigger would just need to do the following:

 

When the opportunity record was saved, and the "request a quote" checkbox was true:

 

1. Create a related quote record

2. Autopopulate the quote name with either "PQ" or "CQ", based on a picklist we would have on the opportunity

3. If a quote had already been created for this opportunity, there would be some sort of prompt or error that would say, "A Quote has already been requested for this Opportunity" (This is because we do all quote revisioning from the quote level itself).

 

This is a pretty lenghthy read/question, so I greatly appreciate anybody willing to offer help/advice, thanks!!!!

Saurabh DuaSaurabh Dua

Well as far as my understanding you want a button which creates a quote under opportunity.  But if the required fields are not filled up in opportunity it should alert the user to fill them up.

 

This is simple to achieve. Use javascript in the button to check whether the required fields are filled in .Use a variable say counter and set the value to 0. If the fields are not filled in the set the counter to 1 .  

 

After checking all the fields check the value of counter . if the counter equals 0 call the class which perform the action required ie creation of a quote else alert ('Enter the required field')..

 

 

If you want i can give the code for it..

John BraunJohn Braun

Saurabh,

 

Thank you so much for the reply -

 

Would this alert be able to highlight specifically the fields on the page layout for which the user would need to populate (like how a validation rule works)? Or only list the fields required in the popup box alert?

 

The code would be greatly appreciated, I'm no where close to being a developer.

Saurabh DuaSaurabh Dua

Yes the alert will only list the fields required in the popup box alert

 

Shortly ill be posting a sample code which u can use as per your requirements

John BraunJohn Braun

Thanks so much for the help!