FTP Images in Salesforce Lookup Dialog

Friday, July 6, 2012 by Aslam - The Alexendra
Hi All,
Recently one of my clients needed one product selection lookup dialog with product images in it. The requirements were as below:

1) Images must not be stored in Salesforce, they want to store images in their own FTP server
2) When user click on create new record, user can select Product from lookup dialog, the same time, in product dialog, user can see the images respective to that particular image. So that it will be easy for user to judge the selection.

So, here is the solution i came up with.

1) Store your images in remote FTP server in a folder, for example, i saved my product images at following location:
http://labs.aslambari.com/products/

2) Give images some unique name similar to ProductCode field of your products like CM_111.jpg, CM_222.jpg, CM_333.jpg etc







3) Now create one "Product Image" formula (text) field on product object like below:

IMAGE("http://labs.aslambari.com/products/" & ProductCode & ".jpg", ProductCode)

4) Add this field into your product lookup dialog layout (Search layouts)

5) Now, whenever you will click on any Product lookup field in your org, you will simply see the product image of that particular product code.

Please check the live demo here.
http://labsprojects-developer-edition.ap1.force.com/Product_Selection

Click on Product lookup field, Select "Product Family" filter , equals to , "Camera" value. You will see all products with images. See below screen shot.



Hope this will help some developers to achieve this kind of requirement sometime.

Thanks
Aslam Bari

Google Transliteration component for Salesforce

Wednesday, March 21, 2012 by Aslam - The Alexendra
Hi All,
Recently I had a requirement where client needs easy way to type details in both English/Hindi language in Standard Salesforce screens. For example, there are call center agent users. They use Salesforce Case screen to type whatever detail they get from end customer. Client needs that agent can type details or resolution in both English and Hindi language. So, i come up with one solution here. I used "Google Transliteration" JS API to achieve it and attached this to standard description field for Case Edit screen.



I found this is useful for many others people or developers. So I come up with one common component solution for this. Here is a screen cast you can see this in Action.

http://screencast.com/t/J5OrRMAR

How to install:

1) Download the "Google Transliteration Support" Home page component code from here http://labs.aslambari.com/google_transliteration_support.txt
2) Make one "Narrow Side Bar" html component in your SFDC org and put the code there.
3) Enable this component to Active Home page layout (Make sure it will be visible on all pages in sidebar)
4) Some settings you need to take care (or need to change)

Language: You can see the line of code "google.elements.transliteration.LanguageCode.HINDI". This is the target language. You can change it if you want the native language according to your need.

Field Id: You can see the line of code "opp14". This is the field id of "description" field of Opportunity Edit Screen. You can find the any field id (textarea/text) of the object which you want to make transliteration support. And you need to give that id here.

Extra feature: There is one extra hidden feature here. While you are typing you can toggle between language "Ctrl + g" shortcut keys. But be sure this is not synch with Button on left side (I did not get much time for that, so left that). But this is very convenient for a agent to switch between two language using shortcut keys.

Let me know your thoughts once you able to use it.

Thanks
Aslam Bari

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