Amazon

Sunday, May 31, 2015

HOW TO CONVERT STRING TO DATE IN SALESFORCE

THE FOLLOWING IMAGE SHOWS THE STRING FORMAT OF JAVASCRIPT

CONVERSION CODE IS HERE

Map <String, Integer> monthNames = new Map <String, Integer> {'Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12};

extendAppEnd = 'Sun May 31 2015 09:30:00 GMT+0000';

//split the string based on spaces first
List <String> stringParts = extendAppEnd.split(' ');

The list after spliting like the follow values

/*stringParts[0] = 'Sun'
stringParts[1] = 'May'
stringParts[2] = '31'
stringParts[3] = '2015'
stringParts[4] = '09:30:00'
stringParts[5] = 'GMT+0000' */

//and split the time string based on ( : ).
List <String> timeParts = stringParts[4].split(':');
he list after spliting like the follow values

/*timeParts [0] = 09
timeParts [1] = 30
timeParts [2] = 00*/


DateTime dt= DateTime.newInstanceGmt(Integer.valueOf(stringParts[3]), monthNames.get(stringParts[1]), Integer.valueOf(stringParts[2]), Integer.valueOf(timeParts[0]), Integer.valueOf(timeParts[1]), Integer.valueOf(timeParts[2]));

OUTPUT

2015,5,31,09,30,00



Wednesday, May 27, 2015

How To Show Current User Details With Profile Photo In Visualforce Page

Apex Controller Class

public class Result_page
{  
    public string photo{get;set;}
    public string idval{get;set;}
    public string today{get;set;}
   
    public  Result_page ()
    {
        today = DateTime.now().format('EEEEEEEEE')+' '+DateTime.now().format('MMMMMMMMM')+' '+DateTime.now().format('dd')+', '+DateTime.now().format('YYYY');
    }
   
    public void uid()
    {
        system.debug('id value'+idval);
        User u = new User();
        photo = [select SmallPhotoUrl from User where id = :idval].SmallPhotoUrl;
        system.debug('photo value'+photo);
    }  

}


Visualforce Page

<apex:page controller="Result_page" id="pg">
<!-- Define Your Jquery Script To Call Action Function-->
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
    $(document).ready
    (
        function()
        {
            sendid();
         }
     );
</script>
<apex:form >
    <!-- Define Action Function To Send User Id To Controller-->
    <apex:actionFunction name="sendid" action="{!uid}" reRender="user">
        <apex:param name="idv" value="{!$User.Id}" assignTo="{!idval}"/>
    </apex:actionFunction>
    <!-- Design your Page-->
    <apex:outputPanel layout="block" styleClass="bPageTitle" id="user">
        <apex:outputPanel layout="block" style="display:inline;" styleClass="ptBody secondaryPalette">
            <apex:outputPanel layout="block">
                <apex:outputPanel layout="block" style="float:left;margin-right:10px;">
                    <a href="/_ui/core/userprofile/UserProfilePage">
                        <apex:image value="{!photo}" height="40"/>
                    </a>
                </apex:outputPanel>
            </apex:outputPanel>
            <apex:outputPanel layout="block">
                <apex:outputPanel layout="block" style="font-size:16px;color:#015ba7;">
                   <a href="/_ui/core/userprofile/UserProfilePage" style="text-decoration:none;">
                       {!$User.FirstName} {!$User.LastName}
                   </a>
                </apex:outputPanel>
                <apex:outputPanel layout="block" style="font-size:11px;color:#015ba7;margin-top:10px;">
                    {!today}
                </apex:outputPanel>
            </apex:outputPanel>
            <apex:outputPanel layout="block" style="float:right;">
                <apex:outputPanel layout="block" style="">
                    <!-- Define Your Help Links Here -->
                </apex:outputPanel>
            </apex:outputPanel>
        </apex:outputPanel>
    </apex:outputPanel>
</apex:form >

</apex:page>

OutPut