12 votes
Accepted

How to format Apex code more flexible than with Prettier

Prettier by design does not really allow customization of the formatting, this is why it is an "Opinionated Source Formatter". For Apex, your formatting options are limited to the following ...
Alan Morey's user avatar
  • 2,421
7 votes
Accepted

LWC HTML formatting using prettier

Follow this. You have to override the html formatter with lwc as parser - note that it will not retrospectively "fix" your markup which means the quotes will stay but at least it should not add them ...
Renji-xD's user avatar
  • 2,791
6 votes
Accepted

Formatting Datetime.now()

You are on the right track that you need to pass in a specific format string to Datetime.now().format(...). Notice how you escape the T in your current format: Datetime.now().format('yyyy-MM-dd\'T\'...
Adrian Larson's user avatar
  • 150k
6 votes
Accepted

Prettier errors out when formatting Apex classes

Posting this so others can find it useful: If you run into this error, make sure to update your java version to at least 11 as prettier-plugin-apex version 1.9.0 and above doesn't support for jdk ...
javanoob's user avatar
  • 8,847
5 votes

Any formatting JavaScript APIs in LWC?

You can access the user's locale via the i18n library methods, which you can then pass in to LWC datatable's typeAttributes: import USERLOCALCURRENCY from '@salesforce/i18n/currency'; ... { label: '...
sfdcfox's user avatar
  • 487k
5 votes

Is the time-zone attribute broken in lightning-formatted-date-time?

@keith-c, thank you for your question. I work at Salesforce, and reviewed the component, and the documentation along with a colleague on the Docs team. If you are setting the attribute time-zone=&...
sfcbweb's user avatar
  • 51
5 votes
Accepted

Use Prettier in VS Code to format Visualforce

I believe I have found a solution. Inside of the vscode settings file the following line needs to be added: "prettier.documentSelectors": ["**/*.page"] Per prettier vscode ...
Michael Schirger's user avatar
5 votes

formatGMT YYYY returning next year and yyyy returning this year?

YYYY is week based calendar. yyyy is our ordinary calender. This is not SF behavior. but something expected whenever you use yyyy or YYYY as they are derived from java SimpleDateFormat. Even SF ...
Pranay Jaiswal's user avatar
4 votes

Formatting Negative Numbers with Parentheses

While Ralph Callaway's example is technically correct, it can be simplified. There is no need for conditional rendering of the <apex:outputText> elements, or multiplying the value by -1. ...
Alan Morey's user avatar
  • 2,421
4 votes
Accepted

Format date from: 01/01/2017 to 1/1/2017

Just change: MM/dd/yyyy to: M/d/yyyy
Adrian Larson's user avatar
  • 150k
4 votes
Accepted

Formatting as a currency on a VF page

One small change required, declare the apex:param tag inside the apex:outputText. <apex:column> <apex:facet name="header">AUM</apex:facet> <apex:outputText value="{0, ...
Hemant Jain's user avatar
  • 2,775
4 votes
Accepted

make text highlighted red & bold if criteria is met?

As of now Salesforce doesn't support conditional formatting of field values even for formula fields. This is still in Idea stage https://success.salesforce.com/ideaView?id=08730000000BrPbAAK. Only ...
Saroj Bera's user avatar
  • 14.7k
4 votes
Accepted

Prettier formatting tabSize and printWidth

After running the install command: npm install --save-dev --save-exact prettier prettier-plugin-apex Restart VS Code. Then, go to View > Command Palette... and find the command "Prettier: Create ...
sfdcfox's user avatar
  • 487k
4 votes

formatGMT YYYY returning next year and yyyy returning this year?

Got the answer y return year of the era Y returns week year so in this last week of Dec when a/few day(s) of the week is/are of next year, YYYY will return 2021 (ie week year) and yyyy (as always) ...
Chirag Mehta's user avatar
  • 1,251
4 votes
Accepted

Is this a bug in Apex DateTime.format?

Duh NO. Some more Googling reveals this answer from a different language: Difference between 'YYYY' and 'yyyy' in NSDateFormatter that can be summarized as: use yyyy not YYYY and that fixes the ...
Keith C's user avatar
  • 136k
3 votes
Accepted

How to format a Visualforce inputField

You can use this code example to display number format in InputField. The getElementById() function will take dynamic component based on id attribute specified. <apex:pageBlockTable value="{!...
Santanu Boral's user avatar
3 votes
Accepted

Removing leading zeros in a string in a VFP page?

It can be done by VALUE function of visualforce: <apex:outputText value="{!VALUE(case.CaseNumber)}" />
Mukesh Verma's user avatar
  • 1,906
3 votes

Calculating the last day of next month using Ampscript

Just one additional thing to Adam Spriggs answer which might be a very valuable information. If your marketing cloud Date Format is not set on English the solution of Adam will NOT work inside email ...
Johannes Schapdick's user avatar
3 votes
Accepted

Calculating the last day of next month using Ampscript

You could do something like this: %%[ set @twoMonthsDate = dateadd(now(), 2, "M") set @month = DatePart(@twoMonthsDate, "M") set @year = DatePart(@twoMonthsDate, "Y") set @firstOfTwoMonthsDate = ...
Adam Spriggs's user avatar
  • 30.4k
3 votes
Accepted

How to fix formatting in <apex:pageBlockSection

When you are using actionRegion, you could loose your alignment, use pageBlockSectionItem and outputLabel to display corrrect label for field: Before changing, remove all your insufficient ...
Ilya Lepesh's user avatar
  • 4,115
3 votes
Accepted

How to get default field formatting with outputText?

Here is an outline of a solution (for dates and datetimes). Other data types I leave as an exercise for the reader You'll need a VF Component Controller public with sharing class UserLocale { ...
cropredy's user avatar
  • 70.8k
3 votes

How to convert a number into a formatted string?

This should work, if its until 2 decimals: Decimal dec; String amount; if (!string.valueof(dec.format()).right(3).contains('.')){ amount = '$' + string.valueof(dec.format()) + '.00'; }else if (...
Ravi's user avatar
  • 31
3 votes

Using lightning:input with type="number" and formatter="currency"

It looks like you already have the solution, I was able to accomplish this using the step attribute and setting it equal to 1. <lightning:input label="Input" type="number" formatter="currency" ...
byrner's user avatar
  • 81
3 votes
Accepted

Visualforce format an output number depending on decimal value, if decimal is zero then just display the number

This is the easiest trick. Multiply the value with 100 and then use MOD function to find the remainder upon diving 100. Basically, if value is 10.00 then it should be 10.00*100 = 1000, So MOD(1000,...
Santanu Boral's user avatar
3 votes

How to get current user date/time format in apex, e.g. MM/dd/YYYY hh:mm:ss a z

In Apex Code, DateTime.format without parameters will return the current date and time, in the user's locale formatting, in the user's current time zone, and Date.format without parameters will return ...
sfdcfox's user avatar
  • 487k
3 votes
Accepted

Is it possible to make text bold in a custom label?

If you're displaying it in Visualforce maybe try something like: <apex:outputText value="{!label}" escape="false"/> An alternative would be to create multiple labels for the different parts of ...
gNerb's user avatar
  • 9,471
3 votes

Date Format in VisualForce Page

You are using the value parameter in apex:commandlink so you're getting the date twice. If you remove it, it should work. <apex:commandLink action="{!timesheetDetails}" > <apex:...
David Cheng's user avatar
  • 7,070
3 votes
Accepted

Date formatting for SOQL String - unexpected output

It should be small dd aka dd-MM-YYYY Date dStart = System.today(); System.debug(DateTime.newInstance(dStart.year(), dstart.month(), dstart.day()).format('dd-MM-YYYY')); //13-11-2019 Format ...
Pranay Jaiswal's user avatar
3 votes
Accepted

Is there a way to invoke Salesforce's phone number formatter on a given string?

Probably not what you want but String s = UserManagement.formatPhoneNumber('1','6505551212'); String s = UserManagement.formatPhoneNumber('1','(650) 555 1212'); both produce +1 6505551212 reference ...
cropredy's user avatar
  • 70.8k
3 votes

In Apex, how can I format Datetime for Europe/Berlin without assuming the input value is GMT?

One option is to take the UTC Datetime value, convert it to Berlin time then extract the date and time (using the dateGmt() and timeGmt() methods on Datetime) values and present these as separate Date ...
Phil W's user avatar
  • 35.4k

Only top scored, non community-wiki answers of a minimum length are eligible