• parkerAPT
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 24
    Replies

can anyone tell me how to update a column of  a table through apex classes?

 

I have created a method for updating and i used update(list type variable) command. It is throwing a run time error like "Illegal view ID update. The ID must begin with / "

 

what does this mean? please suggest...

I'm struggling with the order-of-execution during a VisualForce AJAX postback request and the appropriate way to nest-components that might need to rerender each other.

 

The documentation (http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_postback_request.htm ) has 4 key steps:

 

  1. View Deserialization
  2. Evaluate expressions and all method calls including those on custom component controllers
  3. Evaluate the action that triggered the postback
  4. Render view -> HTML sent to browser

 

I'm getting frustrated by the second step, specifically all method calls.  From what it appears, any public methods (specifically a getter) that are used in a view are called before the action method gets call even if these methods are not binding anything in the View State.

 

The example below illustrates that getDisplayedList method gets called immediately after view state deserialization and then again during the rendering of the view.  In my toy example, I lazy-load a list of strings based on the iCount member variable.  In my real-world application I'm actually using a SOQL query to dynamically fetch a list of S-Objects to display to the user. 

 

 

<apex:page controller="LazyLoadController">

<apex:form id="theWrapper">
	<apex:repeat value="{!DisplayedList}" var="s">
		{!s}
	</apex:repeat>
	
	<apex:commandLink value="refresh" rerender="theWrapper" />
	
	<div>
	iCount : <b>{!iCount}</b>
	</div>
</apex:form>

</apex:page>

public with sharing class LazyLoadController {

	public LazyLoadController(){
		this.iCount = 5;
	}

	public Integer iCount {get; set;}
	
	private Transient List<String> t_theList;
	
	// I want to be able to gurantee getDisplayedList() only gets executed during the rendering of the Component and not during "Postback" validation
	public List<String> getDisplayedList(){
		if(this.t_theList == null){
			// The real use case would Query the Database for the appropriate objects.
			
			this.t_theList = new List<String>();
			for(Integer i=0 ; i< this.iCount; i++){
				this.t_theList.add('[' + String.valueOf(i) + ']');
			}
		}
		iCount++;
		return this.t_theList;
	}
	
	
	public PageReference refresh(){
		// In theory I want to be able to execute code here that is guranteed to be executed before getDisplayedList
		return null;
	}
}

 

Unfortuntaely, because getDisplayedList gets called before I execute any code in my post-back method, I do not have the opportunity to do any additional logic before the Transient list of strings ( t_theList) gets initalized.

 

One quick and obvious solution would be to set the Transient list to null in the postback method and force the list to be regenerated or remove the lazy-loading indirection and initalize the list directly.

 

I typically would do this except for the fact I want this controller to be a component-controller that can be easily dynamically rerendered.  I've outlined the at the high-level what I want to do below.

 

 

<apex:page controller="ParentController">
	<!-- Code that will create a new Task and 
		re-render the component that should display 
		a list containing the newly created task 
		-->
	<apex:commandLink value="addNewTaskAndRefreshList" rerender="componentWrapper" />
	
	<apex:outputPanel id="componentWrapper">
		<c:lazyLoadComponent 
			countOfTasks=5/>
		</c:lazyLoadComponent>
	</apex:outputPanel>
	
</apex:page>

 

public with sharing class ParentController {
	public PageReference addNewTaskAndRefreshList(){
		Task t = new Task();
		//...
		insert t;
		return null;
	}
}

 

 

Pretend for example, that my LazyLoadController is now displaying a list of tasks that are dynamically loaded from the database.  I'd like to be able to put this component onto my page and re-render it so that it dynamically refreshes the list of Tasks.  For example, in the ParentController I want to insert a new task, refresh the child-component and display the new task.  Currently, the Lazy-Loading happens in Step 2 (method calls) of the order of execution before Step 3 (Invoke PostBack method).

 

Does anyone have a suggestion for how I can re-design my code so that I can achieve the above behavior?

 

Thanks

Parker

 

Is there a way to get a handle on the PageReference that corresponds to the New / Edit / Delete actions for SObjects.

 

In Visualforce, you can get the URL by using the URLFOR function:

 

 

<apex:commandButton value="New"action="{!URLFOR($Action.Gathering__c.New, null, [cid=theContact.id])}"/>

 This will properly take me to the New Gathering__c page.

 

Can I get at this in Apex?  Something like:

 

PageReference pageRef = ApexPages.Action.Gathering__c.New;

pageRef.getParameters().put(cid, theContact.id);ApexPages.Action ac = ApexPages.Action.Gathering__c.New;

 Neither of these work like the Page.Custom_Apex_Page

 

Is the only solution to override the New / Edit Views and make a custom Apex Page / Controller?

 

Thanks 

 

 

 

 

I'm seeing some a strange error in a custom visualforce page that has a Standard Set Controller using a QueryLocator.

 

Overview:

The visualforce page shows an error of "Invalid variant 'parent': value 'Contact'"

The main culprit is calling the StandardSetController setPageSize method

 

Code Example:

 

public class BuggedPageController {
public ApexPages.StandardSetController setController { get; set; }
public Contact m_theContact{get;set;}

public BuggedPageController(Apexpages.StandardController asControl){
m_theContact = (Contact) asControl.getRecord();
// There are zero accounts with the name oxxoxo
setController = new ApexPages.StandardSetController(database.getQueryLocator([SELECT name,id,Owner.Name FROM Account WHERE name='oxxoxo']));
//if(this.setController.getResultSize() > 0 ){
this.setController.setPageSize(5);
//}
}

public List<Account> TheAccounts{
get{
return (List<Account>) this.setController.getRecords();
}
}
}

 

<apex:page standardController="Contact" extensions="BuggedPageController">

<apex:dataList value="{!TheAccounts}" var="oAccount">
<apex:outputText value="{!oAccount.name}"></apex:outputText>
</apex:dataList>

</apex:page>

 

 Detail Explanation and Weird Behavior:

  • Depending on the standard controller, the error message differs.  For example, if the standardController is of type "Task" and the appropriate changes are made in the BuggedPagController, the error message reads: Invalid variant 'parent': value 'Task'

  • When you do not specify an ID in the URL the error does not occur.  However, the standardSetController returns a list of all Accounts.
    • That is to say:
    • The URL: https://c.cs1.visual.force.com/apex/demoBuggedTableBinding?id=003S0000002rsfJ throws the error
    • The URL: https://c.cs1.visual.force.com/apex/demoBuggedTableBinding does not throw an error but shows the top 5 Accounts in the list.
  • The root cause lies somewhere in the setController.setPageSize(5) method call
    • If I comment this method call out or only call it when there are records available, the error does not occur when an ID is specified in the URL
    • If I comment this method call out when there is NOT an ID in the url, the Visualforce page does not display the top 5 Accounts.  It appropriately shows zero.
  • Inside a Unit Test, none of these errors occur:  That is to say, I can construct a BuggedPageController and thus call setPageSize when a QueryLocator returns no records without throwing an error.

 

Current Work Around:

  • Always wrap setPageSize in the following if Block:
  •  

    if(this.setController.getResultSize() > 0 ){
    this.setController.setPageSize(5);
    }

     

Related Forum Posts:

 SetPage Size ignored Where Clause

 

 

Message Edited by parkerAPT on 05-15-2009 10:38 AM

There is a small error in the documentation for the <apex:componentBody> tag.

 

The example code for the custom component is the following:

 

<!-- Component: myaccounts-->
<apex:component controller="myAccountsCon">
<apex:attribute name="var" type="String" description="The variable to represent a single account in the iteration."/>
<apex:repeat var="componentAccount" value="{!accounts}">
<apex:componentBody >
<apex:variable var="a" value="{!componentAccount}"/>
<apex:outputPanel style="border:1px solid black;" layout="block">
{!componentAccount.name}
</apex:outputPanel>
</apex:componentBody>
</apex:repeat>
</apex:component>

 

The entire example works because you use "a.name" in apex:ComponentBody even though you should be able to pass in and use any variable name you'd like.  The lines that need to be changed to make this work are:

 

<apex:componentBody >
<apex:variable var="a" value="{!componentAccount}"/>

 

I've made the changes to make the componentBody after the variable tag and changed the variable name to that passed in via the "var" attribute in the component:

 

 

<apex:component controller="myAccountsCon">
<apex:attribute name="var" type="String"
description="The variable to represent a single account in the iteration." />
<apex:repeat var="componentAccount" value="{!accounts}">
<apex:variable var="{!var}" value="{!componentAccount}" />
<apex:componentBody >
<apex:outputPanel style="border:1px solid black;" layout="block">
{!componentAccount.name}
</apex:outputPanel>
</apex:componentBody>
</apex:repeat>
</apex:component>

 

 

Hope this helps anyone trying to use componentBody within custom components!

 

ps- Can you have components with custom Facets?

 

Parker

 

 

 

 

 

 

I'm trying to write an Apex Controller that will modify all of the contacts that are part of a campaign.
I want to do this asynchronously so that the user does not need to click and wait for the processing to take place.

I've tried implementing this as @future method but am running into the limit of 10,000 rows when there are more than 5,000 campaign members.
I hit this limit because I have to query all of the CampaignMembers (5,000) and then query and update all of the contacts (5,000).

I thought that @future methods did not have these kinds of DML limitations because they were executing asynchronously.

If that is not the case, can anyone suggest another way to modify all of the Contacts that are part of a Campaign?

Thanks alot.  I've attached the code as an example.
 

public class CampaignController { public Campaign theCampaign { get; set; } public CampaignController(ApexPages.StandardController stdController) { this.theCampaign = (Campaign)stdController.getRecord(); } public PageReference publishCampaign() { CampaignMananger.FlagCampaignMembersWithTag(this.theCampaign.id); return null; }}global class CampaignMananger { @future public static void FlagCampaignMembersWithTag(ID campaignID){ for(List<CampaignMember> membersC : [Select c.Status, c.Id, c.ContactId, c.CampaignId From CampaignMember c WHERE c.CampaignId = :campaignID ]) { List<ID> theContactIds = new List<ID>(); for(CampaignMember cm : membersC){ theContactIds.add(cm.ContactId); } List<Contact> theContacts = [SELECT c.id, c.CustomTag__c FROM Contact c where c.id in :theContactIds ]; for(Contact c : theContacts ){ c.CustomTag__c = 'Marked as Sent a Campaign'; } update theContacts; } }}

 

 

I've having trouble accessing the Title, Email and Phone fields when traversing the Who field on the task object.

The SOQL query is valid, but the returned fields for title, email and phone are consistently null.

 

I've included a unit test that illustrates this problem.

 

If this is indeed a bug, how do I go about filing a Ticket for this?

 

Thanks, 

Parker

 



// Test illustrating the inability to select the title, email or phone from the Who field on the Task object

// API Version: 15.0

static testMethod void testTitleInWhoTask(){
User oldOwner = [SELECT u.Id,u.name FROM User u WHERE u.isActive = true ORDER BY u.CreatedDate LIMIT 1];
String fakeTitle = 'SVP of Unit Testing';
Contact testContact = new Contact( firstName = 'Unit', LastName = 'Tester', email='unittest@example.com',title = fakeTitle,phone = '555-555-555');
insert testContact;
Task theTask = new Task(WhoId = testContact.id, subject = 'Unit Test Task', ActivityDate = System.Today() );
insert theTask;

// Validate that we have inserted the contact in properly
Contact cToTest = [SELECT c.id, c.firstname, c.lastName, c.name, c.email, c.title, c.phone FROM Contact c WHERE c.id = :testContact.id];
System.assertEquals(testContact.id, cToTest.id);
System.assertEquals(testContact.firstname, cToTest.firstname);
System.assertEquals(testContact.lastName, cToTest.lastName);
System.assertEquals(testContact.email, cToTest.email);
System.assertEquals(testContact.title, cToTest.title);
System.assertEquals(fakeTitle, cToTest.title);
System.assertEquals(testContact.phone, cToTest.phone);

// Validate that we can pull the title, email, name, phone etc from Who in Task
Task taskToTest = [Select t.Who.Title, t.Who.Email, t.Who.Name, t.who.Type, t.Who.phone, t.WhoId, t.id From Task t WHERE t.whoid = :testContact.id];
System.assertEquals(theTask.id, taskToTest.id);
System.assertEquals(cToTest.id, taskToTest.Whoid);
System.assertEquals(cToTest.Name, taskToTest.Who.Name);
System.assertEquals('Contact', taskToTest.Who.Type);

// None of these Pass. They all return null
System.assertEquals(cToTest.title, taskToTest.Who.Title);
System.assertEquals(cToTest.Email, taskToTest.Who.Email);
System.assertEquals(cToTest.phone, taskToTest.Who.phone);

}

 

I am having trouble adding javascript events to the individual selectOptions.  I am able to add events to the wrapping selectList and selectCheckboxes.

 

Please see the following code example.  The expected behavior when clicking on a selectOption would be:

  1. An alert from the surrounding selectList or selectCheckboxes
  2. An alert from clicking on each individual selectOptio, like "Click me 1"
The rendered behavior only alerts when clicking on the selectList and not the underlying selectOptions.
 

I've inspected the HTML source and have confirmed that the onclick events do not get rendered.  Has there been a bug filed against this?

 

 

 

<apex:form >
<apex:selectCheckboxes id="selectedCheckboxesId"  layout="pageDirection" onclick="alert('clicked apex:selectCheckboxes')">
       <apex:selectOption id="so00" itemValue="Click me 1" itemLabel="Click me 1" onclick="alert('Click me 1')" onmouseover="alert('Moused Over 1')"/>
       <apex:selectOption id="so11" itemValue="Click me 2" itemLabel="Click me 2" onclick="alert('Click me 2')"/>
</apex:selectCheckboxes>
<apex:selectList id="selectedListId" onclick="alert('clicked selectList')">
       <apex:selectOption id="so0" itemValue="Click me 1" itemLabel="Click me 1" onclick="alert('Click me 1')" onmouseover="alert('Moused Over 1')"/>
       <apex:selectOption id="so1" itemValue="Click me 2" itemLabel="Click me 2" onclick="alert('Click me 2')"/>
</apex:selectList>
</apex:form>

 

 

Message Edited by parkerAPT on 02-24-2009 02:14 PM

Is there an easy way to only display the Time of a DateTime object in VisualForce?

 

Also is there an easy way to display the Day-of-the-week like 'Friday' in VisualForce?

 

Currently, I'm using a switch statement taken from the pdf on Formulas, but am wondering if there is a better method:

{!CASE(MOD( TODAY() - DATE(1900, 1, 7), 7),0, "Sunday",1, "Monday",2, "Tuesday",3, "Wednesday",4, "Thursday",5, "Friday",6, "Saturday", "Error")}

 

Thanks

Parker

 

I'm having trouble embedding an S-Control that uses a merge field inside a Page Layout when including the view using the component. Specifically, I have the following components:

 

  1. A Visual Force page using the standard Contact Controller with an <apex:detail> component.
  2. A S Control Component (HTML) that uses a merge field: <b>{!Contact.FirstName}</b>
  3. In the pageLayout, I have added this SControl to the Contact layout.

When I view the standard Contact view (Not my custom Visual Force Page), the Scontrol embeds correctly and displays a bold version of the Firstname.

 

However, inside my Visual Force page, the apex:detail does not properly display the FirstName. (other fields are also not visible)

  

Is this a limitation of embedding an SControl or am I doing something incorrectly?

 

Thanks 

The following code illustrates several bugs in how attributes get bound to a custom component's controller.  From what I read in the discussion (http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=5964) on assignTo, I understand that the attributes will not be available in the controller's constructor.  However,

I've include a test bench that illustrates the following problems:
  1. Default values do not get assigned to the variables.  They are Null when the initial page renders.
  2. Required attributes do get properly bound to the controller's Property but cannot be updated by actions.
  3. If we override the custom getter to ensure that its not null when returned, it initially is rendered as null but after an update is bound but does not increment as you would expect
  4. (What works): Properties that that are only present in the controller and do not get anything assigned to them.
The following 3 source files make up the test bench:
demoComponentBinding.page
BuggedComponentBinding.component
BuggedBindingController.cls

Code:
<apex:page >

<h1>The following demonstrates several bugs in using the assignTo attributes with a custom component</h1>
<ol>
 <li> The convention when I'm assigning values is the following:  Those in the hundreds are assigned via component attributes, while those less than 100 are assigned by the controller</li>
 <li>Default values do not get assigned to the variables.  They are Null.</li>
 <li>Required attributes do get properly bound but cannot be updated by actions.</li>
 <li>If we override the custom getter to ensure that its not null when returned, it initially is rendered as null but after an update is bound but does not increment as you would expect</li>
 <li>(What works): Un assigned attributes that are only present in the controller.</li>
</ol>

<c:BuggedComponentBinding demoTitle="Only Specifying required Attributes, default will not get bound properly"
 RequiredBound="300"/>
<c:BuggedComponentBinding demoTitle="Specifying both required and one default attributes, default will get bound but cannot be updated"
 NotRequiredDefaultBound="100"
 RequiredBound="300"/>
<c:BuggedComponentBinding demoTitle="Only specifying default attribute with custom getter"
 DefaultWithCustomGetter="200"
 RequiredBound="300"/>
<c:BuggedComponentBinding demoTitle="Specifying required and both default attributes, default will get bound but cannot be updated"
 NotRequiredDefaultBound="100"
 DefaultWithCustomGetter="200"
 RequiredBound="300"/>

</apex:page>

 
Code:
<apex:component controller="BuggedBindingController">
 <apex:attribute name="NotRequiredDefaultBound" default="11" assignTo="{!DefaultAssignedAttribute}" type="Integer"
  description="The default attribute does not get bound to the appropriate property of the controller" />
 <apex:attribute name="DefaultWithCustomGetter" default="22" assignTo="{!DefaultAssignedAttributeCustomGetter}" type="Integer"
  description="The default attribute does not get bound to the appropriate property of the controller" />
 <apex:attribute name="RequiredBound" assignTo="{!RequiredAttributeAssigned}" type="Integer" required="true"
  description="This required attribute gets bound, but cannot be updated via ajax calls" />
 <apex:attribute name="DemoTitle" type="string" description="Title of this demo"/>
  
<apex:form >

 <apex:outputPanel id="theTableWrapper" layout="block" title="{!DemoTitle}" style="padding: 10px; border: 1px solid black">
  <apex:panelGrid columns="4" id="theGrid" rules="all" cellpadding="5" width="50%">
   <apex:facet name="caption">
    <h2>{!DemoTitle}</h2>
   </apex:facet>
   <apex:outputText value="Property"/>
   <apex:outputText value="IsNull"/>
   <apex:outputText value="Value from Controller" />
   <apex:outputText value="Value from Component Attribute Reference" />
   
   
   <apex:outputText value="DefaultAssignedAttribute" />
   <apex:outputText value="{!ISNULL(DefaultAssignedAttribute)}" />
   <apex:outputText value="{!DefaultAssignedAttribute}" />
   <apex:outputText value="{!NotRequiredDefaultBound}" />
   
   <apex:outputText value="DefaultAssignedAttributeCustomGetter" />
   <apex:outputText value="{!ISNULL(DefaultAssignedAttributeCustomGetter)}" />
   <apex:outputText value="{!DefaultAssignedAttributeCustomGetter}" />
   <apex:outputText value="{!DefaultWithCustomGetter}" />
   
   <apex:outputText value="RequiredAttributeAssigned" />
   <apex:outputText value="{!ISNULL(RequiredAttributeAssigned)}" />
   <apex:outputText value="{!RequiredAttributeAssigned}" />
   <apex:outputText value="{!RequiredBound}" />
   
   
   <apex:outputText value="InternalAttribute" />
   <apex:outputText value="{!ISNULL(InternalAttribute)}" />
   <apex:outputText value="{!InternalAttribute}" />
   <apex:outputText value="N/A" />
   
  </apex:panelGrid>
  <apex:commandButton action="{!updateValues}" reRender="theTableWrapper" value="Update the Values"/>
 </apex:outputPanel>
</apex:form>
 
</apex:component>

 
Code:
public class BuggedBindingController {
 
 public Integer DefaultAssignedAttribute  {get; set;}
 public Integer DefaultAssignedAttributeCustomGetter  {
  get {
   if( this.DefaultAssignedAttributeCustomGetter == null){
    this.DefaultAssignedAttributeCustomGetter = 20;
   }
   return DefaultAssignedAttributeCustomGetter;
  } set;}
 public Integer RequiredAttributeAssigned  {get; set;}
 public Integer InternalAttribute   {get; set;}
 
 public BuggedBindingController(){
  InternalAttribute = 40;
 }
 
 public PageReference updateValues(){
  if(this.DefaultAssignedAttribute != null){
   this.DefaultAssignedAttribute++;
  }
  if(this.RequiredAttributeAssigned != null){
   this.RequiredAttributeAssigned++;
  }
  this.DefaultAssignedAttributeCustomGetter++;
  this.InternalAttribute++;
  return null;
 }
 
}

 




Message Edited by parkerAPT on 01-15-2009 08:16 AM
All,

Is there a way to leverage the hover text ability of the pageBlockSectionItem within a pageBlockTable?

I understand how I can customize the hover text for a pageBlockSectionItem via the helpText attribute.
However, when I try to use the pageBlockSectionItem inside a column, the hover text does not get rendered.

Has anyone run into this problem before and have a solution that uses the built in Apex Components?

Thanks
Parker
Is there a way to redirect or override the default record view for standard sObjects?

For example, if a user was visiting: cs1.salesforce.com/003S0000002Wagt, they normally see the Standard Contact view.  This also works for any record type, it seems that the first 3 characters determine the type of sObject and appropriately display the view.


I have written a custom Apex page for the Contact view and would like to have this be the default view that everyone sees when navigating to the page for a specified Contact Record.  I know that I can customize the page layout of the standard view but am having difficultly figuring out how to redirect to my custom page.

Ideally, for the above link, the user should be redirected to something like: salesforce.com/apex/CustomView?cid=003S0000002Wagt

Can someone point me in the right direction please?

Thanks
Parker
Is it possible to catch the exception thrown when there are too many query rows?

The following code does not catch any exception when there are more than 10,000 rows (500 in testCase) returned.

In this case, because it is a testMethod, the exception gets thrown because there are more than 500 rows returned.


static testMethod void testCatchTooManyRows(){
Boolean caught = false;
try{
Integer theCount = [SELECT count() from Contact];
}catch(Exception e){
caught = true;
}
System.assert(caught);
}
Does VF support adding custom buttons to related lists?

This post indicates that it's not possible on the Attachment related list.
http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=23349

However, I'm wondering if you can add custom buttons to other related like for a Contact's Activity History?

Thanks
Parker
I'm trying to extend the SelectOption class. Does visualforce allow this?

public abstract class ActionableSelectOption extends SelectOption {
public ActionableSelectOption(String val, String labl){
this(val, labl,false);
}
public ActionableSelectOption(String val, String lab, Boolean isDisabled){
super(val,lab,isDisabled);
}
// The method that gets called to perform whatever action is associated with this Selected Item
public abstract boolean performAction();
}

I get the following error message:
Save error: ActionableSelectOption: Non-exception class must extend another user-defined non-exception class: SelectOption

Thanks
P
I'd like to prevent users from repeatedly clicking on a custom button I've created.

Right now I have a button that will create a custom task via an AJAX call on the contacts page. On the returning AJAX call, I reRender the list of Activites associated with this contact.

However, I need a way to provide visual feedback to disable the button after a user clicks it.

I've seen this work on QuickSave button and am wondering how to implement this.

Thanks
-P

Here is the code for reference. (I've removed the inital "
apex:page standardController="Contact" extensions="customController" tabStyle="Contact">
apex:detail subject="{!contact}" relatedList="false"/>
apex:form >
apex:commandButton reRender="activitiesPanel" status="activityStatus" action="{!markContactAsSentEmail}" value="Add task for contact"/>
/apex:form>
apex:outputPanel id="activitiesPanel">
apex:actionStatus id="activityStatus" startText="Refreshing Activity History...">
apex:facet name="stop">
apex:relatedList id="activitiesList" list="ActivityHistories" />
/apex:facet>
/apex:actionStatus>
/apex:outputPanel>



Message Edited by parkerAPT on 12-23-2008 02:15 PM
Pattern p = Pattern.compile('.*"(.*)"');
Matcher m = p.matcher('Outer quote "test case 1"');
if(m.matches()){
for(Integer i =0 ; i < m.groupCount(); i++){
System.debug('Found Group [' + i + ']: ' + m.group(i));
}
}
Pattern p2 = Pattern.compile('.*("(.*)")');
Matcher m2 = p2.matcher('Outer quote "test case 2"');
if(m2.matches()){
for(Integer i =0 ; i < m2.groupCount(); i++){
System.debug('Found Group [' + i + ']: ' + m2.group(i));
}
}

Can someone explain why these print the following:

First pattern:
Found Group [0]: Outer quote "test case 1" {this is expected, but where is the nested group inside double-quotes?}

Second pattern:
Found Group [0]: Outer quote "test case 2" {expected}
Found Group [1]: "test case 2" {expected, but again, where is the inner group?}

Thanks!
Is there a way to make a Pattern case insensitive, like in Java and most other regular expression libraries?

In Java, you can write something like:
Pattern p = Pattern.compile("foobar",Pattern.CASE_INSENSITIVE);

This will match "fOObar" or "Foobar" or any other permutation.

In Apex, it seems like you can only specify the regular expression.

- One solution would be to make the regular expression lowercase and make all strings you match against lowercase. However, if I want to get a case sensitive group, I could not do this elegantly (but can be done).

Thanks

Is there an easy way to only display the Time of a DateTime object in VisualForce?

 

Also is there an easy way to display the Day-of-the-week like 'Friday' in VisualForce?

 

Currently, I'm using a switch statement taken from the pdf on Formulas, but am wondering if there is a better method:

{!CASE(MOD( TODAY() - DATE(1900, 1, 7), 7),0, "Sunday",1, "Monday",2, "Tuesday",3, "Wednesday",4, "Thursday",5, "Friday",6, "Saturday", "Error")}

 

Thanks

Parker

 

I'm struggling with the order-of-execution during a VisualForce AJAX postback request and the appropriate way to nest-components that might need to rerender each other.

 

The documentation (http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_postback_request.htm ) has 4 key steps:

 

  1. View Deserialization
  2. Evaluate expressions and all method calls including those on custom component controllers
  3. Evaluate the action that triggered the postback
  4. Render view -> HTML sent to browser

 

I'm getting frustrated by the second step, specifically all method calls.  From what it appears, any public methods (specifically a getter) that are used in a view are called before the action method gets call even if these methods are not binding anything in the View State.

 

The example below illustrates that getDisplayedList method gets called immediately after view state deserialization and then again during the rendering of the view.  In my toy example, I lazy-load a list of strings based on the iCount member variable.  In my real-world application I'm actually using a SOQL query to dynamically fetch a list of S-Objects to display to the user. 

 

 

<apex:page controller="LazyLoadController">

<apex:form id="theWrapper">
	<apex:repeat value="{!DisplayedList}" var="s">
		{!s}
	</apex:repeat>
	
	<apex:commandLink value="refresh" rerender="theWrapper" />
	
	<div>
	iCount : <b>{!iCount}</b>
	</div>
</apex:form>

</apex:page>

public with sharing class LazyLoadController {

	public LazyLoadController(){
		this.iCount = 5;
	}

	public Integer iCount {get; set;}
	
	private Transient List<String> t_theList;
	
	// I want to be able to gurantee getDisplayedList() only gets executed during the rendering of the Component and not during "Postback" validation
	public List<String> getDisplayedList(){
		if(this.t_theList == null){
			// The real use case would Query the Database for the appropriate objects.
			
			this.t_theList = new List<String>();
			for(Integer i=0 ; i< this.iCount; i++){
				this.t_theList.add('[' + String.valueOf(i) + ']');
			}
		}
		iCount++;
		return this.t_theList;
	}
	
	
	public PageReference refresh(){
		// In theory I want to be able to execute code here that is guranteed to be executed before getDisplayedList
		return null;
	}
}

 

Unfortuntaely, because getDisplayedList gets called before I execute any code in my post-back method, I do not have the opportunity to do any additional logic before the Transient list of strings ( t_theList) gets initalized.

 

One quick and obvious solution would be to set the Transient list to null in the postback method and force the list to be regenerated or remove the lazy-loading indirection and initalize the list directly.

 

I typically would do this except for the fact I want this controller to be a component-controller that can be easily dynamically rerendered.  I've outlined the at the high-level what I want to do below.

 

 

<apex:page controller="ParentController">
	<!-- Code that will create a new Task and 
		re-render the component that should display 
		a list containing the newly created task 
		-->
	<apex:commandLink value="addNewTaskAndRefreshList" rerender="componentWrapper" />
	
	<apex:outputPanel id="componentWrapper">
		<c:lazyLoadComponent 
			countOfTasks=5/>
		</c:lazyLoadComponent>
	</apex:outputPanel>
	
</apex:page>

 

public with sharing class ParentController {
	public PageReference addNewTaskAndRefreshList(){
		Task t = new Task();
		//...
		insert t;
		return null;
	}
}

 

 

Pretend for example, that my LazyLoadController is now displaying a list of tasks that are dynamically loaded from the database.  I'd like to be able to put this component onto my page and re-render it so that it dynamically refreshes the list of Tasks.  For example, in the ParentController I want to insert a new task, refresh the child-component and display the new task.  Currently, the Lazy-Loading happens in Step 2 (method calls) of the order of execution before Step 3 (Invoke PostBack method).

 

Does anyone have a suggestion for how I can re-design my code so that I can achieve the above behavior?

 

Thanks

Parker

 

I've having trouble accessing the Title, Email and Phone fields when traversing the Who field on the task object.

The SOQL query is valid, but the returned fields for title, email and phone are consistently null.

 

I've included a unit test that illustrates this problem.

 

If this is indeed a bug, how do I go about filing a Ticket for this?

 

Thanks, 

Parker

 



// Test illustrating the inability to select the title, email or phone from the Who field on the Task object

// API Version: 15.0

static testMethod void testTitleInWhoTask(){
User oldOwner = [SELECT u.Id,u.name FROM User u WHERE u.isActive = true ORDER BY u.CreatedDate LIMIT 1];
String fakeTitle = 'SVP of Unit Testing';
Contact testContact = new Contact( firstName = 'Unit', LastName = 'Tester', email='unittest@example.com',title = fakeTitle,phone = '555-555-555');
insert testContact;
Task theTask = new Task(WhoId = testContact.id, subject = 'Unit Test Task', ActivityDate = System.Today() );
insert theTask;

// Validate that we have inserted the contact in properly
Contact cToTest = [SELECT c.id, c.firstname, c.lastName, c.name, c.email, c.title, c.phone FROM Contact c WHERE c.id = :testContact.id];
System.assertEquals(testContact.id, cToTest.id);
System.assertEquals(testContact.firstname, cToTest.firstname);
System.assertEquals(testContact.lastName, cToTest.lastName);
System.assertEquals(testContact.email, cToTest.email);
System.assertEquals(testContact.title, cToTest.title);
System.assertEquals(fakeTitle, cToTest.title);
System.assertEquals(testContact.phone, cToTest.phone);

// Validate that we can pull the title, email, name, phone etc from Who in Task
Task taskToTest = [Select t.Who.Title, t.Who.Email, t.Who.Name, t.who.Type, t.Who.phone, t.WhoId, t.id From Task t WHERE t.whoid = :testContact.id];
System.assertEquals(theTask.id, taskToTest.id);
System.assertEquals(cToTest.id, taskToTest.Whoid);
System.assertEquals(cToTest.Name, taskToTest.Who.Name);
System.assertEquals('Contact', taskToTest.Who.Type);

// None of these Pass. They all return null
System.assertEquals(cToTest.title, taskToTest.Who.Title);
System.assertEquals(cToTest.Email, taskToTest.Who.Email);
System.assertEquals(cToTest.phone, taskToTest.Who.phone);

}

 

Is there an easy way to only display the Time of a DateTime object in VisualForce?

 

Also is there an easy way to display the Day-of-the-week like 'Friday' in VisualForce?

 

Currently, I'm using a switch statement taken from the pdf on Formulas, but am wondering if there is a better method:

{!CASE(MOD( TODAY() - DATE(1900, 1, 7), 7),0, "Sunday",1, "Monday",2, "Tuesday",3, "Wednesday",4, "Thursday",5, "Friday",6, "Saturday", "Error")}

 

Thanks

Parker

 

can anyone tell me how to update a column of  a table through apex classes?

 

I have created a method for updating and i used update(list type variable) command. It is throwing a run time error like "Illegal view ID update. The ID must begin with / "

 

what does this mean? please suggest...

I created tabs following the Tabbed Accounts in 30 seconds post and my problem is that whenever I perform an action on any tab other than the detail tab I'm returned to the detail tab after the action is completed instead of returning to the tab I was on.  

 

I tried to find code samples that my lead me to an answer and I thought maybe I had to create an standard controller extension which I attached below.  However, I'm very green at this so I don't really know how to continue so any direction and sample code would be greatly appreciated.  I'm sure I'm not the only one who has implemented this cool technique and has run into this problem.

 

Keith

 

VS Page:

 

<apex:page standardController="Account" extensions="accountExt" id="p"
showHeader="true" tabStyle="account" >
<apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel">
<apex:tab label="Details" name="AccDetails" id="tabdetails">
<apex:detail relatedList="false" title="true"/>
</apex:tab>
<apex:tab label="Contacts" name="Contacts__r" id="tabContact">
<apex:relatedList subject="{!account}" list="contacts__r" />
</apex:tab>
<apex:tab label="Invoices" name="Invoices" id="tabInvoice">
<apex:relatedList subject="{!account}" list="invoices__r" />
</apex:tab>
<apex:tab label="Open Activities" name="OpenActivities" id="tabOpenAct">
<apex:relatedList subject="{!account}" list="OpenActivities" />
</apex:tab>
<apex:tab label="Products Offered" name="ProductsOffered" id="tabProdOffer">
<apex:relatedList subject="{!account}" list="Products_Offered__r" />
</apex:tab>
<apex:tab label="Products Sold" name="ProductsSold" id="tabProdSold">
<apex:relatedList subject="{!account}" list="Product_Releases__r" />
</apex:tab>
</apex:tabPanel>
</apex:page>

 Controller:

 

public class accountExt {

String aId;
String pId;

public accountExt(ApexPages.StandardController controller) {
aId = ApexPages.currentPage().getParameters().get('aId');
pId = ApexPages.currentPage().getParameters().get('pId');
}

public PageReference redirect(){
PageReference pageRef = new PageReference('/'+pId);
pageRef.setRedirect(true);
return pageRef;
}

public void setState(String n) {
state = n;
}

public String getState() {
return state;
}

public PageReference methodOne() {
return null;
}

private String state = 'no';
}

 

 

 

 

 

I am trying to create a list button that will lookup Contacts with a given input, display the results and select the desired Contact. Once the the Contact is selected the related list on an object will populate with that name.

Any ideas to get me started?
Hello.

I'm attempting to make a dashboard table that displays a Lead name along with their Last Activity date. I've first made a Tabular report that just has the Lead name and Last Activity fields specified, but in the Dashboard Component section of the report setup, it doesn't let me select the Last Activity field as the Value field. I then tried recreating the report as a Summary report, but the dashboard then just displays the record count.

How can I accomplish this? Thanks in advance.

-Greg
Is there a way to redirect or override the default record view for standard sObjects?

For example, if a user was visiting: cs1.salesforce.com/003S0000002Wagt, they normally see the Standard Contact view.  This also works for any record type, it seems that the first 3 characters determine the type of sObject and appropriately display the view.


I have written a custom Apex page for the Contact view and would like to have this be the default view that everyone sees when navigating to the page for a specified Contact Record.  I know that I can customize the page layout of the standard view but am having difficultly figuring out how to redirect to my custom page.

Ideally, for the above link, the user should be redirected to something like: salesforce.com/apex/CustomView?cid=003S0000002Wagt

Can someone point me in the right direction please?

Thanks
Parker
Is it possible to catch the exception thrown when there are too many query rows?

The following code does not catch any exception when there are more than 10,000 rows (500 in testCase) returned.

In this case, because it is a testMethod, the exception gets thrown because there are more than 500 rows returned.


static testMethod void testCatchTooManyRows(){
Boolean caught = false;
try{
Integer theCount = [SELECT count() from Contact];
}catch(Exception e){
caught = true;
}
System.assert(caught);
}
I'd like to prevent users from repeatedly clicking on a custom button I've created.

Right now I have a button that will create a custom task via an AJAX call on the contacts page. On the returning AJAX call, I reRender the list of Activites associated with this contact.

However, I need a way to provide visual feedback to disable the button after a user clicks it.

I've seen this work on QuickSave button and am wondering how to implement this.

Thanks
-P

Here is the code for reference. (I've removed the inital "
apex:page standardController="Contact" extensions="customController" tabStyle="Contact">
apex:detail subject="{!contact}" relatedList="false"/>
apex:form >
apex:commandButton reRender="activitiesPanel" status="activityStatus" action="{!markContactAsSentEmail}" value="Add task for contact"/>
/apex:form>
apex:outputPanel id="activitiesPanel">
apex:actionStatus id="activityStatus" startText="Refreshing Activity History...">
apex:facet name="stop">
apex:relatedList id="activitiesList" list="ActivityHistories" />
/apex:facet>
/apex:actionStatus>
/apex:outputPanel>



Message Edited by parkerAPT on 12-23-2008 02:15 PM
Why can I not put the standard Task/Event "Type" field on a custom report type that includes activities?  It seems like a no brainer that the Type field should be on there for filtering purposes.  I would use the standard report types for activities but I want to filter by contact id and that field is not available to me in the standard reports just the contact name.  When I say the standard reports I mean that ones that are called "Activities with Custom Object".  So my tasks are "Related To" the custom object and the "Who" is the contact id.  I can get all of the information I need with a custom report type except for the "Type" field it will not allow me to put that field on the report layout.  Any ideas? 
  • November 17, 2008
  • Like
  • 0
Hi guys I've browsed around the forums a little and looked through the pdf's but just can't seem to get this one right. I'm missing something simple. I know I've overlooked something but I can't find it. Sorry

Can someone let me know how I can make this bit of code on my visual force page... return to the page I'm currently on once it's clicked?

Code:
URLFOR($Action.Sales_Contact__c.Delete, c.Id, null, true)

 
Basically how do I set RetURL for a URLFOR? If someone could write it out for me that would be great.

I need it to return to /apex/addsalesprospectId={!Account.Id}   when I'm finished.

Sorry and thanks to anyone that helps.


Message Edited by patske on 06-04-2008 11:14 PM
Is there any way to force a Collapsible PageBlockSection to start in a collapsed mode, when the page is rendered?  I know with standard page layouts, this isn't possible, but Salesforce remembers what a user chooses and uses that in the future to determine the collapsible state when rendering a page.  So far, I have not seen this same behavior with Visualforce pages.  It would be nice to have a parameter on the PageBlockSection that controls the initial behavior of a collapsible PageBlockSection when it it first rendered.
 
Jon Keener


Message Edited by Jon Keener on 02-14-2008 01:06 PM