+ Start a Discussion
jbardetjbardet 

Custom Button on oppty standard layout works, but not in VF page ?

 

I created a custom button for the standard Opportunity object and it works fine when I put it on a standard page layout on the opportunity, but it's not working when trying to use it in my VF page. (Action doesn't perform and I get sent to a "URL no longer exists" page).

 

Button action is essentially to check / uncheck a custom checkbox field, "RFQ_Receipt_Sent__c".

 

Any help is appreciated, hopefully just a small fix?

 

 

Custom Button (Yes_Send) Code:

{!REQUIRESCRIPT("/soap/ajax/19.0/connection.js")} 
var v=new sforce.SObject("Opportunity");
v.RFQ_Receipt_Sent__c="{!Opportunity.RFQ_Receipt_Sent__c}";
v.id = "{!Opportunity.Id}";
v.RFQ_Receipt_Sent__c=="1"

if(v.RFQ_Receipt_Sent__c=="0")
{
v.RFQ_Receipt_Sent__c='1';
result=sforce.connection.update([v]);
alert("Success! The RFQ Receipt has been sent. Click OK to return to the opportunity");
}
else if(v.RFQ_Receipt_Sent__c=="1")
{

result=sforce.connection.update([v]);
alert("Oops! It looks like an RFQ Receipt has previously been sent, so we better not send another automatically. Click OK to return to the opportunity.");
}
window.location.reload();

 

 

 

Simple VF Page:

 

<apex:page standardcontroller="Opportunity" extensions="SendRFQReceiptControl" showHeader="true" sidebar="false">
 <apex:form >

    <apex:sectionHeader title="RFQ Receipt" subtitle="Would you like to send an RFQ Receipt to {!primcontact.Name}?"/>
     <apex:commandButton action="{!URLFOR($Action.Opportunity.Yes_Send)}" value="Yes Send Email Now"/>
      <apex:commandButton action="{!cancel}" value="No - Return to Opportunity"/>

 </apex:form>
</apex:page>

 

 

Controller (used to grab oppty's primary contact info)

 

public class SendRFQReceiptControl {
    public final Contact primContact {get; set;}
    public final Opportunity o {get; set;}
    public SendRFQReceiptControl(ApexPages.StandardController controller) {
        this.o=(Opportunity)controller.getrecord();
        try{
            ID primContactid = [select id,contactid from opportunitycontactrole where opportunityid=:o.id and isprimary=true LIMIT 1].contactid;
            primContact = [select id,name from contact where id=:primContactid limit 1];
        }catch(QueryException qe){
            system.debug('ERROR Querying contact:'+qe.getmessage());
        }
    }

}

 

Best Answer chosen by Admin (Salesforce Developers) 
Mitesh SuraMitesh Sura

Jeremy,

 

As per the documentation, $Action global variable works for standard actions, create, edit, delete, clone, etc. I don't think it works with custom actions. That would be neat though. 

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_action.htm

 

You will have to move the logic in controller. 

All Answers

AneeshaAneesha

I think the problem is with this piece of code in your VF page

 

{!URLFOR($Action.Opportunity.Yes_Send)}

 Try creating a function in the controller to update the field and then reroute to the opportunity. Replace the action function on the commandbutton accordingly.

jbardetjbardet

yes, that is the key piece wrong considering the button action is not working.

 

However, if possible, I'd like to leverage the action created on the custom button rather than rewriting it into the controller. But if what I'm doing is improper, I'll give it a shot, and any help is always appreciated!

 

Kudos, thanks.

Mitesh SuraMitesh Sura

Jeremy,

 

As per the documentation, $Action global variable works for standard actions, create, edit, delete, clone, etc. I don't think it works with custom actions. That would be neat though. 

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global_action.htm

 

You will have to move the logic in controller. 

This was selected as the best answer
jbardetjbardet

Thank you! The path to be on is now clear, just gotta find my way now!

 

Best,


Jeremy