Skip to main content

Formatting the new time field of Salesforce in Visualforce Page

The Time class in Salesforce is very limited, especially compared to the DateTime class. It doesn't even have its own format method, which I think may be the underlying problem here. Without a format method to accept the formatting string, Salesforce might not be able to properly format the field.

So I have created a method which will convert the time in AM/PM and it will show on the vf page as it is formatted.


public String formatedTime(Time timeValue){

        String hh;
        String mm;
        String ampm;

        if(timeValue != null){
            if(timeValue.hour() <= 12){
                if(timeValue.hour() == 0){
                    hh = String.valueOf(timeValue.hour() + 12);
                }else{
                    hh = String.valueOf(timeValue.hour());
                }
            }
            else{
                hh = String.valueOf(timeValue.hour() - 12);
            }
            
            if(timeValue.minute() < 10){
                mm = '0'+String.valueOf(timeValue.minute());
            }
            else{
                mm = String.valueOf(timeValue.minute());
            }
            
            if(timeValue.hour() < 12){
                ampm = 'AM';
            }
            else{
                ampm = 'PM';
            }
            
            return hh+':'+mm+' '+ampm;
        }else{
            return '';
        }
    }




Comments

Popular posts from this blog

Database Methods

Database Methods Apex contains the built-in Database class, which provides methods that perform DML operations and mirror the DML statement counterparts. These Database methods are static and are called on the class name. Database.insert() Database.update() Database.upsert() Database.delete() Database.undelete() Database.merge() Unlike DML statements, Database methods have an optional allOrNone parameter that allows you to specify whether the operation should partially succeed. When this parameter is set to false , if errors occur on a partial set of records, the successful records will be committed and errors will be returned for the failed records. Also, no exceptions are thrown with the partial success option. This is how you call the insert method with the allOrNone set to false . Database.insert(recordList, false); The Database methods return result objects containing success or failure information for each record. For example, insert and update...

DML Manipulation

Manipulate Records with DML Create and modify records in Salesforce by using the Data Manipulation Language, abbreviated as DML. DML provides a straightforward way to manage records by providing simple statements to insert, update, merge, delete, and restore records. Because Apex is a data-focused language and is saved on the Lightning Platform, it has direct access to your data in Salesforce. Unlike other programming languages that require additional setup to connect to data sources, with Apex DML, managing records is made easy! By calling DML statements, you can quickly perform operations on your Salesforce records. This example adds the TCS  account to Salesforce. An account sObject is created first and then passed as an argument to the insert statement, which persists the record in Salesforce. // Create the account sObject Account acct = new Account(Name='TCS', Phone='(123)456-7890', NumberOfEmployees=100); // Insert the account by using DML insert ...

Salesforce Licenses

For Developer Edition: User Licenses (A user license determines the baseline of features that the user can access.) Name Total License Salesforce 2 Salesforce Platform 3 Customer Community Login 5 XOrg Proxy User 2 Work.com Only 3 Customer Portal Manager Custom 5 Identity 10 Customer Community Plus 5 Silver Partner 2 Gold Partner 3 Customer Portal Manager Standard           5 Force.com App Subscription 2 Customer Community Plus Login 5 Partner App Subscription 2 External Identity 5 Partner Community 5 Partner Community Login 5 Customer Community 5 Force.com – Free 2 Chatter Free 5000 Chatter External 500 High Volume Customer Portal 10...