TechShare Cloud Forum Launched

Tuesday, March 13, 2012 by Aslam - The Alexendra
Hi All,
I am pleased to inform that I have created a very nice and simple forum where you can post your questions regarding Salesforce and other technology.



Please post your questions there to get answers quickly.

forum.aslambari.com


Thanks
Aslam Bari

Light Weight SF force.com chat plugin for sites

Tuesday, February 14, 2012 by Aslam - The Alexendra
Hi All,
Here, I am going to introduce the "Light Weight SF force.com chat plugin for sites".

This is easy to install and setup in your force.com site and easy to use. The positive thing is that it saves data in your native salesforce object for your review. This is just a demo app, if one want, he can extend this app to make more robust.



1) You can simply install it from here:
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000Q0Re

2) After deploy, you can simply access the first page by /apex/JoinChat It will ask you to click on join now link, if you already logged in before in chat room, you will be redirect to chathome page

3) If you not logged in, you will be redirected to /apex/chatlogin page, here you can give a name for yourself to use in chat room

4) To go chat room, you can call this page /apex/chathome Here you can see existing public people who are logged into same chat room To best use , you need to setup all 3 pages on public force.com site.

Here is a demo hosted on my site:
i)JoinChat
http://labsprojects-developer-edition.ap1.force.com/JoinChat

ii) ChatLogin
http://labsprojects-developer-edition.ap1.force.com/chatlogin

iii) ChatHome
http://labsprojects-developer-edition.ap1.force.com/chathome

Note: For automatic updates, due to too much request i have set 30 seconds auto update for chat

There are chances of more enhancements, but its just a start :)

Thanks
Aslam Bari

Overlay Effect for VF form submit

Tuesday, December 13, 2011 by Aslam - The Alexendra
Hi All,
Overlay box is many times used whenever there is a need to show user a processing box and we dont need user do any activity on page while processing is going on. So i am sharing a simple vf component here which has css and js which gives overlay effect in your normal VF pages like below:

<c:overlay style="processing">

Here "style" attribute can have two values for now [classic, processing]. Classic style shows gray overlay, and Processing style shows animated image.



Here is the steps how you can use this component to achieve overlay effect:

1) put the component in head section of your page
<c:overlay style="classic">

2) put this div at the very bottom of your page, just before close of </body> tag or </apex:page> tag
<div id="overlay"></div>

3) put this <apex:actionstatus in your form
<apex:actionstatus id="overlayStatus" onstart="showOverlay();" onstop="hideOverlay();"></apex:actionstatus>

4) finally refer this action status in your action function or command button as below
<apex:commandbutton action="{!saveRecord}" status="overlayStatus" value="Save" rerender="pBlock">

Here is the complete code :


<apex:page controller="OverlayDemoController">
<head>
<c:Overlay style="processing" />
</head>
<apex:form>
<apex:actionStatus id="overlayStatus" onStart="showOverlay();" onstop="hideOverlay();"></apex:actionstatus>
<apex:sectionHeader title="Contact Save" subtitle="Overlay Demo" />
<apex:pageBlock id="pBlock">
<apex:pageMessages></apex:pageMessages>
<apex:pageBlockButtons>
<apex:commandButton action="{!saveRecord}" status="overlayStatus" value="Save" reRender="pBlock"/>
</apex:pageBlockButtons>
<apex:pageBlockSection>
<apex:inputField value="{!cnt.First_Name__c}" />
<apex:inputField value="{!cnt.Last_Name__c}" />
<apex:inputField value="{!cnt.Phone__c}" />
<apex:inputField value="{!cnt.Email__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<div id="overlay"></div>
</apex:page>


http://www.blogger.com/img/blank.gif
5) Here are the links for working online demo for the overlay :

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

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

6) You can download the complete code from here:
http://labs.aslambari.com/overlay.zip

Hope it will be useful for developers.

Thanks
Aslam Bari

Thursday, October 6, 2011 by Aslam - The Alexendra
Hi All,
Today I came to know about 'Stripe' APIs. Stripe is a simple, developer-friendly way to accept payments online. According to Stripe :-
"We believe that enabling transactions on the web is a problem rooted in code, not finance, and we want to help put more websites in business.
Complexity and opacity have traditionally been hallmarks of online payment processing. We want to fix that."


So, as usual, here I came up with the solution of Apex Wrapper for Stripe APIs. I developed this API library with my colleague Sanjay. The library gives basic api methods to call and use as follows:

//1) CreateCharge
Stripe request = new Stripe('y001LvDyqiGbNZclaaaxxxxttttOJk8w');
StripeResponseModel response
= request.createCharge('4242424242424242', '2013', '10', '123', '2000', 'usd', 'testing');
if(!response.isError){
system.debug(
'Transaction ID :: ' + response.id);
system.debug(
'Transaction Fee :: ' + response.fee);
}
else{
system.debug(
'Error Message :: ' + response.errorResponse.message);
}

//Create charge using customer
Stripe request = new Stripe('y001LvDyqiGbNZclaaaxxxxttttOJk8w');
StripeResponseModel response
= request.createCharge('cus_EPTWuvf7EXDb4g', '2000', 'usd', 'testing');
if(!response.isError){
system.debug(
'Transaction ID :: ' + response.id);
system.debug(
'Transaction Fee :: ' + response.fee);
}
else{
system.debug(
'Error Message :: ' + response.errorResponse.message);
}

//2) CreateCustomer
Stripe request = new Stripe('y001LvDyqiGbNZclaaaxxxxttttOJk8w');
StripeResponseModel response
= request.createCustomer('4242424242424242', '10','2013', '123', 'Aslam', '', '', '', '', 'IN', 'aslam.bari@gmail.com', 'test');
if(!response.isError){
system.debug(
'Customer ID :: ' + response.id);
}
else{
system.debug(
'Error Message :: ' + response.errorResponse.message);
}

//3) RetrieveCustomer
Stripe request = new Stripe('y001LvDyqiGbNZclaaaxxxxttttOJk8w');
StripeResponseModel response
= request.retrieveCustomer('cus_EPTWuvf7EXDb4g');
if(!response.isError){
system.debug(
'Customer Country :: ' + response.card.country);
system.debug(
'Customer Last4 CC :: ' + response.card.last4);
}
else{
system.debug(
'Error Message :: ' + response.errorResponse.message);
}

//4) CreateInvoice
Stripe request = new Stripe('y001LvDyqiGbNZclaaaxxxxttttOJk8w');
StripeResponseModel response
= request.createInvoice('cus_EPTWuvf7EXDb4g', '2000', 'usd', 'test');
if(!response.isError){
system.debug(
'Invoice Id :: ' + response.id);
}
else{
system.debug(
'Error Message :: ' + response.errorResponse.message);
}

//5) RetrieveInvoice
Stripe request = new Stripe('y001LvDyqiGbNZclaaaxxxxttttOJk8w');
StripeResponseModel response
= request.retreiveInvoice('ii_W19Xp6cxrqVABH');
if(!response.isError){
system.debug(
'Invoice Date :: ' + response.created);
}
else{
system.debug(
'Error Message :: ' + response.errorResponse.message);
}

//6) CreatePlan
Stripe request = new Stripe('y001LvDyqiGbNZclaaaxxxxttttOJk8w');
StripeResponseModel response
= request.createPlan('AMX_101', '2000', 'usd', 'month' , 'AMX Testing');
if(!response.isError){
system.debug(
'Plan Id :: ' + response.id);
}
else{
system.debug(
'Error Message :: ' + response.errorResponse.message);
}

//7) RetreivePlan
Stripe request = new Stripe('y001LvDyqiGbNZclaaaxxxxttttOJk8w');
StripeResponseModel response
= request.retrievePlan('AMX_101');
if(!response.isError){
system.debug(
'Plan Label :: ' + response.name);
}
else{
system.debug(
'Error Message :: ' + response.errorResponse.message);
}


You can download the code from github here:
https://github.com/aslambari/Stripe-Apex-Toolkit

Or from my website here:
http://www.aslambari.com/stripe_apex_toolkit.html

There are many more methods which are under development like CreateSubscription, ListAllCustomers etc, we are working on them. And will back soon with full set of methods. Till, try this library and let us know if that works fine for you and revert back us for enhancements.

Thanks
Aslam Bari

Showing Salesforce Images/Attachments on PHP/JSP page

Saturday, October 1, 2011 by Aslam - The Alexendra
Hi All,
Today I am going to demo you how to fetch images (attachments) from salesforce instance in to your PHP script and how you can show those imags on page as a portal or catalog way.

1) index.php script
The below code shows how you can query to attachment object in salesforce to fetch some attachment records. For example i have query the pics (attachment) for my two SFDC contact records in sample code. The concept is simple. You need to query the Id of attachment in your main page, then you will have one another php script which will fetch the SFDC attachment (image) binary data and show the image on screen as embedded. We can wrap/embed that image in <img /> tag directly.

<?php
error_reporting(E_ALL);
require_once ('soapclient/SforcePartnerClient.php');
require_once('connection.php');

$ids = array();
$ids[] = '00390000006IUVK';
$ids[] = '00390000001lwbd';
getPhotos(
$ids);


function getPhotos($contactids){
$mySforceConnection = getConnection();
$query = "SELECT Id, Name from Attachment Where ParentId in (";
foreach($contactids as $id){
$query .= "'". $id . "',";
}
$query = substr($query , 0, strlen($query) - 1);
$query .= ")";
$queryResult = $mySforceConnection->query($query);

$records = $queryResult->records;
if(count($records) > 0){
echo "<table cellspacing='5' cellpadding='5'><tr>";
foreach($records as $rec){
echo "<td style='text-align:center;font-size:12px;'>".
"<img src='image.php?id=".$rec->Id."' ".
"style='width:200px;height:200px;border:1px solid #ccc;padding:10px'/> <br/>"
. $rec->fields->Name.
"</td>";
}
echo "</table>";
}
return NULL;
}
?>


2) image.php script
This code simply accepts one Id of the attachment record and fetch the binary body of attachment, then it shows that image on the screen as image content. To view this image in other page you simply need to wrap/embed its call into <img /> html tag. Like below:

<img src="image.php?id=00P9000000185ioEAA" />


<?php
error_reporting(E_ALL);
header('content-type: image/jpeg');
require_once ('soapclient/SforcePartnerClient.php');
require_once('connection.php');

getPhotos(
$_GET['id']);


function getPhotos($id){
$mySforceConnection = getConnection();
$query = "SELECT Id, Name, Body from Attachment Where Id ='" .$id ."'";
$queryResult = $mySforceConnection->query($query);

$records = $queryResult->records;

print_r(base64_decode($records[0]->fields->Body));
return NULL;
}

?>



Here is the demo of the scripts where i am fetching two contact's images from Salesforce and showing on simple PHP page.

http://labs.aslambari.com/sfdc_photos_demo/


Thanks
Aslam Bari

SF Uploadify: File Uploading Utility for Salesforce

Tuesday, September 13, 2011 by Aslam - The Alexendra
Hi All,
I have created a very cool file uploading utility which can be integrated with any system, but mainly I focused on Salesforce. This utility is built using Uploadify Tool and PHP integration. You can find more info about Uploadify here. It supports multiple file uploading with progress bar and uploads the file to your external server (php server where your site or this utility is hosted.) Then it makes the Attachment record in salesforce and links to actual file on server. So you can directly (natively) access your files.


How it works:

  1. User opens any record in salesforce , lets say "Account" record.
  2. There will be a custom button (given in below code), user clicks on button
  3. One file uploading screen opens, click on 'Select Files" button and select multiple files at same time (using control button)
  4. As soon as, user select and close dialog, it starts uploading files with progress bar
  5. The files will be stored on the Server where this utility exists, for now it saves to my server.
  6. It will show finally a screen with close button.
  7. Click on close button , it will refresh the parent window (if not, manually refresh the parent record)
  8. Open the attachments section, you will find the new files (attachments created, which actually a link for actual files on the server)
  9. Click on any file and click on "View" link.
  10. And you will see it opens your uploaded actual file :)

More Details and Updates on my site:
http://www.aslambari.com/sf_uploadify.html

Installation:
1) Button code:
Make one custom button (detail screen button), on any object, for example , account object, see below code.
a. Behavior must be "Open in new window"
b. Content Source will be "URL"
The url for the button will be as below

http://labs.aslambari.com/sf_file_uploader/sf_setup_uploader.php?sessionid={!$Api.Session_ID}&serverurl={!$Api.Partner_Server_URL_220}&recordid={!Account.Id}

2) Utility Code:
The utility is on my server for now, it is in BETA, once all is tested and working , i will make it public :)

Note: For commercial use this tool, you first need to go to Uploadify site and check its license type if any. Because my tool uses the Uploadify internally.

See the screen cast how it works:
http://screencast.com/t/ibDqgMBbfQ

Hope you will like it. :)

Thanks
Aslam Bari

Heat Map using Google Map in Salesforce

Saturday, September 10, 2011 by Aslam - The Alexendra
Hi All,
Recently i came across for one requirement with my client where he wants to see density of his shops across US. For example he has a lot of branches of his coffee shops across US like in CA, TX, MB etc. He want to see a good way on map to see density of his branches. I found the way how to show this, this type of maps are called HeatMaps.

Heat Maps are used to show density of your prouduct, services and any useful information on Geaographical area, based on your addresses.




The another example may be like, i want to know Starbucks shops across the US and want to know which area has density (number of shops) more.
So, i created one example in Salesforce VF page to show, how we can make it.

1. Copy paste below code in your VF page

<apex:page showHeader="false" sidebar="false">
<script src="http://www.heatmapapi.com/javascript/HeatmapAPI.aspx?k=86123b76-2190-4a4b-b182-86e7199b0406" type="text/javascript"></script>

<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA09SA9e7gW5A4Mpy3VCJQjxQfiV3Wc4AiuMkI_RwI0dk2dVyy7hQWusr2PE1VCubWNkTco2njprfSxg" type="text/javascript"></script>

<script src="http://www.heatmapapi.com/javascript/HeatmapAPIGoogle.js" type="text/javascript"></script>
<script type="text/javascript"
src
="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var m = null;
var batch = "";
var myHM = null;
var request = GXmlHttp.create();
var TOTAL_COUNT = 0;
var INDEX = 0;
function loadGoogle()
{
if (GBrowserIsCompatible())
{
m
= new GMap2(document.getElementById("map"));
m.setCenter(
new GLatLng(38.5, -95.8), 3);
m.setUIToDefault();
initHeatmap();
}
else
alert(
'Your Internet browser is not compatible with this website.');
}



function initHeatmap()
{
// Heatmap Scripts
try
{
myHM
= new GEOHeatmap();
myHM.Init(
400, 400); // Must be same as map size, or same ratio
addMarkersFromXml();





}
catch(e)
{
alert(e);
}
}

function addMarkersFromXml(){

request.open(
'GET', '/apex/data', true);
request.onreadystatechange
= function() {
//alert(request.readyState);
if(request.readyState == 4) {
var xmlDoc = request.responseXML;
var markers = xmlDoc.documentElement.getElementsByTagName("store");
TOTAL_COUNT
= markers.length;
INDEX
= 0;
for(var i=0; i < markers.length; i++){
var state = markers[i].getAttribute("state");
var density = "1";//markers[i].getAttribute("density");
geocoder = new GClientGeocoder();
var address = state;
geocoder.getLatLng(address,
function(point) {
if (!point) {

}
else {
fullVal
= point.lat().toFixed(5) + "," + point.lng().toFixed(5) + "," + density + ",";
batch
+= fullVal;
INDEX
++;
if(INDEX >= TOTAL_COUNT){
startMap();
}
}
});
}

}
}


function startMap(){
document.getElementById(
"HMMapdata").value=batch;
myHM.SetData(batch);
myHM.SetBoost(.
5); // Optional, see documentation
myHM.SetDecay(0); // Optional, see documentation
//var proxyURL = "http://localhost/proxy.php";
//myHM.SetProxyURL(proxyURL);
var preUrl = myHM.GetURL();

// Now render in our Google Map
var heatmapOverlay = new HMGoogleOverlay(preUrl);
m.addOverlay(heatmapOverlay);
}
request.send(
null);

}





</script>

<apex:sectionHeader subtitle="Heat Map using Google Map" title="Aslam Bari (http://www.aslambari.com)"/>
<body onload="loadGoogle();">
<input type="hidden" id="HMMapdata" />
<input type="hidden" id="HMImageURL" name="HMImageURL"/>
<div id="map" style="width:400px;height:400px;"></div>
</body>
</apex:page>



2. Create another page called "data" and copy paste below code in that. Note: this page contains the addresses of your shops, offices etc which we want to see as density. So, change accordingly

<apex:page sidebar="false" showHeader="false" contentType="text/xml">
<stores>
<store state="IN,US"></store>
<store state="KY,US"></store>
<store state="WA,US"></store>
<store state="MB,US"></store>
</stores>
</apex:page>


Note: you need to go http://www.heatmapapi.com to get new Free API key and also for google free api key to get your code work.

Here is the working example of this. Click to see.
http://labsprojects-developer-edition.ap1.force.com/HeatMapExample

Hope you will need this sometime in your project.

Thanks
Aslam Bari