Salesforce Utility Methods

Here are some of the utility methods, which we will be using very frequently in our salesforce world.

//This utility takes the input as List<sobjects> and the desired field name, which inturn returns the unique values of the specified field names
public static Set<String> pickDesiredSet(List<SObject> sobjects, String fName){
	Set<String> strSet = new Set<String>();
		if(sobjects != null && sobjects.size() > 0 && fName != null && fName.trim() != null) 
			for(SObject sobj : sobjects)
	return strSet;
//This utility takes the input as List<sobjects>, key and pair, which inturn returns the key and pair as a map
public static Map<String, String> pickDesiredMap(List<SObject> sobjects, String key, String pair){
	Map<String, String> strMap = new Map<String, String>();
		if(sobjects != null && sobjects.size() > 0 && key != null && key.trim() != null) 
			for(SObject sobj : sobjects)
				if(!strMap.containsKey(key)) //To keep only the first value
					strMap.put(String.valueOf(sobj.get(key)), String.valueOf(sobj.get(pair)));
	return strMap;

Any addons to these methods are highly appreciated.

This entry was posted in Apex, salesforce, Salesforce Tips & Tricks, Visualforce. Bookmark the permalink.

One Response to Salesforce Utility Methods

  1. Annmarie says:

    Ahaa, its good dialogue about this article here at this web site, I have read
    all that, so at this time me also commenting here.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s