'Android To Case' : Android App to log Salesforce Case

Saturday, May 21, 2011 by Aslam - The Alexendra
Hi All,
Most of you may know "Web To Case" functionality of Salesforce. I have used the same concept and reuse that idea to make simple Android App, which works exactly same as "Web to case", so i called this app as "Android To Case".

Here is some screen shot how it will look like:

1) Initial Screen:



2) After Submit below screen will come:




The code and app is simple. Here is the main code as below:

package com.androidsfdc.androidtocase;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;

import javax.net.ssl.HttpsURLConnection;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AndroidToCase extends Activity {
/** Called when the activity is first created. */
private static final String ORGID = "00D###0###0###G";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn
= (Button) findViewById(R.id.submit);

btn.setOnClickListener(
new View.OnClickListener() {

public void onClick(View v) {
try {
EditText name
= (EditText) findViewById(R.id.contactName);
EditText email
= (EditText) findViewById(R.id.email);
EditText phone
= (EditText) findViewById(R.id.phone);
EditText subject
= (EditText) findViewById(R.id.subject);
EditText description
= (EditText) findViewById(R.id.description);
StringBuffer params
= new StringBuffer();
params.append(
"orgid=" + URLEncoder.encode(ORGID, "UTF-8"));
params.append(
"&name="
+ URLEncoder.encode(name.getText().toString(),
"UTF-8"));
params.append(
"&email="
+ URLEncoder.encode(email.getText().toString(),
"UTF-8"));
params.append(
"&phone="
+ URLEncoder.encode(phone.getText().toString(),
"UTF-8"));
params.append(
"&subject="
+ URLEncoder.encode(subject.getText().toString(),
"UTF-8"));
params.append(
"&description="
+ URLEncoder.encode(description.getText()
.toString(),
"UTF-8"));
String output
= excutePost(
"https://www.salesforce.com/servlet/servlet.WebToCase?encoding=UTF-8",
params.toString());
name.setText(
"");
email.setText(
"");
phone.setText(
"");
subject.setText(
"");
description.setText(
"");
Toast.makeText(getBaseContext(),
"Case is successfully Created!!!",
Toast.LENGTH_LONG).show();

}
catch (Exception ex) {
ex.printStackTrace();
}
}
});
}

public static String excutePost(String targetURL, String urlParameters) {
URL url;
HttpsURLConnection connection
= null;
try {
// Create connection
url = new URL(targetURL);
connection
= (HttpsURLConnection) url.openConnection();
connection.setRequestMethod(
"POST");
connection.setRequestProperty(
"Content-Type",
"application/x-www-form-urlencoded");

connection.setRequestProperty(
"Content-Length",
"" + Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty(
"Content-Language", "en-US");

connection.setUseCaches(
false);
connection.setDoInput(
true);
connection.setDoOutput(
true);

// Send request
DataOutputStream wr = new DataOutputStream(
connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();

// Get Response
InputStream is = connection.getInputStream();
BufferedReader rd
= new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response
= new StringBuffer();
while ((line = rd.readLine()) != null) {
response.append(line);
response.append(
'\r');
}
rd.close();
return response.toString();

}
catch (Exception e) {

e.printStackTrace();
return null;

}
finally {

if (connection != null) {
connection.disconnect();
}
}
}
}


You only need to change "ORGID" with your organization id in the above code. And it will work for your developer/production org.

This application will be useful for such companies who want their customers to log cases directly from their Android mobiles natively. They can simply setup this application and ask their customers to install the app on their mobiles. And this is ready to use.

You can download the complete code from here:
http://www.aslambari.com/downloads/AndroidToCase.zip

Hope you like this app :) . Give me feedback what do you think.

Thanks
Aslam Bari

Salesforce Drag Drop MultiSelect List Using JQuery

Friday, May 13, 2011 by Aslam - The Alexendra
Hi All,
Recently i came across with one requirement where end user needs a multiselect picklist where he can drag drop items between two list in Salesforce. I searched for some good drag drop scripts over net and finally found best one which fits in my need. It is from thechriswalker.net and you can see that in action here.

So I used that jquery stuff and wrapped that in a re-usable VF component to make it more general. It is very simple to use and easy to embed in you VF page.
In your VF page you simply need to call the VF component as below syntax:

<c:sfdragdroplist list1="India;United States;France;Germany;Japan" outputfieldid="list_2_serialised">

The above syntax will make two list on screen drag and drop enabled. Source list will have counties given in "list1". This attribute contains the list of items separated by semicolon ";". You can directly hard code these items to component or you can also fetch from any object fields and make that semicolon separated (note: multiselect picklist already contains values as semicolon separated) and pass to component. For storing what user is selecting for your DB or later processing purpose you need to make one extra textfield (or hidden field) and provide that id in above component like "list_2_serialised"

<input id="list_2_serialised" name="list_2_serialised" value="{!list2FinalItems}" type="hidden">



You can download the complete code from this package url
https://login.salesforce.com/?startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t90000000PpxL

You can see the working demo here
http://labsprojects-developer-edition.ap1.force.com/apex/DemoSFDragDropList

The above implementation is for simple list drag drop, one can extend it to make it more advance level to enable drag drop between two different tables or screens.

Hope this will be helpful for users!!!

Thanks
Aslam Bari

Making Related List without using Apex Class

Thursday, May 5, 2011 by Aslam - The Alexendra
Hi All,
Here i want to give some sample code to show you how to make RelatedList on your VF page without using any Apex Code. There are two solutions for this problem.

1) Using <apex:relatedlist>
Suppose you have standard Case object and have one custom child object named "Child__c" to case. Then you can show your relatedlist on vf page using below code.

<apex:page standardController="Case">
<apex:relatedList list="Childs__r"/>
</apex:page>

The list will be displayed on your page but it always gives "Action" column also with "Edit | Del" links. If you want to get rid off that then you need to do a little jquery trick to remove that. See the below code.

<apex:page standardController="Case">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>

<script>
$(document).ready(function(){
$('#Childs a').attr('target','_blank');
});
</script>

<style>
.pbButton{
display:none;
}
.actionColumn{
display:none;
}
</style>

<Div id="Childs">
<apex:relatedList list="Childs__r"/>
</Div>

</apex:page>

The main issue i found using above approach of making list is that it depends on fields selected on page layout for that relatedlist. If you have added 2 fields on your layout, your vf will also show two fields. If you remove that related list from layout, then your vf will show only default fields ( name) only. So, in some sitations this solution is not perfect. For that reason, here is another solution.

3) Using relations objects iteration and Standard Tags.
Here is the other way to achieve your related list on vf page:

<apex:page standardController="Case">
<apex:sectionHeader title="http://www.aslambari.com" subtitle="Related List Example"/>
<apex:pageBlock>
<apex:pageBlockTable value="{!Case.Childs__r}" var="child">
<apex:column headervalue="Name"><apex:outputLink value="/{!child.id}">{!child.name}</apex:outputLink></apex:column>
<apex:column value="{!child.detail__c}"/>
<apex:column value="{!child.is_active__c}"/>
<apex:column value="{!child.createddate}"/>
<apex:column value="{!child.createdbyId}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Here is a working demo for above code sample:
http://labsprojects-developer-edition.ap1.force.com/apex/RelatedListSample?id=50090000000sW5q


The above way, you can customize your list as you want.

Hope It helps developers to find quick solution for related list.

Thanks
Aslam Bari

Salesforce Native DatePicker Year Extending Component

Saturday, April 23, 2011 by Aslam - The Alexendra
Hi All,
I developed one simple and useful component to extend Native Salesforce DatePicker. You all must aware of that we can't change Year list in datepicker and have to depend of salesforce native year list which is about -1 to +5 of current year. This is not useful on many situation like if i need to make one Date Of Birth field or any other date field where i need years range some high.



So i came up with simple component solution for this of your VF page. You simply need to include this in your VF page and use as following.

Sample Usage:
1) By using "lowerLimit" and "higherLimit"
<c:datepickerextend lowerlimit="10" higherlimit="15"/>
It will pick first year available in picker year list , for example 2010, and then add 10 earlier years to top of the picklist.
Same for higherLimit, it will pick last year available in picker year list, for example 2016, and then add 15 later years to bottom of the picklist.

2) By using "startYear" and "endYear
<c:datepickerextend startYear="1982" endYear="2020"/>
It will simply fill year list from 1982 to 2020.

Downloads
----------------------------------------------------
1) Component Code: Download from here
http://www.aslambari.com/datepick_extend/DatePickerExtend.txt

2) jQuery Lib: Download from here and save in static resource as datepicker_extend (You can you any jquery lib instead)
http://www.aslambari.com/datepick_extend/jquery-1.5.2.min.js

3) Demo Usage Code: Download from here
http://www.aslambari.com/datepick_extend/DemoUsageCode.txt


Working online demo:
You can view one simple demo, used following code:

<c:datepickerextend lowerlimit="10" higherlimit="5"/>

http://labsprojects-developer-edition.ap1.force.com/DatePickerExtendDemo


Provide your feedback as always. Enjoy !!!

Thanks
Aslam Bari

SF Ballot : Native Poll System For Salesforce

Saturday, April 16, 2011 by Aslam - The Alexendra
Hi All,
Today i came up with one new tool i created "SF Ballot". This is a small application tool used for polling/voting for Salesforce internal users, customer portal users and others with native support. It is easy to setup and integrated with sidebar for users. Users can submit and see result easily for their daily polls. Admin can easily creates new poll daily for users.



You can download the package from this url:

https://login.salesforce.com/?startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t90000000DNdg

Here is the detailed information about this tool. You can find screencast also there and updated info about the tool.

http://www.aslambari.com/sf_ballot.html

Try this out and give me feedback about your experience with this.

Thanks
Aslam Bari

Restrict Duplicate Records In Salesforce [Duplicate Detector]

Friday, April 8, 2011 by Aslam - The Alexendra
Hi All,
There are many needs in most of the times for business to avoid duplicate records in their systems. For example Companies don't want duplicate Accounts, Contacts or Leads to be inserted into the systems. So i came up here with one solution application called "Duplicate Detector".



This is a managed package, easy to install into Salesforce and ready to use. The package is in Beta and it gives you power to Configure following things:-

1) Custom Error message when duplicate found
2) Stop Duplicate
3) Report Duplicate, it stops the duplicate and also prompts the duplicate found record link records.
4) You can select fields on which you want to make "Duplicate Detector" to find duplicate and stops the insertion/updation.

I am planning to extend this package to put some more advance features in near future.

Go Here to download the package:
http://www.aslambari.com/duplicate_detector.html

Click here to see a small screen cast about the functionality:-
http://screencast.com/t/N5RmVk2oN90

Here are some screen shot for it:

1) Main Front Launching Screen:


2) Configuration/Criteria Screen:


3) When duplicate record inserted (Account) it reports like below:



It may have some chances to enhance the tool, Try it and let me know your valuable feedbacks and any bug if you find.


Thanks
Aslam Bari

sfGMap [Salesforce + Google Map + jQuery]

Saturday, April 2, 2011 by Aslam - The Alexendra
Hi All,
I came across many times for implementing Goolge Map on VF page for many clients in different needs. Every time its a time consuming process like download scripts, write code to fetch addresses, write code to set markers and additional javascript for that. So, I decided to make one Simple Component (Package) which is easy to use and embed in your VF page. Here is a live demo for the map on VF page which shows all accounts markers and info in popup.

https://labsprojects-developer-edition.ap1.force.com/mapdemo

Here is the package link wihch is used to install sfGMap package easily.

https://login.salesforce.com/?startURL=%2Fpackaging%2FinstallPackage.apexp%3Fp0%3D04t90000000Po3w





Here is some guidelines to use <c:sfgmap> the component.

You simply need to use component in your vf page with appropriate attributes.
--> width: Width of the map
--> height: Height of the map
--> addressmodel : all addresses need to show on map
--> uselatlng : check to see if use lat lng or address
--> zoom : zoom level for google map
--> default : default address where map will be center on load

Here is sample use:
<c:sfgmap width="600" height="400" addressmodel="{!addressmodel}" zoom="4" uselatlng="false">

Here AddressModel is a class which contains the list of Addresses. After installation of the package you can simply go to "mapdemo" VF page and "mapdemocontroller" to see the sample code how to use this.

This package is simple to use and time saving for many. Give it a try :)

Thanks
Aslam Bari
Posted in | 17 Comments »