Useful Apex Functions Solution "SFApexUtilFunctions"

Thursday, March 31, 2011 by Aslam - The Alexendra
Hi All,
Most of time while devleoping Apex Code, we face many business requirements for which we develop our own logic and methods. Most of us written many useful methods so far in their development. So, my idea is simple. I welcome all of you to contribute your common useful apex methods with me and complete my "SFApexUtilFunctions" class. I have started this class with some of my reused methods. If we all contribute our useful methods then i am sure we will have a good library written which will be useful for all of us.

The format for contributing your methods will be like given as per below with the proper comments on method top describing method and author. You can post in blog itself or mail me. I will inform the newly added methods to all and update the actual class also. One can download the latest version of class from this url:

http://www.aslambari.com/SFApexUtilFunctions.cls




/**
@ Name SFApexUtilFunctions
@ Author Aslam Bari
@ Created Date 31 March, 2011
@ Description A utility methods class for helping developers community
*/
public class SFApexUtilFunctions{

/**
@ Name join
@ Author Aslam Bari
@ Created Date 31 March, 2011
@ Desctiption Join one list of String to a full string
@ Param List<String>: list of string data
@ Param separator: the string by which the list is joined
*/
public static string join(List<String> lstArg, String separator){
String fullString
= '';
for(String item: lstArg){
fullString
+= item + separator;
}
if(fullString.length() > 0)
fullString
= fullString.substring(0, fullString.length() - 1);

return fullString;
}

/**
@ Name getUrlContents
@ Author Aslam Bari
@ Created Date 31 March, 2011
@ Desctiption Fetch the contents of remote url
@ Param url: remote url with all parameters attached to url for GET call
*/
public static string getUrlContents(String url){
HttpRequest request
= new HttpRequest();
request.setEndPoint(url);
request.setMethod(
'GET');
Http call
= new Http();
HttpResponse response
= call.send(request);
return response.getBody();
}
}



So start now and lets contribute :)

Thanks
Aslam Bari

Simple SF Tree for VF Page

Friday, March 25, 2011 by Aslam - The Alexendra
Hi All,
Many times people need one solution for using Tree structure on thier VF page. There are many solution using JS/JQuery. Here i used jquery treeview plugin and created one apex component which can be used directly in you VF page. You simply need to use following syntax to embed this tree in your VF page:

<c:sftree />





Here is a working demo for this SF Tree.
http://labsprojects-developer-edition.ap1.force.com/sftreedemo

The component provides two JS method on click of parent and child node and send id of the node. You can define those methods in our VF page and do process whatever you need.


Mail me if you face any issue. Hope its helpful for some people.

Thanks
Aslam Bari

Using Map In Your VF Pages

Wednesday, March 16, 2011 by Aslam - The Alexendra
Hi All,
Most of you aware of this but i am sure most of you (like me) un aware about that we can use Map directly on VF pages. Atleast for me, it is a news :) . Anyway, i am going to show you how to use simple map on your VF page so that you can avoid Model class (If you making only because of thinking that VF does not support Map). Here I am going to show a simple program which counts duplicate accounts by name and shows on VF screen. Here Account Name is "key" of Map and the "value" part is count of duplicate account.





Class Code:
public class TestMapController{

public map<string,integer> data {get;set;}

public TestMapController(){
data
= new map<string,integer>();
for(Account acc: [Select Id, Name, (Select Id, Name, Email from Contacts), Phone from Account]){
integer count
= data.get(acc.name);
if(count != null)
count
++;
else
count
= 1;
data.put(acc.name, count);
}
}
}




VF Page Code:
<apex:page controller="TestMapController">
<apex:pageblock title="Map Usage On VF">
<apex:pageBlockTable value="{!data}" var="d">
<apex:column headerValue="Account Name">
{!d}
</apex:column>
<apex:column headerValue="Duplicate Count">
{!data[d]}
</apex:column>
</apex:pageBlockTable>
</apex:pageblock>
</apex:page>



Hope this will help new developers who struggle to manage and show their data model on pages.

Thanks
Aslam Bari

Rounded corner box using easy JS

Sunday, March 6, 2011 by Aslam - The Alexendra
Hi All,
I think most of us many times faced the situation when they need to make some rounded corner boxes (div) on their web page. Generally most of us go for two ways:
1) Use of -moz-border-radius , but this works in Mozilla browsers only not in IE
2) If one want to do that for support all browsers then he needs to achieve that using combination of 3-4 divs , setting some border images which already rounded. It means extra divs in your existing logic. So far i also follow that.

But recently i found a useful library which make any div available in your webpage to rounded corner with single line of code. So you just need to focus on your web design and just need to call one method to make rounded corner for whichever div you need. The library is DD_roundies. This gives same output in all browsers so you no need to take any extra actions. Here is the sample code and working demo i used.

The single line of code which you need to call is:
DD_roundies.addRule('#yet_another', '10px', true);

Here "#yet_another" is the id for the div which you need to make round, '10px' is the radius for border for roundness, and 'true' is a flag for support all browser.

Complete Code:
<style>
#yet_another
{
border
:1px solid #000;
background-color
:#ccc;
padding
:5px;
height
:100px;
width
:400px;
text-align
:center;
}
#up_another
{
border
:1px solid #000;
background-color
:#ccc;
padding
:5px;
height
:100px;
width
:400px;;
text-align
:center;
}

#capsule_round
{
width
:100px; height:100px; background:#FA0;
padding
:10px;
text-align
:center;
padding-top
:100px;
}
#totally_round
{
width
:100px; height:100px; background:#FA0;
padding
:10px;
text-align
:center;

}
</style>
<script src="DD_roundies_0.0.2a-min.js"></script>
<script>
/* EXAMPLES */
/* varying radii, "all" browsers */
DD_roundies.addRule('#yet_another', '10px', true);
DD_roundies.addRule('#up_another', '10px 10px 0px 0px', true);
DD_roundies.addRule('#capsule_round', '10000px', true);
DD_roundies.addRule('#totally_round', '10000px', true);
</script>

<body>

<div id="yet_another">
Rounding box with 10px radius
</div>
<br/>
<br/>
<div id="up_another">
Rounding box with upper round 10px radius
</div>
<br/>
<br/>
<div id="capsule_round">
Capsule Round
</div>
<br/>
<br/>
<div id="totally_round">
Total Round
</div>

Here is the link for working demo. You can check it in Firefox as well as in IE.
https://labsprojects-developer-edition.ap1.force.com/RoundCorners


Hope it will be useful for somebody who searching for that support :)

Thanks
Aslam Bari