This sample code covers a general query utility which can be used to query any object.
This is the general class which runs the query. Comments are embedded inline for understanding the functionality.
Copy and paste this class
To Call this class:
You can call this class from any other class. Below is a sample code which you can embed into any class or you can execute this from the system log.
This is the general class which runs the query. Comments are embedded inline for understanding the functionality.
Copy and paste this class
Public class QueryUtility
{
// Function to run the query
Public List<sObject> runQuery(String objname,String[] fieldnames,String condition)
{
List<sObject> queryresult;
String fieldslist = '';
// Generate the fieldslist from the string array
if (fieldnames != NULL)
{
if(fieldnames.size() > 0)
{
for (Integer i=0; i < fieldnames.size(); i++)
{
if( i <= (fieldnames.size() - 2))
fieldslist = fieldslist+fieldnames[i]+',';
else
fieldslist = fieldslist+fieldnames[i];
}
}
}
// Construct the query string
String soqlquery = 'Select '+fieldslist+' from '+objname+' '+condition;
// Run the query
queryresult = Database.query(soqlquery);
return queryresult;
}
}
To Call this class:
You can call this class from any other class. Below is a sample code which you can embed into any class or you can execute this from the system log.
// Construct the list of fields
String[] flist = new List<String>{'Name','Id'};
// Initialte a new variable of the general utility class
QueryUtility test = new QueryUtility();
// Call the runquery method to execute the query. Note that the condition has to be passed as an empty string if you do not have any condition
Account[] qresult = test.runQuery('Account',flist,'');
system.debug('The query result is'+qresult);
This article covers a sample code to insert a poll component into your Salesforce.com instance as a home page component, or elsewhere Visualforce is supported.
This component allows administrators to open up a simple poll for users to get feedback from users. Once installed, the poll component can be configured easily.
Below is a demo of the application. Note that the below is an iframe of a Force.com Site page, Yes, it's a visualforce page embedded within this blog.
This component allows administrators to open up a simple poll for users to get feedback from users. Once installed, the poll component can be configured easily.
You can watch the demo at forcetreedemos too..
To install the app in your Salesforce instance, install the below package.
Production, Developer Org - https://login.salesforce.com/packaging/installPackage.apexp?p0=04t900000000sla
Sandbox - https://test.salesforce.com/packaging/installPackage.apexp?p0=04t900000000sla
Suggestions and Comments welcome!