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
Mony Gueorguiev 11Mony Gueorguiev 11 

Visualforce and Custom Button for Record Update - How/Help?!

Hey Guys,

Im tasked with creating a Button that updates the related record on a Case/Ticket quick action area that we have in our instance. This button should provide fields for update on the Proposal (PPS Proposals object name) that is attached to that Ticket. So it's an Update button. 

The user needs to have the option to update only a few fields on that record. -

Proposal Status (Picklist)
Core Estimated Hours (Number)
Core Estimated Fees (Currency)
Core Discount (Currency)
One-Time Solution Fee (Currency)
Add-On Estimated Hours (Number)
Add-On Estimated Fees (Currency)
Add-On Discount (Currency)
Type (Picklist)


I have never done this before and could use some (any?) help! Is this even possible? 

Mony
 
Mony Gueorguiev 11Mony Gueorguiev 11
 Hey Amit,

Thanks for the links. They are helpful and getting me on the right track. I'm not sure how to create a visualforce page that is loaded with JUST those fields above. Those fields are from a our custom object. Those are the only fields that need to be updated by the user once they click on the "button". 

What would be the best way to start, or just create, a visual force page that has those fields available? A simple page.

Thank you!! I appreciate any help.

Mony
Nithesh NNithesh N
Can you provide the fieldnames (api) of those custom object fields and custom object name along with their __c trail.
So that i can make a sample visual force page for you.
Mony Gueorguiev 11Mony Gueorguiev 11
I think its also worth noting, there is an Opportunity attached to each Ticket. On the Opportunity attached is where the PPS Proposals exist. There can be more than 1 Proposal but ONLY 1 is the Primary PPS Proposal. That is designated by a checkbox field...called Primary - API Name: Primary_Old__c

The record that the user gets taken to from clicking the button should be the Primary PPS Proposal related to that Opportunity on the Ticket.

The custom object that they exist on, and to which the user should be taken to is, PPS_Proposal__c

Fields are:

Proposal_Status__c
Core_Estimated_Hours__c
Core_Estimated_Fees__c
Core_Discount__c
One_Time_Solution_Fee__c
Add_On_Estimated_Hours__c
Add_On_Estimated_Fees__c
Add_On_Discount__c
Type__c


 
Nithesh NNithesh N
This is a Simple visualforce template that I created, This user can simply edit the mentioned fields of that custom object and upon clicking 'save' command button, the record will be updated.

Make changes accordingly to suit your needs.
 
<apex:page standardController="PPS_Proposal__c">
 <apex:form>
    <apex:pageBlock title="Update Proposal" mode="edit">
      <apex:pageBlockButtons>
        <apex:commandButton action="{!save}" value="Save"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="" columns="2">
        <apex:inputField value="{!PPS_Proposal__c.Proposal_Status__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Core_Estimated_Hours__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Core_Estimated_Fees__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Core_Discount__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.One_Time_Solution_Fee__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Add_On_Estimated_Hours__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Add_On_Estimated_Fees__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Add_On_Discount__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Type__c}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>

 
Mony Gueorguiev 11Mony Gueorguiev 11
Wow thats awesome! How can I get this to show up as a VisualForce page on the Ticket/Case object? When I go to the button that I have created on the ticket/case and select VisualForce pages, the Content dropdown does not have the VisualForce page that I saved with that code?
Mony Gueorguiev 11Mony Gueorguiev 11
So just to clarify, this PPS Proposal should be the Primary PPS Proposal on the Opportunity that is attached to the Case object record. The Primary PPS Proposal is designated by a field called Pimary_Old__c and is a checkbox field, so it needs to be checked for it to be the Primary record, and there can only be 1 primary pps proposal on an opportunity, ...thats the record that needs to be edited.
 
Nithesh NNithesh N
That's because, the visual force page is using PPS_Proposal__c standard controller instead Case Standard controller. So, the dropdown doesnt list the visualforce page.

To Make it work, you need a Custom Controller.
Mony Gueorguiev 11Mony Gueorguiev 11
Hey Nitesh,

Thank you. How do I make a Custom Controller and then incorporate it so that the visualforce page is visible?

Mony Gueorguiev
Nithesh NNithesh N
There is another workaround i guess, Instead of visualforce button type, Try changing it to url type button.
And Use the below formula (Change it accordingly). This one takes your to the visualforcepage from the different object(Oppotunity in this case) as long as that PPS Proposal Id is one of the fields of that object.
 
{!URLFOR("/apex/YourPageName", null, [id= Opportunity.PrimaryProposalId)}
So, make sure you have Primary Proposal Id on your opportunity object.
 
Mony Gueorguiev 11Mony Gueorguiev 11
I see, I am trying this right now. There is no primary proposal ID field though. Since Primary is just a checkbox field on the Proposal I created a formula Proposal ID field that pulls the ID for records that only have the Primary checkbox checked. 

That exists on the Proposal object. The Update Proposal button with the visualforce page needs to be on the Case object. So I am trying to pull the new formula ID field for the Proposal all the way through the Case record, but am unsuccessful so far, since its across objects, its hard to figure out. Once I do find a way, I believe the URL hack you sent will work.
Mony Gueorguiev 11Mony Gueorguiev 11
Hey that worked! Awesome job! I was able to tweak it and figure it out. 

One last thing, is there any way to make the pop up window close after clicking Save?


Mony
Nithesh NNithesh N
Cool, I am afraid the answer is again Controller Extension or Custom Controller. 
For this, we need to overide a standard controller action (save , in this case) using an extension.
As i don't have your metadata in my org, I couldnt check for errors in the code. But in essence This code should point you in the right direction.

Visualforce Page Code (You need to tweak it accordingly)
<apex:page standardController="PPS_Proposal__c" extension="customPopupExt">
 
    <style type="text/css">

        .popup
        {
            background-color: white;
            border-width: 2px;
            border-style: solid;
            z-index: 9999;
            left: 50%;
            padding:10px;
            position: absolute;
            width: 500px;
            margin-left: -250px;
            top:80px;
        }

        .popupBg
        {
            background-color:black;
            opacity: 0.20;
            filter: alpha(opacity = 70);
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 9998;
        }

    </style>
    
    <apex:form>
    <apex:pageBlock title="Update Proposal" mode="edit">
    <apex:pageMessages />
      <apex:pageBlockButtons>
        <apex:commandButton action="{!save}" value="Save" rerender="popup"/>
      </apex:pageBlockButtons>
      <apex:pageBlockSection title="" columns="2">
        <apex:inputField value="{!PPS_Proposal__c.Proposal_Status__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Core_Estimated_Hours__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Core_Estimated_Fees__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Core_Discount__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.One_Time_Solution_Fee__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Add_On_Estimated_Hours__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Add_On_Estimated_Fees__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Add_On_Discount__c}"/>
        <apex:inputField value="{!PPS_Proposal__c.Type__c}"/>
      </apex:pageBlockSection>
    </apex:pageBlock>
        
        <apex:outputPanel id="popup"> // Your PopUp
        <apex:outputPanel styleClass="popupBg" layout="block" rendered="{!getPopupApproval}"/>
            <apex:outputPanel styleClass="popup" layout="block" rendered="{!getPopupApproval}">
                Popup window
                <apex:commandButton value="Hide" action="{!closePopup}" rerender="popup"/>
            </apex:outputPanel>
        </apex:outputPanel>
  </apex:form>
</apex:page>

And The Extension Code Will be like this (You need to tweak it accordingly),
 
// Extension Class  
public with sharing class customPopupExt 
{
    //Global Variables
    private final PPS_Proposal__c finalProposal;
    public Boolean showPopup = false;
    //End of Global Variables
    
    // Standard Controller Constructor
    public customPopupExt(ApexPages.StandardController controller) 
    {
        this.finalProposal =(PPS_Proposal__c) controller.getrecord();
    }
    // End of Standard Controller Constructor 
    
    // Method Called on to Update Proposal
    Public PageReference save()
    {
        try
        {
            update finalProposal;
            this.showPopup = true;
        }
        catch(System.DMLException e)
        {
            return null;
        }
        Return NULL; //If you want to stay on same page after clicking save.
    }
    // End of Method 
    
    Public Boolean getPopupApproval{
        return this.showPopup;
        //This decides whether to show your popup or not
    }
    
    public PageReference closePopup()
    {       
        this.showPopup = false;   // once you click hide button on the popup, this will be fired
        PageReference ppsPage = new ApexPages.StandardController(PPS_Proposal__c).view();
        ppsPage.setRedirect(true); //sending the user to PPS Object record.
        return ppsPage;
    }    
}

If you find my code helpful, please mark my solution as Best Solution.  Hope it works for you.

 
Mony Gueorguiev 11Mony Gueorguiev 11
Hey,

Thanks so much for that. Thats quite a lot! I will try to go over this and make the necessary changes, it will probably take me a few days/tries in order to get it right. 

I will update you! Thank you so much for your help so far, its been awesome!
B SreenivasuluB Sreenivasulu
Hi Nithesh,

Your code not working. it will showing  like Error: Unsupported attribute extension in <apex:page>
Nithesh NNithesh N
Just a typo Error 

Change
<apex:page standardController="PPS_Proposal__c" extension="customPopupExt">
to
 
<apex:page standardController="PPS_Proposal__c" extensions="customPopupExt">

As i dont have your metadata with me, I didnt do the error checking, Please make the changes accordingly . The code i provided can be used as a template for your referrence.