Thursday 26 March 2015

System.TypeException: Invalid date in Salesforce

        Hope most of the peoples may across such issue "System.TypeException: Invalid date", while converting String to Date format. This article for how to convert string to date.


Parse Method

      Constructs a Date from a String. The format of the String depends on the local date format.

Note: Parse method based on User locales.

Examples based on Locale

Locale --> English (United States) --> String format should be mm/dd/yyyy


  1. String str = '03/26/2015';
  2. Date mydate = Date.parse(str);
  3. System.debug(mydate);

Locale --> English (India) --> String format should be dd/mm/yyyy

  1. String str = '26/03/2015';
  2. Date mydate = Date.parse(str);
  3. System.debug(mydate);


If you provide wrong string format, then you will receive an System.TypeException Invalid Date Error.

ValueOf Method

     Returns a Date that contains the value of the specified String. The String should use the standard date format “yyyy-MM-dd HH:mm:ss” in the local time zone. 
    

Example


  1. string year = '2008';
  2. string month = '10';
  3. string day = '5';
  4. string hour = '12';
  5. string minute = '20';
  6. string second = '20';
  7. string stringDate = year + '-' + month
  8.  + '-' + day + ' ' + hour + ':' +
  9. minute + ':' + second;
  10. Date myDate = date.valueOf(stringDate);


Refer more at,
http://www.salesforce.com/us/developer/docs/dbcom_apex230/Content/apex_methods_system_date.htm

Monday 23 March 2015

Integrating Google Map Using New Spring 15 Visualforce Components

            Most of us already known about the Google Map integration in Salesforce. For integrating Google map in previous releases we used Java script calls, referring some of resource files, etc.  But in Spring’15 release it is too simplified. There are two new Visualforce mapping components introduced that are,

            <apex: map>              - Display an interactive map with Zooming, Scrolling, markers.
            <apex: mapMarker>    - Defines a marker to be displayed at a location.

Steps to Enable Map Feature

Before using this new feature, we need to enable this in salesforce organization,

            Go to App Setup in the Side Bar à Maps and Location à Setting à Edit à Check Enable Maps and Location Services.

  1. <apex:page standardController="Account">
  2.     <apex:pageBlock>
  3.         <apex:map width="1000px" height="400px" mapType="roadmap"
  4.                   center="{!Account.BillingStreet},{!Account.BillingCity},{!Account.BillinState}">
  5.             <apex:repeat value="{!Account.Contacts}" var="contact">
  6.                 <apex:mapMarker title="{!contact.Name}"
  7.                                 position="{!contact.MailingStreet},{!contact.MailingCity},{!contact.MailingState}"/>
  8.             </apex:repeat>
  9.         </apex:map>
  10.     </apex:pageBlock>
  11. </apex:page>

Limitation

1. Visualforce mapping components aren’t currently available in Developer Edition organizations.
2. There’s a limit of 10 geocoded address lookups per page request. It means you can see maximum of 10 pointers in the map.  Center and Position attribute values counted in this limit.

Reference



Allow only positive numbers in textbox using javascript in salesforce

            Find the below simple JavaScript code to allow only positive numbers in textbox. The below script done using javascript keyboard events. This will prevent users from entering other characters except numbers.

Example:

  1. <apex:page standardController="Account">
  2.    
  3.     <script type="text/javascript">
  4.    
  5.     function isNumber(evt)
  6.     {
  7.         evt = (evt) ? evt : window.event;
  8.         var charCode = (evt.which) ? evt.which : evt.keyCode;
  9.         if(charCode > 31 && (charCode < 48 || charCode > 57))    
  10.         {
  11.             alert('Please enter positive number only');
  12.             return false;
  13.         }
  14.         return true;
  15.     }
  16.    
  17.     </script>
  18.    
  19.     <apex:form >
  20.         <apex:pageBlock >
  21.             <apex:pageBlockSection >
  22.                 <apex:inputField value="{!Account.Name}"/>
  23.                 <apex:inputField value="{!Account.AccountNumber}" onkeypress="return isNumber(event)"/>
  24.             </apex:pageBlockSection>
  25.         </apex:pageBlock>
  26.     </apex:form>
  27.    
  28. </apex:page>

Thanks to StackExchange 

Reference: Keyboard events


Friday 20 March 2015

How to Convert UTC Time Zone to User Time Zone in Salesforce

SOQL queries in a client application return dateTime field values as Coordinated Universal Time (UTC) values. You need to manually handle to convert this UTC time zone to your User Time zone.

For this salesforce provides, convertTimezone method. But You can use convertTimezone() in a date function.


Let see how to convert UTC time zone to User Time Zone,

  1. DateTime scheduleTime = DateTime.valueofGmt( ‘Your Date Time to be Convert’);
  2. // Get User time zone.              
  3. Timezone userTimezone = UserInfo.getTimezone();
  4. Integer userOffset = userTimezone.getOffset(scheduleTime);
  5. // Get Organization time zone.
  6. Timezone orgTimeZone = Timezone.getTimezone('America/Los_Angeles');
  7. Integer orgOffset = orgTimezone.getoffset(scheduleTime);
  8. Integer offsetDifference = orgOffset - userOffset;
  9. // DateTime is converted from UTC timezone to User Timezone
  10. DateTime correctedDateTime = scheduleTime.addMinutes(offsetDifference / (1000 * 60));

Wednesday 4 March 2015

Salesforce Spring'15 Maintenance / Release Exam Notes

     
       Here is the quick summary of salesforce.com Spring'15 release notes, This will be very helpful for your maintenance exam.

Wave – The Analytics Cloud

1.       It gives anyone in the company answers to any questions from multiple business apps, databases and big data.
2.       Explore millions of data points in your fingertips.
3.       Answer in the palm of your hand using mobile device.
4.       Conversation around data.
5.       Multiple source data and multiple type data(Structured, Semi-Structured, Unstructured)
6.       Access from any device and no need to maintain s/w or h/w or maintenance.

Create New Task Action

1.       Allows users to create tasks directly from a chatter feed.
2.       To avail this feature to end user in side bar set up menu,
Build à Customize à Chatter à Fee Item à Layout à Drag and Drop the Create New Task

Questions to Case

1.       Allow administrators to escalate chatter questions directly from feed.
2.       Administrators can use lightning process builder to automatically create cases from questions based on specific criteria.

Lightning Process Builder

1.       It’s a workflow tool that allows administrators and developer to automate businsess processes using a visual interface.
2.       Automate everything from daily tasks to complex process.
3.       Creates the entire process in one place.
4.       Eliminates use of Apex to automate simple task.
5.       You can access this Under Workflow & Approvals à Process Builder
With this tool you can do the following actions,
·         Apex – Triggering  Apex
·         Create a Record
·         Email Alerts
·         Flows
·         Post to Chatter
·         Quick Actions
·         Submit for Approval
·         Update Records


General Enhancement

1.       Publisher Actions renamed to Quick Action. It allows create, update records and log a call.
2.       Publisher Actions section renamed to Action in the Publisher.
3.       Enable Publisher Actions options renamed to Enable Actions in the Publisher.

Manager Groups

1.       Manager Groups allows users to share records up or down their management chain.
2.       To enable this features Go to Setup à Security Controls à Sharing Settings à Edit.
3.       Users can share records by Manual Sharing, Sharing Rule and Apex Managed Sharing.
4.       Do not include portal users and it contains only standard and chatter only users.


Import My Account & Contacts

1.       You can import account and contact from 16 data sources into salesforce. As of now, this feature avail in new and trail organization.

Duplicate Management

1.       It allows maintains clean and accurate data.

Report enhancement

1.       End users can subscribe to a report to receive report notifications
2.       Each user can subscribe up to five reports.
3.       User need to Subscribe in the Report run page. This feature enabled by default and you can disable it for this Go to Setup à Report and Dashboard à Report Notifications.

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...