In Salesforce, if I'm binding a date into a VisualForce page, how do I apply custom formatting to it?
Example:
<apex:page standardController="Contact">
<apex:pageBlock title="Test">
<p>{!contact.Birthdate}</p>
</apex:pageBlock>
<apex:detail relatedList="false" />
</apex:page>
This will output a date in the default format:
Thu Jul 01 09:10:23 GMT 2009
How do I get it (for example) into dd/mm/yyyy format, like this:
01/07/2009
(Hopefully this is a fairly easy question, but to get the Salesforce community going on here I figure we need a few easy questions.)
<apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
<apex:param value="{!contact.Birthdate}" />
</apex:outputText>
link to full doc: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_outputText.htm
The answer seems to depend on context. I have one VF page which pre-populates the Subject line of a task with the value of NOW(). To record it with the user's Locale settings, I included methods in the controller to format date and datetime fields, along these lines:
Datetime myDT = Datetime.now();
String myDate = myDT.format();
But just now in another VF page where I'm merely displaying a datetime field, I confirmed that SFDC handled formatting based on the user's Locale setting. That was in this context, where cm.CampaignMembers is a variable from the controller:
<apex:column>
<apex:pageBlockTable value="{!cm.CampaignMembers}" var="cmp" >
<apex:column headerValue="" value="{!cmp.Campaign.Name}" />
<apex:column headerValue="" value="{!cmp.Status}" />
<apex:column headerValue="" value="{!cmp.FirstRespondedDate}" />
<apex:column headervalue="" value="{!cmp.CreatedDate}" />
</apex:pageBlockTable>
</apex:column>
Related
This is my visualforce markup
<apex:form id="importForm">
<apex:pageBlock>
<apex:pageBlockSection>
<apex:inputFile value=”{!csvInput}” accept=".csv" disabled="{!enableFileInput}"/>
<apex:commandButton value=”Import” action=”{!readCsvInput}”/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
I get this error while deploying the page
Open quote is expected for attribute "value" associated with an element type "apex:inputFile"
How do I resolve this?
MS Word, Outlook or something like that tried to be helpful and screwed up your quotes. They need to be straight ", not fancy hipster ”
https://support.microsoft.com/en-us/office/smart-quotes-in-word-702fc92e-b723-4e3d-b2cc-71dedaf2f343
I am new to Apex. I am trying to create an object with 2 fields : Subject(Text) and Description(Rich Text Area). This should be displayed in a table format. The description should display only the first 50 characters, and onclick on the description, it should open a new Visualforce page to display the entire content.
<apex:page controller="Notes_Controller" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!recordsList}" var="n">
<apex:column value="{!n.Subject__c }" headerValue="Subject"/>
<apex:column styleClass="slds-truncate" headerValue="Description">
<apex:facet name="header">Description</apex:facet>
<apex:outputLink value="{!n.Description__c}" target="_blank">{!LEFT(n.Description__c,50)}
</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
So far I have tried the above, but I am unable to get the entire description to open up in a new tab.
Any ideas?
Can this be done using a formula field ?
I tried using outputlink where value = description and label is the subject, such that click on the subject name will take you to the description. But I get "Url does not exist".
Any help is appreciated.
In the apex:outputLink you can try the value attribute specify URLFOR with the action and Id.
Something like
<apex:outputLink value="{!URLFOR($Action.n.Description__c)}" target="_blank">{!LEFT(n.Description__c,50)}
</apex:outputLink>
The apex:outputlink value should be a url.
URLFOR(Description__c) will not work since Description is a text field.
Try <apex:outputLink value="/{!n.id}" target="_blank">{!LEFT(n.Description__c,50)}</apex:outputLink>
See apex:outputLink
**<p>(! c.FirstName &''& c.lastName)</p>**
(Error:The entity name must immediately follow the '&' in the entity reference in visualforce)
</apex:repeat>
</apex:outputPanel>
This is the error I'm getting. Can anyone please tell me what changes to make in the VF page to display the contact's First and Last names.
for ampersand you have to use
&
This is the correct code
<apex:outputPanel id="contactdisplay">
<apex:repeat value="{! contactinformation }" var="c">
*<p>{! c.Firstname &' '& c.LastName}</p>*
</apex:repeat>
</apex:outputPanel>
Note - Make use of flowerbrackets.
<apex:page controller="MyController" sidebar="false">
<apex:form >
<apex:inputText size="36" value="{!Str}"/>
<apex:commandButton onClick="alert('{!Str}');" value="Alert"/>
</apex:form>
The code is just to pop out an alert window to display the input. However, it seems not a possible to do so with Salesforce apex since it's a server-side language. Am I correct ?
Fou new value of str you nead select it by javaScript or jQuery.
apex:inputText styleClass="str" value="{!Str}"
'alert($('.str').value())'
I want to display the apex:column header in 2 lines. I have column with the header as "Distributed Total" I want to show in 2 lines
<apex:column headerValue="Distributed Total$">
<apex:outputText value="${0, number, ###,##0.00}">
<apex:param value="{!item.Dtotal}"/>
</apex:outputText>
</apex:column>
Any idea how we can achieve this
Thanks
Pradip
If I understand the question, you want a column header than spans 2 lines?
<apex:column>
<apex:facet name="header">
Distributed<br/>Total$
</apex:facet>
<apex:outputText value="${0, number, ###,##0.00}">
<apex:param value="{!item.Dtotal}"/>
</apex:outputText>
</apex:column>
I would try to play with <br/> tag.