Getting Reports From Salesforce to Custom Portal using php

Hey All,
I have been searching ways to get data of the reports from salesforce to a Custom Web portal developed using php. Found a way of doing this using CURL extention of php. So Below are the steps ..
1.) Enable PHP_CURL in your php instalations.
2.) Create code for connecting to your instance as per my previous blog.
$result = $client->login($username, $password);$client->sessionId = $result[‘sessionId’]; 
3.) Get the report ID from your instance using a webservice method in APEx
WebService string FindReport(string ReportName)
{
List reports = [Select Id, Name from Report Where Name = :ReportName];
if (reports == null || reports.size() == 0) return null;

PageReference pageRef = new PageReference(‘/’ + reports[0].Id);
Blob ReportBlob = pageRef.getContent();
return ReportBlob.toString();
}Thanks to David

4.)Define the URL to hit

$url = “https://na1.salesforce.com“;
$reportUrl = $url.”/”.$reportId.”?export=1&enc=UTF-8&xf=csv”;
5.) Initialize CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $reportUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Not doing any verification of SSL certificates
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIE, ‘sid=’.$client->sessionId);
setcookie(“sid”, $client->sessionId, 0, “/”, “.salesforce.com”, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$result = curl_exec ($ch);
curl_close ($ch);
$result is a XML of data now you can parse it using SimpleXMl library of php


Source : http://www.saasanalogy.com/getting-reports-from-salesforce-to-custom-portal-using-php/

Comments

Popular posts from this blog

Salesforce.com: Expression Operators in Salesforce lightning Components

Custom Calendar on VisualForce Page

Salesforce.com: Scheduled Apex