• rtuttle
  • NEWBIE
  • 118 Points
  • Member since 2009

  • Chatter
    Feed
  • 4
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 107
    Replies

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!

hello,

 

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);
}
else
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}" />
</apex:form>

 

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?

 

Thanks,

Andrew

 

 

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:

 

https://cs2.salesforce.com/servlet/servlet.FileDownload?file=(FileName)

 

Can someone clarify this please??

 

Cool_D

 

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) {

System.debug(LoggingLevel.INFO,e.getMessage());

}

}

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;

}

set;

}

 

 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

Hi,

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

<?php 
$key
="0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
$binkey
= 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 ="";
       
try
       
{
            finalSecretKeySpec secretKey = newSecretKeySpec( DatatypeConverter.parseHexBinary(CONSTANTS.KEY),"HmacSHA512");
            mac
=Mac.getInstance("HmacSHA512");
            mac
.init( secretKey );
           
finalbyte[] macData = mac.doFinal( datas.getBytes());
           
byte[] hex =newHex().encode( macData );
            result
=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 :

100A6A016A4B21AE120851D51C93B293D95B7D8A44B16ACBEFC2D1C9DF02B6F54FA3C2D6802E52FED5DF8652DDD244788A204682D2D1CE861FDA4E67F2792643

 

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

 

 

Can anyone help ?

 

Rup

 

 

   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?

 

Thanks

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.

 

Thanks!

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>

 

 

<apex:repeat>

iterate over a list of objects

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

</apex:repeat>

 

<div display-none dialog>

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

</div>

 

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.

 

http://f5.test.cs1.force.com/iebug

Page:

 

<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:facet>
        </apex:actionStatus>
    
        <apex:outputPanel id="output">
            {!time}
        </apex:outputPanel>
    </apex:form>
</apex:page>

Controller:

 

public class IERerenderBug {

    //Contructor
    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() {
       system.debug('something');
    }

    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:

http://f5.test.cs1.force.com/IEiframe

Page:

<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>
</apex:page

 

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

 

Thanks,

Jason

  • 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.

 

Page:

 

<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();
        
        j$(document).ready(function(){
            //Creat modal
            j$("#popup").dialog();
        });
    </script>
    
    <apex:outputPanel id="count">
        Count: {!count} <br/>
        Checkbox: {!myCheckBox} <br/>
        String: {!myString}
    </apex:outputPanel>
    
    <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();"/>
        </div>
    </apex:form>
</apex:page>

 Controller:

 

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(){
        count++;
    }
}

 

 

Thanks,

Jason

 

 

  • 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