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
smrkepwaresmrkepware 

Custom Button not working on Visualforce Page

I created a Visualforce page to override the standard case view page.  I have a custom button on the standard view page that launches an email template with some of the fields values pass in the URL.  The button works fine on the standard case view page, but not on my visualforce page.  Does anyone have any idea why this button does not work on the visualforce page I created?  When I click on it, I get a "URL No Longer Exists" error.

 

Custom Button Code: Execute JavaScript, OnClick JavaScript.

 

location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=00X40000000tisK');

 

Code for Button on VisualForce page used to override case view.

 

<apex:commandButton action="{!URLFOR($Action.Case.Email_Solution,Case.id)}" value="Reply"/>

Ankit AroraAnkit Arora

Hi,

 

Not sure but try this :

 

window.location.href = '/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=00X40000000tisK';

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

smrkepwaresmrkepware

I tried using window.location.href instead of location.replace and I am still getting the same URL No Longer Exits message.

 

If it makes any difference, I am developing the new visualforce page and custom button in a Full Sandbox environment.

SteveBowerSteveBower

windows.location.href expects an absolute URL (http://something.salesforce.com/email/... etc).

 

You can try windows.location.href.pathname for setting a relative path.   Best, Steve.

smrkepwaresmrkepware

I tried window.location.href.pathname as well with the same results.  I am pretty sure that the button is not being loaded correctly by visualforce or the Javascript is not executed properly in the button when launched from a visualforce page.  I even tried hardcoding a path to google.com using window.location.href as a test,  and still got the URL No Longer Exists page.  If I manually construct the path with the IDs and paste it into my browser it works fine, but it doesn't work when launched from the visualforce page.  Again, this button works perfectly when called from the standard case page with the same code that fails when lauched from the visualforce page.  I have spent several days trying to get this to work.

SteveBowerSteveBower

A few things: 

1. HAve you turned on the Javascript console in the browser.  Does it report any errors?

2. Have you used "view source" to inspect the HTML/Javascript that has been generated for your VF page.  Often that can point you to something that isn't what you expected.

3. Now that I'm reading your initial post, I'm a little confused:

 

You're overriding the default Case View page with your own VF.   Ok, got that.   Now, in that VF page you've defined a button which I presume is this:

 

<apex:commandButton action="{!URLFOR($Action.Case.Email_Solution,Case.id)}" value="Reply"/>

 

Is this the button that's not working?   Where does $Action.Case.Email_Solution come from?  I didn't recall that from the list of Actions and I just went and looked and it's not there.  So, perhaps that's the problem?   Perhaps you want $Action.Activity.SendEmail?

 

 

Where did this:

location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=00X40000000tisK');

come into the picture?  If this your goal is to recreate the e=mail URL that Salesforce generates, the URL I just got is:

 

https://na4.salesforce.com/_ui/core/email/author/EmailAuthor?p2_lkid=0033000000BjLS0&rtype=003&p3_lkid=500300000014gqF&retURL=/500300000014gqF

 

In which case you're missing a leading "_ui/core/" from your URL?   But, I think you should do it with the $Action as above.

 

Hope this helps, Steve.

smrkepwaresmrkepware

Hi Steve,

 

Thank you for your response.

 

1. I tried turning on the Javascript console in the browser and it did not report any errors,

 

2. I viewed the source code for the VF Page.  It does not appear that the custom button I am defining is any different then other buttons on the VF page that do work. 

 

For example,

 

The Delete button works and looks like this in the code.

<input type="submit" name="j_id0:j_id2:j_id3:j_id4:j_id6" value="Delete" class="btn" />

 

My Custom button Reply does not work, but looks similar in the source code.

<input type="submit" name="j_id0:j_id2:j_id3:j_id4:j_id8" value="Reply" class="btn" />

 

3. The button that is not working is defined on the VF page with the following code.

<apex:commandButton action="{!URLFOR($Action.Case.Email_Solution,Case.id)}" value="Reply"/>

 

This code works fine on the Standard case view page, but not on the VF page.  $Action.Case.Email_Solution points to the custom button that I defined named Email_Solution.  This button uses Javascript to pass the Case Id, Contact Id, and Template Id for the email. 

 

location.replace('/email/author/emailauthor.jsp?retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=00X40000000tisK');  is the JavaScript code in the custom button named Email_Solution.

 

I tried using the action that you suggested,  $Action.Activity.SendEmail, on the VF page.  After changing this, the Reply button opened a "Send an Email" task, but the To field was not set, the Related To field was set to Account instead of Case, the email template I wanted to use was not selected,  and therefore the subject line and body was not filled in with the information that is contained in the email template.

 

I also tried adding "/_ui/core/" to the path and still received the "URL No Longer Exists" page.

 

Any other ideas?

 

 

 

SteveBowerSteveBower

Well, I don't think you can define your own actions merely by creating new buttons. 

 

I think you need to be exploring how to use the sendmail action and pass the parameters you want...    

 

So, go down the road of exploring:

 

<apex:commandButton action="{!URLFOR($Action.Activity.SendEmail,null,[retURL=/{!Case.Id}&p3_lkid={!Case.Id}&rtype=003&p2_lkid={!Case.ContactId}&template_id=00X40000000tisK')])}" value="Reply"/>

 

, and forget the definition of your own custom button.

 

Best, Steve.

SayasoniSayasoni

Hi,

Am trying to implelement the same.Any luck in getting it done?