Add Reprice Action to Edit Opportunity Page

Add an action in the Edit Opportunity page that salespeople can use to retrieve updated prices.

  1. In Application Composer, navigate to Standard Objects > Opportunity > Actions and Links.

  2. Click the Create icon.

  3. In the Opportunity: Create Action or Link page, in the Display Label field, enter Reprice Opportunity. As you click away from the Display Label field, the Name field automatically populates with the internal name.

  4. In the Type field, ensure that Action is selected.

  5. In the Script region, click the New icon.

  6. In the Create Object Function page, in the Function Name field, enter RepriceOpty.

  7. In the Edit Script region, enter this script:

    def revenueItems = ChildRevenue
    def pricebook = nvl (PriceBook_Obj_c, null)
    if (pricebook == null)
    return
    def priceBookId = pricebook?.getAttribute("PricebookId")
    
    def view_PriceBookItem = newView('PriceBookItem')
    def view_Criteria = newViewCriteria(view_PriceBookItem)
    def view_criteria_row = view_Criteria.createRow()
    def view_condition = view_criteria_row.ensureCriteriaItem('InvItemId')
    view_condition.setOperator('=')
    
    
    view_Criteria.insertRow(view_criteria_row)
    view_PriceBookItem.appendViewCriteria(view_Criteria)
    def view_condition_1 = view_criteria_row.ensureCriteriaItem('PricebookId')
    view_condition_1.setOperator('=')
    view_condition_1.setValue(priceBookId)
    while (revenueItems.hasNext()) {
    def revenueLine = revenueItems.next()
    def itemid= nvl(revenueLine.InventoryItemId, 0L)
    def invorgid = nvl (revenueLine.InventoryOrgId, 0L)
    view_condition.setValue(itemid)
    //1,400 is the number of records in the system; change this number according to your system records.
    view_PriceBookItem.setMaxFetchSize(1400) 
    view_PriceBookItem.executeQuery()
    while(view_PriceBookItem.hasNext()){
    def var_Row = view_PriceBookItem.next()
    
    //Get the price from PriceBookItem for the item you want:
    revenueLine.setAttribute('UnitPrice', var_Row.getAttribute('ListPrice'))}
    }
  8. Click Save and Close.

  9. Back in the Opportunity: Actions and Links page, click Save.

  10. Verify the action was created by going to Opportunity > Server Scripts > Object Functions. If you still don't see it, sign out and back in.
  11. Add the action to the opportunity details page: Navigate to Opportunity > Pages.

  12. Ensure that the Application Pages tab is selected.

  13. In the Opportunity: Pages page, find the Details Page Layouts region. Duplicate the standard layout and then name and edit the copy.

  14. In the Details Layout page, at the top right of the page next to the Actions drop-down list, click the Edit icon.

  15. In the Buttons and Actions page, find the action you created and move it to from the Available Actions shuttle area to the Selected Actions shuttle area.

  16. Click Save and Close.

  17. Click Done.