• rtuttle
  • 118 Points
  • Member since 2009

  • Chatter
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 107

I have overridden the "new" and "edit" buttons for a custom object with a Visualforce page / Apex extension.  The constructor of the extension gets the "retURL" parameter from the currentPage().getParameters() like so:



theOpp = [select Id, Name, (select Id, Account__c, Opportunity__c, Role__c from Partners2__r) from Opportunity where Id = :ApexPages.currentPage().getParameters().get('retURL').substring(1) limit 1];



I have confirmed that all buttons available to our users to get to this screen always contain /OPPORTUNITYID as the retURL and thus I am just removing the slash and using the Id to query an Opportunity.


The problem is that it is randomly producing errors... stating the retURL parameter is null.  Then the same user can go back and try again and it works... totally sporadic.  So I am thinking maybe the constructor is running "too quickly" so the parameter isn't established yet?  Possibly I need to make this call in the "Action" of the page instead?  Any help is appreciated!



im trying to create a trigger to prevent users from adding comments on closed cases.


this is my code:


trigger CloseComment on CaseComment (before insert) {

for (CaseComment t: Trigger.new)
Case c = new Case(Id = t.ParentId);

if(c.Status == 'Closed' && c.Process__c == 'Payroll')
t.addError(c.Process__c + 'case closed' + c.Status);
t.addError(c.Process__c + 'case open' + c.Status);


but i can't get the values of any case fields. I guess im missing something simple.


Any ideas?

Message Edited by MiguelGuerreiro on 01-14-2010 09:20 AM

I have a small form with an <apex:inputFile> in which I am trying to upload an attachment.


<apex:form id="form_Upload">
<apex:inputFile id="file_File" value="{!fileBody}" filename="{!fileName}" size="60"/>
<apex:commandButton id="button_Upload" value="Upload"

onclick="if (!validateUploadForm())return" action="{!processUpload}" />


Because I have an onclick JavaScript handler specified for the commandButton, the "action" never occurs (i.e. the Ajax call that would normally be inserted into the onclick never gets inserted) so my HTML source says ony onclick="if (!validate etc...)".


I've found that the way to solve this is to add a rerender="" attribute to the commandButton. Since I don't need to rerender anything, I created an empty outputPanel, and added that to the rerender of the commandButton like this:


<apex:commandButton rerender="panel_Empty" ... />


Well that fixed the problem, because now the generated onclick for the commandButton called my JavaScript onclick then called the Ajax submit method. So far so good....


The problem is that when I run this page, I get a runtime error that says that the <apex:inputFile> cannot be used with a commandButton that specifies a rerender attribute.


Is this deliberately like this, or is it a bug?






Hi Friends,


One issue that i am facing to display the attachments related to an object on a VisualForce page is making me think that can we use the standard attachment View URL on a visualforce page.


URL is this:




Can someone clarify this please??




PS: Whenever i use this link on my VF page, my URL gets broken in IE redirecting me to "https://cs2.salesforce.com/apex"


Has anyone figured a way to work around this error when instantiating using a StandardSetController with a QueryLocator?  I've tried creating a get method for the controller object that pulls a record inside of a try catch block, but this error seems to happen before the controller is ever touched.


Edit:  This only happens after 15 minutes of idle usage.  If after that point someone tries to call a method on the StandardSetController it throws an uncatchable exception.


Here is what I attempted to catch this exception to no avail:



public ApexPages.StandardSetController controller {

get {

if(this.controller!=null) {

try {

//Integer x = controller.getPageSize(); // attempt to trigger the timed out query locator exception

SObject s = controller.getRecords()[0];

return controller;

} catch(Exception e) {




String parentId = QuickCaseUtil.getParameter('id');

if(parentId != '') {

this.controller = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT CreatedDate, Content__c,Identifier__c,Title__c,ThreadType__c FROM CaseThread__c WHERE Case__c = :parentId ORDER BY CreatedDate DESC]));

} else {

this.controller = null;


return controller;





 Edit:  Fixed code box which seems to hate Chrome


Message Edited by rtuttle on 02-18-2010 01:46 PM
Message Edited by rtuttle on 02-22-2010 02:48 PM
Message Edited by rtuttle on 02-22-2010 02:48 PM


I'm trying to reproduce in APEX this PHP example :

= pack("H*", $key);
echo strtoupper
(hash_hmac('sha512',"ABC", $binkey));


or this Java example :

privateString generateHMAC(String datas )

//                final Charset asciiCs = Charset.forName( "utf-8" );
Mac mac;
String result ="";
            finalSecretKeySpec secretKey = newSecretKeySpec( DatatypeConverter.parseHexBinary(CONSTANTS.KEY),"HmacSHA512");
.init( secretKey );
finalbyte[] macData = mac.doFinal( datas.getBytes());
byte[] hex =newHex().encode( macData );
=newString( hex,"ISO-8859-1");

return result.toUpperCase();



This is my APEX code :

private String hmacFunction(String str, String k) {
    Blob mac = Crypto.generateMac('hmacSHA512', Blob.valueOf(str), Blob.valueOf(k));
    return EncodingUtil.convertToHex(mac).toUpperCase();


This is no good, for the moment : encrypted strings match between Java and PHP, not with APEX.

The result for ABC should be :



Obviously, the difficulty lies in the pack('H*, key) conversion which seems to be different from the Blob.valueOf(key) call.



Can anyone help ?





   I wrote a trigger agnist Feeditem .The problem is , When any other user writes a feed to me then the trigger gets fired but when I write my own(I.e when I change my status) the trigger is not fired . Also when I update any object (That I selected for feed tracking) the trigger is not fired .

   Please help me with this.

Hi guys,

I have a fieldset called "States" with all 51 us states: AL__c, AR__c, AZ__c, CA__c, etc...

Now I want to add all field values and labels to an item list like this (this is pseudo-code):


for( <fieldset-element> : <all fieldset-elements>)


items.add(<fieldset-element>.value, <fieldset-element>.label);



How can I do that in Apex?



Josh :-)

Hey guys,


I have a visualforce page, and I'm including several other visualforce pages within it.  Each of these pages have access restrictions based on different profiles (some people can use only 1 of the included pages, some can use 2, etc...).  If I include them all on the same page, then users will get the standard Access Restricted message for pages that aren't available to them.


Instead I'd rather not render the page at all if a user's profile does not give them access to it, so they don't see the error message.  I could do some silly "If user.profile == A or B or C..." logic, but I'd rather not have to edit the code every time some new profile needs access to a new page.


Basically I'm wondering if there's a way in either the Visualforce page or the controller to tell if a person has access to a page, sort of like how you can check for Object accessibility with {!$ObjectType.objectname.accessible}.


Also open to other suggestions if there's a better way.  I'm new to the force ecosystem so I may just be missing something simple.



DISCLAIMER : JQuery Novice !

I have a beefy Visualforce Page with some Jquery - had a question about refreshing a div being used to render as a jquery dialog.


Here's a pseudo structure of my page


<Jquery Dialog Definition>




iterate over a list of objects

Edit  Button on Click = invoke JS to launch the dialog, rerender=div



<div display-none dialog>

displays details of the element on which the Edit button is clicked in the repeat above.



Now my question is how do I refresh this dialog to reflect the details of the element on which the Edit was clicked. Although my Edit Button onClick uses Javascript remoting to set the selected element id on the controller, the dialog box never refreshes to show this content. rerender doesnt seem to cut it. Anyone know how does one refresh a section which was originally rendered (not visible though) as part of the original page.


So clearly IE9 is causing some major headaches with Visualforce. Rerenders completely broke with IE9 but forcing the browser to run in compatibilty mode is a decent short term fix: http://boards.developerforce.com/t5/Visualforce-Development/Ajax-doesn-t-work-in-IE9/td-p/259049 . This works great.... unless the page is being served from an iframe. If it is the hack won't work and the page breaks anytime a rerender is performed. This means inline VF pages still don't have a work around and any pages you may have in other iframes won't work with IE9.


This is a serious problem for us as we have several webforms integrated into other sites with iframes.


Here is some code and pages to reproduce. This page has the IE9 hack fix and works okay.





<apex:page controller="IERerenderBug" showHeader="false" standardStylesheets="false">
    <apex:form >
        <apex:commandButton value="Go" action="{!doSomething}" reRender="output" status="status"/>
        <apex:actionStatus id="status">
            <apex:facet name="start">
                Doing something...
        <apex:outputPanel id="output">



public class IERerenderBug {

    public IERerenderBug(){
        //IE9 Visualforce hack
        String browserType = Apexpages.currentPage().getHeaders().get('USER-AGENT'); //gets the browser name 
        if(browserType != null && browserType.contains('MSIE')){
            Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8');
    public void doSomething() {

    public Integer getTime(){
        return system.now().second();

The above works fine but if that page is in an iframe somewhere else the hack does not work:



<apex:page showHeader="false">
    This is an iframe of IEBug page... hack doesn't work if page is in an iframe.
    <iframe width="100%" height="200" frameborder="1" src="{!$Page.IEBug}"></iframe>


Does anyone know of any tricks or hacks to get this working when the page is in an iframe?




  • March 23, 2011
  • Like
  • 0

Something strange is going on and I can't figure it out. Data binding to variables in an Apex controller is not working if the <apex:input> tags are within a jQuery UI Dialog box. I've confirmed action method executes when called from a dialog box and rerenders are working but data binding is not. Unfortunately all else I can can provide is this very simple page to reproduce and then hope someone can help figure this out.




<apex:page controller="JQDialog">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"/>
    <apex:stylesheet value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/themes/ui-lightness/jquery-ui.css"/>
    <script type="text/javascript">
        var j$ = jQuery.noConflict();
            //Creat modal
    <apex:outputPanel id="count">
        Count: {!count} <br/>
        Checkbox: {!myCheckBox} <br/>
        String: {!myString}
    <apex:form >
        <div id="popup">
            <apex:inputCheckbox value="{!myCheckbox}"/> <br/>
            <apex:inputText value="{!myString}"/> <br/>
            <apex:commandButton value="Do Something" action="{!doSomething}" rerender="count" oncomplete="closeModal();"/>



public class JQDialog {

    public Integer count {get; set;}
    public Boolean myCheckbox {get; set;}
    public String myString {get; set;}
    public JQDialog(){
        count = 0;

    public void doSomething(){







  • January 07, 2011
  • Like
  • 0

Apex provides supports for convert String to Hex value but not the Hex value to String. Can you help me on this.


Thank you