• Douglas Ayers
  • NEWBIE
  • 40 Points
  • Member since 2013
  • Software Architect
  • Fruit of the Loom, Inc.


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 6
    Likes Given
  • 0
    Questions
  • 15
    Replies
I have been searching for answers and testing solutions all day for this. Any help would be greatly appreciated.

We use a large number of workflow tasks that are assigned to different members of our opportunity teams depending on what stage the opportunity enters. We do not want our users to change when these tasks are due, but we also do not want tasks to be due during non business days. Both of these solutions I have solved for, but I cannot solve for both at the same time. I have a trigger in place that changes the date of tasks that fall due on Saturdays or Sundays.
trigger WeekendTasks on Task (after insert, after update)
{
for (Task tas : Trigger.new)
{
if (tas.RecordTypeID == '012i00000011lsq' && tas.ActivityDate != null)
{
Date origin = Date.newInstance(1900,1,6);
Date due = tas.ActivityDate;
Integer x = origin.daysBetween(due);
Integer day = Math.mod(x,7);
if (day < 2 )
{
Task tt = new Task
(
Id = tas.Id,
ActivityDate = (tas.ActivityDate + 1)
  );
update tt;
}
}
}
}
This works perfectly for our needs, but when I combine this with my Task Validation Rule:
AND( ISCHANGED( ActivityDate ), RecordType.Name ="RPA Auto Task" ,$Profile.Name <>"System Administrator", $Profile.Name <>"RPA Director")
My users receive this error:
 
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger WeekendTasksUpdate caused an unexpected exception, contact your administrator: WeekendTasksUpdate: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00Te000000DlLGREA3; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Only Administrators and Directors are able to change task due dates.: [ActivityDate]: Trigger.WeekendTasksUpdate: line 18, column 1".
This only happens when a workflow tasks falls on the weekends and the trigger trys to change the task due date which is prevented by my validation rule. I tried to follow Bob Buzzard's guide (http://bobbuzzard.blogspot.com/2011/11/bypass-validation-rules-from-apex.html) on setting a custom checkbox on the task but could not get this to work. I believe the issue comes because my trigger fires after update/insert, but I do not know enough about apex to fix this.

Any ideas on how to make the validation rule and trigger play nice with each other? I would love the ability to run the trigger as an admin each time, but that does not seem possible either.
I am having a problem with using named credentials for an HTTP callout.  When I follow the example in the article titled, "Spring '15 - Simplify Authenticated Apex Callouts by Specifying Named Credentials as Endpoints" (https://help.salesforce.com/HTViewSolution?id=000206761&language=en_US" target="_blank), I get a 401 Unauthorized error from the server I'm trying to connect to.
I used Runscope to inspect the headers being sent to the server from Salesforce, and it seems that using named credentials is leaving off the "Basic" prefix from the Authorization header's value.  For example, if your username is "abc" and your password is "123", using named credentials sends this in the header:
Authorization: YWJjOjEyMw==
Instead, it should be sending this for it to work:
Authorization: Basic YWJjOjEyMw==
Is this a bug with Named Credentials?
I have a custom object that has Start and End fields as datetime. I am trying to create a Visualforce email template that will be able to send an email with a .ics attachment that will use my object's Start/End fields.

I've got everything working except that my object's field values are getting output as GMT, not UTC, and the .ics format needs UTC. Here's what I've got in the template (PS, I've tried not wrapping my fields in the outputText tags, the result is the same):
DTSTART;TZID="Eastern Standard Time":<apex:outputText value="{!RelatedTo.evt__Event__r.evt__Start__c}" />
DTEND;TZID="Eastern Standard Time":<apex:outputText value="{!RelatedTo.evt__Event__r.evt__End__c}" />
Here is an example of what gets output in the resulting .ics file:
DTSTART;TZID="Eastern Standard Time":Mon Jul 06 17:00:00 GMT 2015
DTEND;TZID="Eastern Standard Time":Mon Jul 06 21:00:00 GMT 2015
How do I just get VF to output my fields in UTC? Isn't this how they are actually stored in the database, anyway??

  • August 27, 2014
  • Like
  • 1
I have been searching for answers and testing solutions all day for this. Any help would be greatly appreciated.

We use a large number of workflow tasks that are assigned to different members of our opportunity teams depending on what stage the opportunity enters. We do not want our users to change when these tasks are due, but we also do not want tasks to be due during non business days. Both of these solutions I have solved for, but I cannot solve for both at the same time. I have a trigger in place that changes the date of tasks that fall due on Saturdays or Sundays.
trigger WeekendTasks on Task (after insert, after update)
{
for (Task tas : Trigger.new)
{
if (tas.RecordTypeID == '012i00000011lsq' && tas.ActivityDate != null)
{
Date origin = Date.newInstance(1900,1,6);
Date due = tas.ActivityDate;
Integer x = origin.daysBetween(due);
Integer day = Math.mod(x,7);
if (day < 2 )
{
Task tt = new Task
(
Id = tas.Id,
ActivityDate = (tas.ActivityDate + 1)
  );
update tt;
}
}
}
}
This works perfectly for our needs, but when I combine this with my Task Validation Rule:
AND( ISCHANGED( ActivityDate ), RecordType.Name ="RPA Auto Task" ,$Profile.Name <>"System Administrator", $Profile.Name <>"RPA Director")
My users receive this error:
 
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger WeekendTasksUpdate caused an unexpected exception, contact your administrator: WeekendTasksUpdate: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id 00Te000000DlLGREA3; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Only Administrators and Directors are able to change task due dates.: [ActivityDate]: Trigger.WeekendTasksUpdate: line 18, column 1".
This only happens when a workflow tasks falls on the weekends and the trigger trys to change the task due date which is prevented by my validation rule. I tried to follow Bob Buzzard's guide (http://bobbuzzard.blogspot.com/2011/11/bypass-validation-rules-from-apex.html) on setting a custom checkbox on the task but could not get this to work. I believe the issue comes because my trigger fires after update/insert, but I do not know enough about apex to fix this.

Any ideas on how to make the validation rule and trigger play nice with each other? I would love the ability to run the trigger as an admin each time, but that does not seem possible either.
Hi,
I'm having an issue loading a basic "test" visualforce page in my summer 14 dev org.

steps to reproduce

1) login as administrator on the summer 14 org
2) create new visualforce page with name "test", leave all page content as the default. save
3) load the visualforce page using the url: https://naXX.salesforce.com/apex/test
4) blank page is displayed and url is

https://c.na17.visual.force.com/visualforce/recsession?sid=<sid removed>&inst=o&cshc=0000000qBFQ0000000KC0M&retURL=https%3A%2F%2Fc.na17.visual.force.com%2Fapex%2Ftest

I've reproduced this issue on 2 orgs.


Can anyone else reproduce it? Does anyone know what is going on?


Thank you.

Hi,

I have a custom field where is stored a 15 digits Id.
I need to build a String csv with the 18 digits version of this Id.
In my Execute anonymous window, I tried a simple

system.debug(Id.valueOf('101c00000001GWe'));

 


and got

USER_DEBUG|[2]|DEBUG|101c00000001GWeAAM

 


Wonderful, that's what I need !  But when I try to write in my class

csv += Id.valueOf(var);

 


I get an ugly

Save error: variable does not exist: Id

 



I finally did what I need by creating a variable with

Id myId = String.valueOf(var); 
csv += myId;

 


But I don't understand why the documented static method Id.valueOf works in anonymous code and not in a class ?

 

hi everyone,

i came up with a error when upload a file using Chrome. (yes, not IE)

when uploading, an error shows, but then refresh the page, the file uploaded successfully.

this error don't shows at chatter tab, but shows at Account feed, Contact feed.

 

any help would be appreciated!

Request URL:https://ap.salesforce.com/chatter/handlers
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryoXgeuyXh213NtnNr
Origin:https://ap.salesforce.com
Referer:https://ap.salesforce.com/0031000000PlXua
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
Request Payload
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="chatterFile"; filename="20131210_093634_220.tif"
Content-Type: image/tiff


------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="fileName"

20131210_093634_220
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="desc"


------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="hiddenFileName"

C:\fakepath\20131210_093634_220.tif
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="shareOption"

pvt
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="feedItemType"

ContentPost
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="entityId"

0031000000PlXua
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="feedItemVisibility"


------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="topicIds"


------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="feedType"

ENTITY
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="q"

;postFile
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="refreshRecentFiles"

false
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="token"

XxVHXM7RplnlEGEmV7osBlxOwx2cmNf62_WKf6Q8YuWFGOi03GvWyBiZerXmaM7h1f7jEXdiGZTpBGCISTJp3CKgDs7oRtpy8PJvn1sf4SzFFMLt4crjiE1h53H9E1lojc3AyDuGkunGXJ.c_7a_J7Rxk6Q=
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="fileName"

20131210_093634_220
------WebKitFormBoundaryoXgeuyXh213NtnNr
Content-Disposition: form-data; name="desc"


------WebKitFormBoundaryoXgeuyXh213NtnNr--

 

Request URL:https://ap.salesforce.com/chatter/handlers
Request Method:POST
Status Code:400 Bad Request
Request Headersview source
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:ja,en-US;q=0.8,en;q=0.6,zh-CN;q=0.4,zh;q=0.2,zh-TW;q=0.2
Authorization:xxxx
Connection:keep-alive
Content-Length:0
Cookie:web_core_geoCountry=jp; IS3_History=1386451449-1-55_0--1+1--1+5--1+7--1+10--1+18--1+25--1__0-1-5-7-10-18-25_; lastlist=/_ui/core/chatter/files/FileDetailPage; setupopen=; sid=00D10000000KCvW!ARMAQJqROF7VMuyIWQRRKAQVtnVcSm6xbgY4ma3O8qFZRjKBbUH32Zb7d_nHG1F.BSstVBQBIRdf6gtKPHg1s2cvT6j0vXBg; sid_Client=0000000wjoG0000000KCvW; clientsrc=113.36.149.11; oid=00D10000000KCvW; rememberUn=true; login=xxx@yyy.com; com.salesforce.LocaleInfo=jp; oinfo="c3RhdHVzPUZSRUUmdHlwZT0zJm9pZD0wMERFMDAwMDAwMGE1bzk="; sfdc_lv2="KxG83HhrFTMdewxwgtakJU9TRpu522YkBLTExcx+V7AVPHrtBwVF4wSLDSAgEAUQJBHtl8qQChix6Zqo5p9n8kkiDf+O7IQbMuKyAiFso9SxSJeQ3ymnzh8gy1R24QVTZZysGprdzBdasuRVIspCPFJw6GY1vGCLoZg3r0mZGNqkGgY3m45s6q"; disco=E:00DE0000000a5o9:005E0000000f2D3:0; autocomplete=1; webact=%7B%22l_vdays%22%3A1%2C%22l_visit%22%3A1386637878824%2C%22session%22%3A1386643243299%2C%22l_search%22%3A%22%22%2C%22l_dtype%22%3A%22Typed%2FBookmarked%22%2C%22l_page%22%3A%22APPX%3Aus%3Asetupmodule%22%2C%22counter%22%3A4%2C%22pv%22%3A23%2C%22f_visit%22%3A1386552061368%2C%22version%22%3A%22w172.1%22%2C%22customer%22%3A1386552061368%2C%22d%22%3A%2270130000000sUVq%22%2C%22l_cloud%22%3A%22No%20Cloud%22%2C%22seg%22%3A%22customer%3Ajp%22%2C%22db%22%3A%7B%22name%22%3A%22eiko%20design%20%26%20creation%20co%20ltd%22%2C%22size%22%3A%22%22%2C%22ind%22%3A%22manufacturing%3Amanufacturing%22%2C%22cmp%22%3A%22%22%2C%22aud%22%3A%22smb%3Amanufacturing%22%7D%2C%22doco%22%3A%7B%22name%22%3A%22%22%2C%22city%22%3A%22%22%2C%22size%22%3A%22%22%2C%22sales%22%3A%22%22%2C%22ind%22%3A%22%22%7D%2C%22elq%22%3A%2226482984-afd8-4040-a19a-ebd3379e28b1%22%2C%22developer%22%3A1386643243299%7D; s_vi=[CS]v1|29528D7E85489EA7-40000101200601D3[CE]; inst=APP1
Host:ap.salesforce.com
Origin:https://ap.salesforce.com
Referer:https://ap.salesforce.com/0031000000PlXua
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
X-Requested-With:XMLHttpRequest
Response Headersview source
Cache-Control:private
Content-Type:application/json; charset=UTF-8
Date:Tue, 10 Dec 2013 02:58:35 GMT
Transfer-Encoding:chunked

 

 

I know that it is possible to create a FeedItem using Flow (as I have done so!), but is it possible to create an @mention in the body of that FeedItem?

 

I have tried doing @[{!varManagerName}], as well as using just the Id and another number of combinations, but it doesn't seem to want to work :)

 

 

If someone can help me figure it out, I would be ecstatic. This would be an absolutely perfect solution to a process issue we are currently experiencing!

Hi,

I'm trying to generate XML via Visualforce, but visualforce is not nesting tags properly. I have got following VF page:

<apex:page standardStylesheets="false" controller="DController" contentType="application/xml#D.xls">{!xmlheader}
<apex:variable value="" var="n"/>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" 
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  <Author>SF</Author>
  <Version>15.00</Version>
 </DocumentProperties>
 <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
  <AllowPNG/>
 </OfficeDocumentSettings>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
    ...
 </ExcelWorkbook>

<Styles>
    ...
</Styles>

<Worksheet ss:Name="Objects">
    <Names>
        ...
    </Names>
    <Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="{!objectList.size+1}" x:FullColumns="1"
   x:FullRows="1">
        
      <apex:repeat value="{!objectList}" var="o">
        <Row>
            <Cell ss:StyleID="s22"><Data ss:Type="String"><apex:outputText escape="false" value="{!HTMLENCODE(o.Name)}"/></Data>
                <NamedCell ss:Name="_FilterDatabase"/></Cell>
            <Cell ss:StyleID="s22"><Data ss:Type="Number"><apex:outputText escape="false" value="{!o.R_Count__c}"/></Data>
                <NamedCell ss:Name="_FilterDatabase"/></Cell>
            <Cell ss:StyleID="s22"><Data ss:Type="Number"><apex:outputText escape="false" value="{!o.F_size__c}"/></Data>
                <NamedCell ss:Name="_FilterDatabase"/></Cell>
        </Row>
      </apex:repeat>
    </Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">   ...
 </WorksheetOptions>
</Worksheet>


<apex:outputPanel layout="none" rendered="true">
<Worksheet ss:Name="Fields">
    ...
</Worksheet>
</apex:outputPanel>

</Workbook>{!endFile}
</apex:page>

 The thing is, that outputed XML is damaged. Sometimes tags are missing and almost always some tags are ended too late. This code produces following structure:

...
<Styles>
    ...
</Styles>
<Worksheet ss:Name="Objects">
	...
	<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
	</WorksheetOptions>
  
<Worksheet ss:Name="Fields">
	...
	<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
	...
	<WorksheetOptions>
</Worksheet></Workbook>
</Worksheet>

 You can see </Worksheet> tag at end of file. I've tried to surround it with some text to see, what happens. This VF:

</WorksheetOptions>
asdf</Worksheet>asdf

 produces this in output XML:

asdf</WorksheetOptions>asdf

...

</Workbook>
</Worksheet>

 

Sometimes it helps if I surround whole section with <apex:ouputPanel layout="none"> but mostly it has no effect. Does someone has any idea?

Hey all,

 

So I am using some command buttons to execute some page redirects via page references, but I was wondering how I could specify the target for the new window. I know that outputLink has the target attribute, but I would like to stick with the default Salesforce style on the buttons and not have to recreate it myself. Right now I have resorted to using javascript because I can specify "_parent", but does anyone know how to accomplish this with a PageReference?

 

Thanks!

I am having a problem with using named credentials for an HTTP callout.  When I follow the example in the article titled, "Spring '15 - Simplify Authenticated Apex Callouts by Specifying Named Credentials as Endpoints" (https://help.salesforce.com/HTViewSolution?id=000206761&language=en_US" target="_blank), I get a 401 Unauthorized error from the server I'm trying to connect to.
I used Runscope to inspect the headers being sent to the server from Salesforce, and it seems that using named credentials is leaving off the "Basic" prefix from the Authorization header's value.  For example, if your username is "abc" and your password is "123", using named credentials sends this in the header:
Authorization: YWJjOjEyMw==
Instead, it should be sending this for it to work:
Authorization: Basic YWJjOjEyMw==
Is this a bug with Named Credentials?
Hi,
I'm having an issue loading a basic "test" visualforce page in my summer 14 dev org.

steps to reproduce

1) login as administrator on the summer 14 org
2) create new visualforce page with name "test", leave all page content as the default. save
3) load the visualforce page using the url: https://naXX.salesforce.com/apex/test
4) blank page is displayed and url is

https://c.na17.visual.force.com/visualforce/recsession?sid=<sid removed>&inst=o&cshc=0000000qBFQ0000000KC0M&retURL=https%3A%2F%2Fc.na17.visual.force.com%2Fapex%2Ftest

I've reproduced this issue on 2 orgs.


Can anyone else reproduce it? Does anyone know what is going on?


Thank you.

Hi,

I have a custom field where is stored a 15 digits Id.
I need to build a String csv with the 18 digits version of this Id.
In my Execute anonymous window, I tried a simple

system.debug(Id.valueOf('101c00000001GWe'));

 


and got

USER_DEBUG|[2]|DEBUG|101c00000001GWeAAM

 


Wonderful, that's what I need !  But when I try to write in my class

csv += Id.valueOf(var);

 


I get an ugly

Save error: variable does not exist: Id

 



I finally did what I need by creating a variable with

Id myId = String.valueOf(var); 
csv += myId;

 


But I don't understand why the documented static method Id.valueOf works in anonymous code and not in a class ?

 

Salesforce1 has a great Today page which shows the users calendar mashed up with salesforce.com. It works well when the user is not using Salesforce as their primary calendar.  However many want to use Salesforce as the primary calendar.  So - How then do you display a calendar in Salesforce1?

 

This is a hack - but an easy one which works!  Here is how to add a Salesforce calendar to Salesforce1:

 

1) Create a visualforce page "My Calendar"  Be sure to make the page available for salesforce mobile apps.  The content of the page should be:

 

<apex:page showHeader="false" sidebar="false" >

<div style="overflow:scroll; width:100%; height:100%;">
    <object type="text/html" data="https://na2.salesforce.com/00U/c?isdtp=mn"
            style="overflow:scroll; width:1200px; height:2400px;">
    </object>
</div>

</apex:page>

 

2) Add a VisualForce tab for the visualforce page called my calendar.  Ensure the users can access the tab but make it hidden.  Does not need to be mobile ready as that setting is for the Classic Mobile app.

3) Under Mobile Administration / Moble Navigation add the "My Calendar" Visualforce tab to the selected Navigation menu item.

4) Login to Salesforce1 and celebrate your job well done!

 

I hope you find this as useful as I did.

 

 

 

Background
We have activated the Multi-Currency feature in our Org. 
 

 

I read the on-line help and the document at this url and have not been able to find any pertinent information. https://na6.salesforce.com/help/doc/en/salesforce_using_multiple_currencies.pdf 

 

We are building a standalone solution on Force.com with no integration into SFDC CRM objects. 

 

 

Question:

How do we get the DATA for the conversion rates?  Does Salesforce store the daily conversion rates in a table somewhere from where we can retrieve the actual conversion rate on a particular date?  In other words, we call an SFDC API passing in the (date, from currency, to currency) and the SFDC system returns the conversion rate for that date? 

 

OR 

 

Do we have to load this data into our own org on a daily basis by calling a webservice such as the one provided by the NY Fed Reserve http://www.newyorkfed.org/markets/pilotfx.html  and write the conversion rates to the currency table provided by SFDC (manage currencies section). 

 

After all, SFDC document at the url above says the system admin maintains the currencies but it seems absurd that it would be a manual process to input each conversion rate...  what am I missing here?

 

 

 

Thanks!!

  • February 18, 2010
  • Like
  • 1
There were a few times I thought I may have been literally losing my mind trying to isolate this issue but I was finally able to nail down the steps to reproduce (and solution). Sometimes the param value is not being assign to the variable in the controller.

Here is the code to reproduce. I tried to make it as short as possible but sorry it is still a little long, see steps below code:
Code:
Page:

<apex:page controller="paramBug" > <apex:form > <apex:pageBlock > <apex:outputPanel id="table"> {!showTable} <apex:pageBlockTable value="{!opps}" var="o" rendered="{!showTable}"> <apex:column headerValue="Status"> <apex:outputPanel id="oppStatus"> <apex:outputText value="Y" rendered="{!IF(o.status = 'modified', true, false)}"/> </apex:outputPanel> </apex:column> <apex:column value="{!o.opp.Name}"/> <apex:column > <apex:facet name="header"> <apex:commandLink value="Stage" rerender="table,debug" action="{!sortTable}" status="sorting"> <apex:param value="StageName" assignTo="{!sortColumn}" /> </apex:commandLink> </apex:facet> <apex:inputField value="{!o.opp.StageName}"> <apex:actionSupport event="onchange" action="{!change}" rerender="oppStatus,buttons"> <apex:param name="oid" value="{!o.opp.id}" assignTo="{!changedOpp}" /> </apex:actionSupport> </apex:inputField> </apex:column> </apex:pageBlockTable> </apex:outputPanel> </apex:pageBlock> </apex:form> </apex:page>

Controller:

public class paramBug {

List<oppWrapper> opps = new List<oppWrapper>();
List<SelectOption> stages;
public ID changedOpp {get; set;}
public string sortColumn {get; set;}
Map<String,String> sortOrder = new Map<String,String>();

//Constructor
public paramBug(){
for(Opportunity opp : [select Id, Name, StageName from Opportunity limit 10]){
opps.add(new oppWrapper(opp));
}
}

public List<oppWrapper> getOpps(){
return opps;
}

public void change(){
for(oppWrapper o : getOpps()){
if(o.opp.Id == changedOpp){
o.status = 'modified';
}
}
}

public Boolean getShowTable(){
Boolean show = true;
if(opps.size() == 0 ){
show = false;
}
return show;
}

public void sortTable(){
transient List<oppWrapper> sortedOpps = new List<oppWrapper>();
transient Map<String, List<oppWrapper>> stringMap = new Map<String, List<oppWrapper>>();

system.debug('--------------This is the debug line to watch--------------------');
system.debug('sColumn: ' + sortColumn);

if(sortColumn == 'StageName'){
for(oppWrapper o : getOpps()){
Object oField = o.opp.get(sortColumn);
String fieldValue = (String)oField;

if(stringMap.get(fieldValue) == null) {
stringMap.put(fieldValue, new List<oppWrapper>());
}
stringMap.get(fieldValue).add(o);
}

transient List<String> keys = new List<String>(stringMap.keySet());
keys.sort();

for(String key:keys){
sortedOpps.addAll(stringMap.get(key));
}

//reverse order
if(sortOrder.get(sortColumn) == 'asc'){
sortedOpps.clear();
for(Integer i = (keys.size()-1);i >= 0; i--) {
sortedOpps.addAll(stringMap.get(keys.get(i)));
}
}

if(sortOrder.get(sortColumn) == 'asc'){
sortOrder.put(sortColumn,'desc');
}else{
sortOrder.put(sortColumn,'asc');
}

}
system.debug('sortedOpps: ' + sortedOpps);
system.debug('Opps: ' + Opps);
opps = sortedOpps;
}

public class oppWrapper{

public Opportunity opp {get; set;}
public String status {get; set;}

//Contructor
public oppWrapper(Opportunity opp){
this.opp = opp;
}
}
}

First let's show it working correctly:
1) Open up this page and open the System Log.
2) Click the Stage Name header. This passes a param to the variable "sortColumn" in the controller and calls the action method sortTable().
3) Monitoring the debug log you can see that this is correctly being passed over: line 41, column 9: sColumn: StageName

Now let's show it not working:
1) Reload the page.
2) Change the Stage of the first opp in the table. This runs the change() method in the controller and rerenders the contents of the Status column. A 'Y' should appear in the row of the edited opp.
3) Click the Stage header to sort. The table will disappear because the sort logic did not execute. If you look at the system log you can see that the param was not passed to the controller and sortColumn is null: line 41, column 9: sColumn: null

Now the fix. I don't know why or how this fixes it but it does. Simply adding the name attribute to the param component does the trick. It doesn't even matter what the name is, just as long as it is there:

Code:
Change this:
<apex:param value="StageName" assignTo="{!sortColumn}" />

to this:
<apex:param name="asdfasd" value="StageName" assignTo="{!sortColumn}" />

and it works.

So there you go. I'm pretty sure this is a bug but if it's not I'll modify the title.

-Jason




Message Edited by TehNrd on 01-16-2009 12:04 PM
  • January 16, 2009
  • Like
  • 1