Utlilze a Apex Webservice in php

I was looking to get some report id in my php code so found a workaround for that. we can make a Apex webservice method and call that in php. So below is the step by step process to do that.
1.) Make a apex webservice class and a method.
To Create a class :- Develop| Apex Classes| New
Here we are making a service to get ReportID for a given report name

global class reportsManager{

WebService static string FindReport(string ReportName)
{
List reports = new list([Select Id, Name from Report Where Name = :ReportName]);
if (reports == null || reports.size() == 0) return null;

return reports[0].Id 
}
}

2.) Download the WSDL xml for above class and save it in a source folder.
To Download WSDL :-   Develop| Apex Classes| WSDL(Save the file)

3.)Now in your php code make a function as follows.
a.) Get connection to your org  ReferIntegration Blog.
$crmHandle = $this->getConnection()

b.)$sfdc = new SforcePartnerClient();// Making object of toolkit class

c.)Create a variable for your class name mine is "reportManager"
define ("_WS_NAMESPACE_", 'http://soap.sforce.com/schemas/class/reportsManager');

d.)Set headers of your request
$session=array("sessionId" => $_SESSION['sessionId']);
$sforce_header = new SoapHeader(_WS_NAMESPACE_, "SessionHeader",$session);

e.) Create a client of your webservice method
$client = new SoapClient('includes/soapclient/reportsManager.wsdl.xml');

f.)Set Parameters for your sebservice method mine takes a single param that is report name
$wsParams=array('ReportName'=>'test');

g.)Time to call the webservice method
$response = $client->FindReport($wsParams);
var_dump($response);

Bingo you have your result in $response
 
 
Source : http://www.saasanalogy.com/utlilze-a-apex-webservice-in-php/ 

Comments

Popular posts from this blog

Salesforce.com: Expression Operators in Salesforce lightning Components

Custom Calendar on VisualForce Page

Salesforce.com: Scheduled Apex