• md1
  • NEWBIE
  • 155 Points
  • Member since 2005

  • Chatter
    Feed
  • 6
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 42
    Replies

I'm trying to build my first actual visualforce page on my own (well, borrowing heavily from examples). And this is what I get for being too uppity. I'm stuck.

My Goal:
Create a custom list on Contracts that shows all related Opportunities (where Contract__c on the Opportunity = the currently viewed Contract Id) on the Contract page layout. Eventually, I want to create a total of the Amounts and use this to compare to the total contract value. (We have a data model where many opps can be related to one contract.)

What I Was Thinking:

I created a Contract controller extension, borrowing from this other post and following the directions here.

public class ContractExtension { public List<Opportunity> ChildOpportunities = new Opportunity[]{}; public List<Opportunity> getContractOpps() { ChildOpportunities = [SELECT o.Contract__r.Id, Amount, Id, StageName, CloseDate FROM Opportunity o WHERE o.Contract__r.Id = :System.currentPageReference().getParameters().get('id') ]; return ChildOpportunities; } }

But, when I include the reference to the extension on my visualforce page, I get an error. "Unknown constructor 'ContractExtension.ContractExtension(Apex.Pages.StandardController controlller)'

Here's my page:

<apex:page standardController="Contract" extensions="ContractExtension"> <apex:detail id="ChildOpps_v1" relatedList="true"> <apex:relatedList id="ChildOpportunities" list="Opportunities" title="Child Opportunities" subject="{!ContractOpps}"> </apex:relatedList> </apex:detail> </apex:page>

 Any helpful tips for a vf newbie?


 

 

I can use new SelectOption('value', 'label') to create many dropdown (<select>) options but how do I create groups around them?  <optgroup> is a fairly common HTML tag and I can't figure out how to make half the list be in one <optgroup> and the 2nd half in another <optgroup> but still part of the same dropdown.

 

With some luck someone understands what I mean and can point me in the right direction.  Best I can do now is think about how to do it with javascript after the page renders.

Hi,

 

I have created a formula field on Account to get the prefix from Account Number. I have account number in form like "1234-5678". I created a new formula field 'Account Number Prefix' which gets me "1234" from this Account Number.

 

formula: LEFT( AccountNumber,FIND("-", AccountNumber,0)-1)

 

This shows correct results within Salesforce instance. But when i go and Query this field from Apex explorer it doesnt shows me any value in this formula field. i tried replacing this formula to:

TEXT(FIND("-", AccountNumber,0))

 

and it shows me the correct result.

 

I am also querying many other formula fields which are giving me correct result in my queries. Is there something wrong in the way i am using "LEFT()"?

 

Please advise.

  • March 24, 2009
  • Like
  • 0

I'm using actionSupport to re-render a pageBlockTable. The problem is that it does a rerender everytime the event (onchange or onblur) occur. Is there anyway to rerender the section conditionally? For example, I wouldn't want it to rerender if the field on which the actionSupport is added to is blank.

 

 

<apex:column style="white-space : nowrap;">

<apex:facet name="header">Account</apex:facet>

<apex:inputtext id="account" value="{!element.accName}" size="22">

<apex:actionSupport event="onblur" action="{!element.setAcc}" rerender="{!$Component.transferTable},pageMessages"/>

</apex:inputtext></apex:column>

 

Thanks in advance,

-Manu 

 

 

Message Edited by md1 on 12-01-2010 02:43 PM
  • January 12, 2010
  • Like
  • 0

I have a simple Batch Apex class called from a trigger on the User object that updates a field on the Accounts owned by the User if a corresponding field is updated on the User.

 

All's working well as regards functionality, but the test method does not seem to be calling the Execute.

 

The trigger:

 

trigger au_User on User (after update) {

List<id> usersToUpdate = new List<id>();

//Loop through the trigger set for (integer iterator=0; iterator<trigger.new.size(); iterator++){

//Add the Users to collection where the values of the given fields have changed

if(trigger.new[iterator].Super_Sector_Region__c <> trigger.old[iterator].Super_Sector_Region__c){

usersToUpdate.add(trigger.new[iterator].id);

}

}

AccountUpdaterBatch batch = new AccountUpdaterBatch();

batch.usersToUpdate = usersToUpdate;

Database.executeBatch(batch, 20);

}

 

 The batch apex class:

 

 

global class AccountUpdaterBatch implements Database.Batchable<SObject>, Database.Stateful{

public List<id> usersToUpdate = new List<id>();

global Database.QueryLocator start(Database.BatchableContext BC){

String query='select a.id, a.Sector_Region__c, a.Owner.Super_Sector_Region__c'

+' from Account a where a.OwnerId IN :usersToUpdate';

return Database.getQueryLocator(query);

}

global void execute(Database.BatchableContext BC, List<sObject> scope){

List<Account> accns = new List<Account>();

for(sobject s : scope){

Account a = (Account)s;

if(a.Sector_Region__c != a.Owner.Super_Sector_Region__c)

a.Sector_Region__c = a.Owner.Super_Sector_Region__c;

accns.add(a);

}

update accns;

system.debug('####### Number of accounts updated'+accns.size());

}

global void finish(Database.BatchableContext BC){ //Do nothing }

 

}

 

The test method:

 

 

static testMethod void testUserTrigger(){

User currentUser = [Select u.Super_Sector_Region__c, u.Id From User u Where u.Id =: UserInfo.getUserID()];

List<Account> testAccs = new List<Account>();

for(integer i=0;i<90;i++){

Account testAccount = new Account(Name = 'TestAccount'+i, OwnerId = currentUser.Id);

testAccs.add(testAccount);

}

insert testAccs;

Test.starttest();

currentUser.Sector_Sales_Team__c = 'Test1';

update currentUser;

AccountUpdaterBatch testBatch = new AccountUpdaterBatch();

testBatch.usersToUpdate = new List<id>{currentUser.Id};

Database.executeBatch(testBatch, 20);

test.stoptest();

}

 

 

 

 Finally, the dump from the test log that shows that the start method was called, but the execute wasn't:

 

 

20100110162747.501:External entry point: returning Database.QueryLocator from method global Database.QueryLocator

start(Database.BatchableContext) in 0 ms

20100110162747.501:Class.AccountUpdaterBatch.start: line 35, column 10: SOQL locator query with 93 rows finished in 122 ms

Cumulative resource usage:

..

..

..

..

 

20100110162738.641:Class.TestAccountTrigger.testUserTrigger: line 123, column 3: returning from end of method global static void stopTest() in 5760 ms

 

20100110162738.641:External entry point: returning from end of method static testMethod void testUserTrigger() in 9065 ms

 

 Can someone please guide me as to what I'm missing or doing wrong?

 

Thanks,

 

-Manu 

Message Edited by md1 on 10-01-2010 04:36 PM
  • January 10, 2010
  • Like
  • 0

Apex Gurus,

 

I'm trying to create Account Team members and setting the Account Share as 'Read/Write' for all objects but am getting the error  INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST. Here's the code:

 

Database.SaveResult[] saveResults = Database.insert(members,false);

AccountShare[] newShare = new AccountShare[]{}; //list of new shares to add

integer newcnt1=0;

for(Database.SaveResult sr : saveResults){

if(!sr.isSuccess()){

Database.Error emsg = sr.getErrors()[0];

system.debug('\n\nERROR ADDING TEAM MEMBER:'+emsg);

}else{

newShare.add(new AccountShare(UserOrGroupId = members[newcnt1].UserId, AccountId=members[newcnt1].Accountid, AccountAccessLevel='Read/Write', OpportunityAccessLevel='Read/Write', CaseAccessLevel='Read/Write', ContactAccessLevel='Read/Write'));

}

newcnt1++;

}

if(newShare.size()>0){

System.debug('No. of shares to be created: '+newShare.size());

Database.SaveResult[] lsr0 =Database.insert(newShare,false); //insert the new shares

Integer newcnt0=0;

for(Database.SaveResult sr0:lsr0){

if(!sr0.isSuccess()){

Database.Error emsg0=sr0.getErrors()[0];

system.debug('\n\nERROR ADDING SHARING:'+newShare[newcnt0]+'::'+emsg0);

}

newcnt0++;

}

System.debug('No. of shares created: '+newcnt0);

}


 

I get an error each line of team share that i'm trying to insert:

 

Bad value for restricted picklist field: Read/Write;getStatusCode=System.StatusCode.INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST 

Been stuck at it for 2 days now so appreciate any help possible to eradicate the above!

 

Thanks in advance,

-Manu 

Message Edited by md1 on 15-12-2009 02:55 PM
  • December 15, 2009
  • Like
  • 0

I think this is a common problem, but I'm unable to get the 'right' answer for it throughout forums and elsewhere. I have a datatable and want to display the error message for a required selectlist next to the field in the table if its not entered:

 

 

<apex:pageBlockTable value="{!MyElements}" var="element" id="myTable">

<apex:column >

<apex:facet name="header">Request To</apex:facet>

<apex:outputfield value="{!element.element.Function__c}" id="function"/>

</apex:column>

<apex:column >

<apex:facet name="header">Requested By</apex:facet>

<apex:outputfield value="{!element.element.CreatedBy.Name}" id="createdby"/>

</apex:column>

<apex:column >

<apex:facet name="header">Request Date</apex:facet>

<apex:outputfield value="{!element.element.CreatedDate}" id="createddate"/>

</apex:column>

<apex:column >

<apex:facet name="header">Action</apex:facet>

<apex:selectList value="{!element.approvalOption}" size="1" id="action" required="true">

  <apex:selectoptions value="{!ApprovalOptions}"/>

</apex:selectList>

</apex:column>

<apex:column >

<apex:facet name="header">Transfer To</apex:facet>

<apex:selectList value="{!element.transferTo}" size="1" id="transferTo" required="true" rendered="{!element.showTransferOptions}">

<apex:selectoptions value="{!transferOptions}"/>

</apex:selectList>

<apex:message id="transferToMessage" for="transferTo"/>

<!-- or <apex:pageMessage id="transferRequired" severity="2"/>-->

</apex:column>

</apex:pageBlockTable>

 

 Can someone guide how to get a reference to the message or page message if the select option is not selected? Right now, I have it as required, so I get the error in the page messages on the top of the page as but with the dom reference to the missing fields :

 

mypage:myForm:myBlock:myTable:4:transferTo: Validation Error: Value is required  

mypage:myForm:myBlock:myTable:5:transferTo: Validation Error: Value is required 

 

Thanks,

-Manu 

 

  • December 07, 2009
  • Like
  • 0

I'm using the following markup to show an ordered list in my Visualforce page:

 

<apex:dataList type="1" value="{!EmployeeFAQ.ClsSolution}" var="itemQ" id="theList" styleClass="questionsList"> <apex:outputLink value="#a{!itemQ.SCount}"> <apex:outputText value="{!itemQ.Obj.SolutionName}" /> </apex:outputLink></apex:dataList>

 

However, the result being rendered is an unordered list:

 

 

<ul class="questionsList" id="j_id0:j_id1:theList" type="1"><li id="j_id0:j_id1:theList:0" class="">...</li>......<ul>

  

Any pointers as to what could be wrong here?

 

Thanks in Advance,

-Manu 

 

  • November 02, 2009
  • Like
  • 0

Two questions for using standard Web-to-lead with Sites:

 

1. Are there any best practices defined for using standard web-to-lead with sites?

 

2. Is there a way to add de-duplication logic using the standard web-to-lead so that the mapping is still taken from the Web-to-lead mapping page but we have our de-duping logic sit in between, maybe in a controller?

 

 

  • May 08, 2009
  • Like
  • 0

Hello,

 

Is it possible by way of a formula to convert a picklist field to a Date/Time field, even by combining a Date field? Looking for a workaround to the limitation to overcome the lack of a a Time field in SFDC.

 

I know this will be a solution for a lot of people who could use a custom time picklist and then just have that value populate a (hidden) Date/Time field automatically.

 

Thanks,

 

-MD 

  • March 31, 2009
  • Like
  • 0
Can we enable Salesforce Content for Dev Orgs? If so, how?
  • February 24, 2009
  • Like
  • 0

We have been trying 'desperately' to deploy our app from Sandbox to Production. Earlier in the week, we knew we could face problems as the Sandbox was in Spring'09 while Production was still Winter'09. During that phase, the Force.com IDE either just timed out or threw an error after a long time without any description.
 
Now that both Sandbox and Production are on Spring'09, we started getting Java Heap Size - Out Of Memory exceptions. We tried to increase the Heap Size but to no relief; it just wouldn't go.
 
We gave up using Eclipse and tried deploying with Ant. Thankfully, that showed us a few errors in our Test Methods which we corrected. But lo and behold,  now even Ant is timing out.
 
Is this something to do with Spring'09? Do we have to wait for the new IDE or Ant tool? What could be the reason for this? This is not only on one project or on a single location/machine. The deployment was tried on multiple systems in multiple countries and on 2 projects - one where the production server is on NA1 and another where it is NA6.
 
This is very crucial, important and urgent so any help would be beneficial.
 
Thank You! 

  • February 07, 2009
  • Like
  • 0
IS it possible to send a record or a set of records to a database from Apex code; as a simple example, when a record gets updated in SFDC, the same is 'upserted' in the database of choice? Or do we have to write a hosted application using the Web services API for the same?

Any ideas on this are welcome as its an urgent requirement.

Thanks in advance,
-MD!

Message Edited by md1 on 01-08-2009 03:39 PM
  • January 08, 2009
  • Like
  • 0
Has anyone got any experience retrieving score data from any Gaming platform like PS3, Xbox, etc into SFDC? Just need to know if any of these provide the capability to do so and if so which one and how.

Thanks in advance.
  • January 06, 2009
  • Like
  • 0
Hi,

I've installed the LMA and it is functional. Problem is that I want to use the License object in my LMO org to identify my customer org using the API, but there doesn't seem to be any object or field on the customer org with which I can relate back to the license.

Is there a way to do this? The idea is that I have a webtab from which I want to identify which customer is accessing my application so that I can provide the relevant information for that org. If only the OrgId or similar information was available in the License, I'd be able to get it.

The LMA documentation says that a License gets 'installed' on the customer org, but as far as I could try, there's no access to this too.

This is urgent so any help will be appreciated.

Thanks,

-Manu
  • January 10, 2008
  • Like
  • 0
Hi,

I'm trying to create a instance of a custom object using the partner API using JSP/Java, but am getting a NullPointerException. Is creating a custom object instance different from creating a standard object instance?

Can you please provide me with a sample code, if its different.

The error comes when setting the object the binding.

This is urgent, so any help is appreciated.

Thanks.
  • July 14, 2005
  • Like
  • 0

I am developing a chrome extension which uses chatter api. The extension will authenticate the user using oauth. Fom there on, if someone comments on the user's post, or if some one comments on the post liked by user, or if someone comments on the post which the user follows, chrome extension has to display desktop notification. I thought of using streamin API.

 

But the limits are looks constraining. And I am not sure whether this is possible using streaming api. Or is there any better approach for doing this?

We have a (non Salesforce/force.com) application used by employees and now want to sprinkle a bit of "Social" all over it. So the decision to add Chatter was an easy one as they are all familiar with its capabilities. My question is, has anyone attempted to recreate the "Share box" used to update status info?

 

In particular, the challenge appears to be supporting @-mentions with its autocomplete picklist of employees. Is there a jQuery widget or other javascript codes available to duplicate its functionality?

 

Regards

Hi,

 

Any one please help me, for importing the data of google spreadsheet in to salesforce object using salesforce classes. I tried a lot. But i am not getting. any one give me suggestion for solving these. Thanks in advance.

 

Thanks,

Lakshmi

 

I am struggling with determining whether the current user has Edit or Read Only rights on a record. In this case its an opportunity.
I check if the User has a sharing record. As the Owner or someone who has been manually/APEX shared with, they will have a sharing record.
I check if they have elevated rights using our own custom permission model.
I want to know if the user is also in the hierarchy above the owner, but don't seem to be able to code against the role hierarchy. The only option I have found is to try an edit on the opportunity, and revert it back. Its the last step if they don't have edit rights by other means. It means 2 updates which I believe are unnecessary  and ineloquent. I check if the update fails for the reason they only have READ ONLY rights. It could fail for other reasons such as validation rules, but that doesnt mean they dont have edit rights, it means they didnt complete the form properly.
The function below determines how a VF component on the Opportunity page layout behaves. If they have edit rights on the opportunity they see one thing, if they dont they see something else. This logic should work as the page loads and not when a user clicks a button on the opportunity.
Below is my function.
private boolean bCanBeEdited()
    {
     boolean edit = false;
    
     try
     {
       
     //Get a list of Users/Groups that the Opportunity is shared with, limited by opp id and the users ID.
       
     List<OpportunityShare> SharedWith = [Select o.id, o.UserOrGroupId, o.RowCause, o.OpportunityAccessLevel From OpportunityShare o where o.UserOrGroupId = :UserInfo.getUserId() AND o.OpportunityId = :oppId];
     edit = (!opp.Revenue_From_Order__c && SharedWith.Size() > 0);  //Allow edit if the check box is not checked (as before) and the user has a share on the Opportunity.
   
    edit = (edit || SecurityFunctions.hasPrivilege(SecurityFunctions.CanEditOpportunityRevenue)); // Allow Edit if they are an owner or SysAdmin
   
    system.debug('##########1 Edit: ' + edit);
   
    if(!edit)
    {
    string temp = opp.Name;
    system.debug('################1 Opp Name: ' + opp.name);
    opp.name = opp.Name + 'Edit';
    system.debug('################2 Opp Name: ' + opp.name);
    update opp;
    system.debug('################3 Opp Name: ' + opp.name);
    opp.name = temp;
    system.debug('################4 Opp Name: ' + opp.name);
    update opp;
    system.debug('################5 Opp Name: ' + opp.name);
    edit = true;
    }
     }
     catch (System.DmlException  DMLEx)
     {
     if(StatusCode.INSUFFICIENT_ACCESS_OR_READONLY == DMLEx.getDmlType(0))
     {
     system.debug('##########Exception - Edit Rights: None');
     edit = false;
     }
     else
     {
     system.debug('##########Exception - Another Exception');
     edit = true;
     }
    
     system.debug('##########2 Edit: ' + edit);
    return (edit || SecurityFunctions.hasPrivilege(SecurityFunctions.CanEditOpportunityRevenue)); // Allow Edit if they are an owner or SysAdmin
     }
        
     system.debug('##########2 Edit: ' + edit);
     return (edit || SecurityFunctions.hasPrivilege(SecurityFunctions.CanEditOpportunityRevenue)); // Allow Edit if they are an owner or SysAdmin
    }

 

Why is it that you can only search on the 'Name 'field of custom objects when performing a search via a lookup button? I want to be able to search on other fields in my custom objec

 

Would be interested to hear from others who have overcome the same issue.

 

Thanks :smileyhappy:

 

 

Hi everyone. Is there any method to communicate with 2 visualforce pages?? I have tried with the ids(the inputText id,or page id), but it does not work at all. I have tried with apex controllers too.Here,I can use getter setter methods. But since I cannot pass value to controller through JavaScript I am not able to achieve this task. Is there any solution?? I have tried with 'static' variable too. As we know its meaning is different in Apex, we cannot use it for different pages. Any suggestions will be helpful Thanks in advance.

I have a VF page that I'm embedding in a standard page layout. I'd like to pass a parameter into the VF page. The VF page's controller will look at the parameter and the current record, then decide what to display on the embedded page.

 

I have the VF page and controller written. But how can I get the standard page layout editor to pass a parameter in to the VF page? Is that even possible? If not, do you have any other suggestions?

 

Thanks!

  • May 08, 2010
  • Like
  • 0

Hi, 

 

I need to get the ids of Similar Opportunities  with Apex code?

 

Regards,

Deepak 

 

 

I'm using actionSupport to re-render a pageBlockTable. The problem is that it does a rerender everytime the event (onchange or onblur) occur. Is there anyway to rerender the section conditionally? For example, I wouldn't want it to rerender if the field on which the actionSupport is added to is blank.

 

 

<apex:column style="white-space : nowrap;">

<apex:facet name="header">Account</apex:facet>

<apex:inputtext id="account" value="{!element.accName}" size="22">

<apex:actionSupport event="onblur" action="{!element.setAcc}" rerender="{!$Component.transferTable},pageMessages"/>

</apex:inputtext></apex:column>

 

Thanks in advance,

-Manu 

 

 

Message Edited by md1 on 12-01-2010 02:43 PM
  • January 12, 2010
  • Like
  • 0

I have a simple Batch Apex class called from a trigger on the User object that updates a field on the Accounts owned by the User if a corresponding field is updated on the User.

 

All's working well as regards functionality, but the test method does not seem to be calling the Execute.

 

The trigger:

 

trigger au_User on User (after update) {

List<id> usersToUpdate = new List<id>();

//Loop through the trigger set for (integer iterator=0; iterator<trigger.new.size(); iterator++){

//Add the Users to collection where the values of the given fields have changed

if(trigger.new[iterator].Super_Sector_Region__c <> trigger.old[iterator].Super_Sector_Region__c){

usersToUpdate.add(trigger.new[iterator].id);

}

}

AccountUpdaterBatch batch = new AccountUpdaterBatch();

batch.usersToUpdate = usersToUpdate;

Database.executeBatch(batch, 20);

}

 

 The batch apex class:

 

 

global class AccountUpdaterBatch implements Database.Batchable<SObject>, Database.Stateful{

public List<id> usersToUpdate = new List<id>();

global Database.QueryLocator start(Database.BatchableContext BC){

String query='select a.id, a.Sector_Region__c, a.Owner.Super_Sector_Region__c'

+' from Account a where a.OwnerId IN :usersToUpdate';

return Database.getQueryLocator(query);

}

global void execute(Database.BatchableContext BC, List<sObject> scope){

List<Account> accns = new List<Account>();

for(sobject s : scope){

Account a = (Account)s;

if(a.Sector_Region__c != a.Owner.Super_Sector_Region__c)

a.Sector_Region__c = a.Owner.Super_Sector_Region__c;

accns.add(a);

}

update accns;

system.debug('####### Number of accounts updated'+accns.size());

}

global void finish(Database.BatchableContext BC){ //Do nothing }

 

}

 

The test method:

 

 

static testMethod void testUserTrigger(){

User currentUser = [Select u.Super_Sector_Region__c, u.Id From User u Where u.Id =: UserInfo.getUserID()];

List<Account> testAccs = new List<Account>();

for(integer i=0;i<90;i++){

Account testAccount = new Account(Name = 'TestAccount'+i, OwnerId = currentUser.Id);

testAccs.add(testAccount);

}

insert testAccs;

Test.starttest();

currentUser.Sector_Sales_Team__c = 'Test1';

update currentUser;

AccountUpdaterBatch testBatch = new AccountUpdaterBatch();

testBatch.usersToUpdate = new List<id>{currentUser.Id};

Database.executeBatch(testBatch, 20);

test.stoptest();

}

 

 

 

 Finally, the dump from the test log that shows that the start method was called, but the execute wasn't:

 

 

20100110162747.501:External entry point: returning Database.QueryLocator from method global Database.QueryLocator

start(Database.BatchableContext) in 0 ms

20100110162747.501:Class.AccountUpdaterBatch.start: line 35, column 10: SOQL locator query with 93 rows finished in 122 ms

Cumulative resource usage:

..

..

..

..

 

20100110162738.641:Class.TestAccountTrigger.testUserTrigger: line 123, column 3: returning from end of method global static void stopTest() in 5760 ms

 

20100110162738.641:External entry point: returning from end of method static testMethod void testUserTrigger() in 9065 ms

 

 Can someone please guide me as to what I'm missing or doing wrong?

 

Thanks,

 

-Manu 

Message Edited by md1 on 10-01-2010 04:36 PM
  • January 10, 2010
  • Like
  • 0

When developing a Visualforce page for overiding view page for any object, one problem that creeps up is to display the History details of a record. The standard related list Component doesn't works for History.

 

With the help of some code from Community ( I now can't find the link to it :( ), I wrote my own code  then to display the history of an object. It mimics the standard list as far as possible.  

 

Heres the code. It is for the Case object but it can be used for any other object.

 1.Component Code

 

<apex:component controller="CaseHistoriesComponentController">
<!-- Attribute Definition -->
<apex:attribute name="CaseId" description="Salesforce Id of the Case whose Case History needs to be rendered" type="Id" required="true" assignTo="{!caseId}" />

<!-- Case History Related List -->
<apex:pageBlock title="Case History">
<apex:pageBlockTable value="{!histories}" var="History" >
<apex:column headerValue="Date" value="{!History.thedate}"/>
<apex:column headerValue="User"> <apex:outputLink value="/{!History.userId}"> {!History.who} </apex:outputLink></apex:column>
<apex:column headerValue="Action"><apex:outputText escape="false" value="{!History.action}"/></apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:component>

 

 

 

 

2. Apex Code

 

public class CaseHistoriesComponentController {

public Id caseId {get; set;}
public cHistories[] histories;

// Variables
public Static final Map<String, Schema.SObjectField> CaseFieldmap = Schema.SObjectType.Case.fields.getMap();
public Static final List<Schema.PicklistEntry> fieldPicklistValues = CaseHistory.Field.getDescribe().getPicklistValues();

public List<cHistories> getHistories()
{
list<cHistories> histories = new list<cHistories>();
String prevDate = '';
for(CaseHistory cHistory : [Select CreatedDate, CreatedBy.Name, CreatedBy.Id, Field, NewValue, OldValue from CaseHistory where CaseId = :caseId order by CreatedDate desc])
{
if((cHistory.newValue == null && cHistory.oldValue == null)
|| (cHistory.newValue != null && !(string.valueOf(cHistory.newValue).startsWith('005') || string.valueOf(cHistory.newValue).startsWith('00G')))
|| (cHistory.oldValue != null && !(string.valueOf(cHistory.oldValue).startsWith('005') || string.valueOf(cHistory.oldValue).startsWith('00G'))))
{
cHistories tempHistory = new cHistories();
// Set the Date and who performed the action
if(String.valueOf(cHistory.CreatedDate) != prevDate)
{
tempHistory.theDate = String.valueOf(cHistory.CreatedDate);
tempHistory.who = cHistory.CreatedBy.Name;
tempHistory.userId = cHistory.CreatedBy.Id;
}
else
{
tempHistory.theDate = '';
tempHistory.who = '';
tempHistory.userId = cHistory.CreatedBy.Id;
}
prevDate = String.valueOf(cHistory.CreatedDate);

// Get the field label
String fieldLabel = CaseHistoriesComponentController.returnFieldLabel(String.valueOf(cHistory.Field));

// Set the Action value
if (String.valueOf(cHistory.Field) == 'created') { // on Creation
tempHistory.action = 'Created.';
}
else if(cHistory.OldValue != null && cHistory.NewValue == null){ // when deleting a value from a field
// Format the Date and if there's an error, catch it and re
try {
tempHistory.action = 'Deleted ' + Date.valueOf(cHistory.OldValue).format() + ' in <b>' + fieldLabel + '</b>.';
} catch (Exception e){
tempHistory.action = 'Deleted ' + String.valueOf(cHistory.OldValue) + ' in <b>' + fieldLabel + '</b>.';
}
}
else{ // all other scenarios
String fromText = '';
if (cHistory.OldValue != null) {
try {
fromText = ' from ' + Date.valueOf(cHistory.OldValue).format();
} catch (Exception e) {
fromText = ' from ' + String.valueOf(cHistory.OldValue);
}
}

String toText = '';
if (cHistory.OldValue != null) {
try {
toText = Date.valueOf(cHistory.NewValue).format();
} catch (Exception e) {
toText = String.valueOf(cHistory.NewValue);
}
}
if(toText != '')
tempHistory.action = 'Changed <b>' + fieldLabel + '</b>' + fromText + ' to <b>' + toText + '</b>.';
else
tempHistory.action = 'Changed <b>' + fieldLabel;
}

// Add to the list
histories.add(tempHistory);
}
}

return histories;
}

// Function to return Field Label of a Case field given a Field API name
public Static String returnFieldLabel(String fieldName)
{
if(CaseHistoriesComponentController.CaseFieldmap.containsKey(fieldName))
return CaseHistoriesComponentController.CaseFieldmap.get(fieldName).getDescribe().getLabel();
else
{
for(Schema.PicklistEntry pickList : fieldPicklistValues)
{
if(pickList.getValue() == fieldName)
{
if(pickList.getLabel() != null)
return pickList.getLabel();
else
return pickList.getValue();
}
}
}
return '';
}
// Inner Class to store the detail of the case histories
public class cHistories {

public String theDate {get; set;}
public String who {get; set;}
public Id userId {get; set;}
public String action {get; set;}
}
}

  Let me know your views on the code or if you have any questions

 

I'm trying to test an Apex method that calls an @future method.  I looks like my testing works up until the point where the @future test is called.  The test checks some results from the @future method and it looks like they haven't been executed yet.

 

Does @future execute asyncronously in test mode?

 

If so, how does one test @future methods?

 

 

I can use new SelectOption('value', 'label') to create many dropdown (<select>) options but how do I create groups around them?  <optgroup> is a fairly common HTML tag and I can't figure out how to make half the list be in one <optgroup> and the 2nd half in another <optgroup> but still part of the same dropdown.

 

With some luck someone understands what I mean and can point me in the right direction.  Best I can do now is think about how to do it with javascript after the page renders.

Hi All,

 

I would like to be able to call the SF Metadata API from Apex code in my custom app.

 

I went to Setup/App Setup/Develop/API and clicked on 'Download Metadata WSDL' and saved it to my hard drive.

 

Then I went to Setup/App Setup/Develop/ApexClasses and clicked on the 'Generate from WSDL' button. For Step 1, I navigate to the Metadata WSDL that I just saved and click 'Parse WSDL.' This takes me to the Step 2 screen where I then click on the 'Generate Apex code' button.

 

This takes me to the Step 3 screen which shows this error:

 

<error>

Apex generation failed.

Error message:
Error: Class name 'Metadata' already in use. Please edit WSDL to remove repeated names

 

</error>

 

Does this error mean that what I am attempting to do is not allowed? If it is allowed, how do I get around this error.

 

Any help would be appreciated.

 

Thanks,

Andrew

The Eclipse Force.com IDE Schema Browser doesn't display "OldValue" and "NewValue" column values for History tables.

To see the problem, open the Schema Browser, (click on "salesforce.schema" at the bottom of the project in package explorer,) and click on any "__History" table. (A table for which "track field history" is turned on.) When you click on the checkbox to create a query with all fields and run the query, (you might want to add a "limit 100" to the query first,) you will see all the columns, and every column has values except "OldValue" and "NewValue".

If you query the history table through another means, such as SQL Server/DBAmp, the values show in the columns.

My Force.com IDE version is up to date at 13.0.0.200806130415.


Message Edited by Jim Cripe on 10-06-2008 10:23 AM
Hello there,
I wanted to find out the max(of a list of Dates) .e.g: Select PSOD_Project__r.Name,Resource__r.Name,max(Period_Beginning__c) from Time_Sheet__c where PSOD_Project__r.Name = 'PSOD Internal'

This is not working; Any hints whether this is feasible at all in SOQL ? if so, help pls.



Thanks,
Arun B