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
NathalieNathalie 

Inline s-control to display account data on opportunity page ?

I have very limited programing skills and would like feedback telling me if what we are trying to do can be done or not.
 
There's a "Negotiated discount rate" field on Accounts. We need to make sure reps aren't giving more discount than what was negotiated, or if they need to, make sure their manager has approved such discount. How can we compare the discount entered by a rep against the discount on the account record ? I thought of an s-control that could go grab the account's discount and then do a simple validation... Can such s-control run as soon as the Account lookup field is populated on an opportunity record, in edit mode ? If not, what would you suggest to be a good user-friendly process to grab the account's discount and compare it against the discount entered on a new opportunity record ?
 
Note that we can't overwrite the create new opportunity button on the account page to pre-fill data on the opportunity record. Users have to create opportunities from various objects depending on the type of opportunity (such as from a Project custom object). Ideally, we'd like a process that would work for any scenario, no matter the starting point of the new opportunity.
 
Many thanks for your help !
 
sean33043sean33043

It looks like you will want to use the triggers functionality. Here is a basic example of what the trigger might look like.:

Code:

/* Before an opportunity is saved, compare the quoted rate on this 
   opportunity to the max rate on the account for this opportunities
*/

trigger checkQuotedRate on Opportunity (before insert, before update) {
   /* get the max rate for this account */
   Double max_discount = [ select Discount_Rate__c from Account where Id =: Trigger.new[0].AccountId ].Discount_Rate__c;
   if(Trigger.new[0].Quoted_Discount_Rate__c > max_discount ){
      /* do stuff here to process a rate quoted too high */
      /* —–˜ Change stage to "pending approval", create approval task, etc */ 
      Trigger.new[0].Quoted_Discount_Rate__c.addError('Quoted rate higher than allowed.');
   } else {
      /* do stuff here when rate is at or lower than allowed */ 
      /* or do nothing */
      /* Trigger.new[0].Quoted_Discount_Rate__c.addError('Rate OK'); */

   }
}


 
Using this method requires testing and development in your sandbox before it can be added to your live instance.

This is a start. Hope it helps.

Sean Shannon

 

NathalieNathalie
Many thanks Sean ! Works like a charm :smileyvery-happy: