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

4 comments:

Richard Vanhook said...

See apex-lang StringUtils and HttpUtils

apexsutherland said...

Aslam, have you considered contributing these functions to the apex-lang library?

http://code.google.com/p/apex-lang/

Aslam - The Alexendra said...

@Richard and @sutherland: Yes, apexlang indeed very useful package of many utilities methods. My aim is to make simpler class with re-usable methods which people come across. And, if i will be able to collect some useful methods which are not in apexlang, i will love to contribute there.

Aslam - The Alexendra said...

One new method "makeCondition" is contributed by Akhilesh Soni. That method is used to make condition in dynamic query.
Thanks @Akhilesh

Post a Comment