To access opportunities data from Salesforce via soap api call get security token, Username and Password.
Also need force Soapclient library files. You can get these files from this link https://github.com/developerforce/Force.com-Toolkit-for-PHP/tree/master/soapclient
You can get opportunities data through query string for example Select Name, Opportunity_ID__c From Opportunity. Select required parameter data as per you need.
Use below sample code to execute the salesforce api in php:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php define('USERNAME', 'User name value'); define('PASSWORD', 'password value'); define('SECURITY_TOKEN', 'use security token here'); // include soapclient library files include('force/soapclient/SforceEnterpriseClient.php'); try { $mySforceConnection = new SforceEnterpriseClient(); $mySforceConnection->createConnection("enterprise.wsdl.xml"); $mySforceConnection->login(USERNAME,PASSWORD.SECURITY_TOKEN); $query = "SELECT Name,Opportunity_ID__c,CloseDate,AccountId,Amount,Description,Revenue_Line__c,ExpectedRevenue,Customer_Reference__c,Ship_To_City__c,Ship_To_Country__c,Ship_To_State__c,Ship_To_Name__c,Ship_To_Postal_Code__c FROM Opportunity"; $response = $mySforceConnection->query($query); foreach ($response->records as $record) { echo "Account ID:".$record->AccountId. ": " ."<br/>\n"; echo "Amount:".$record->Amount. ": " ."<br/>\n"; echo "Ship to city:".$record->Ship_To_City__c."<br/>\n"; echo "Name:".$record->Name."<br/>\n"; echo "Opportunity ID:".$record->Opportunity_ID__c. ": " ."<br/>\n"; echo "Close Date:".$record->CloseDate. ": " ."<br/>\n"; echo "Description:".$record->Description. ": " ."<br/>\n"; echo "Revenue Line:".$record->Revenue_Line__c. ": " ."<br/>\n"; echo "Expected Revenue:".$record->ExpectedRevenue. ": " ."<br/>\n"; echo "Customer Reference:".$record->Customer_Reference__c. ": " ."<br/>\n"; echo "Ship to Country:".$record->Ship_To_Country__c. ": " ."<br/>\n"; echo "Ship to state:".$record->Ship_To_State__c. ": " ."<br/>\n"; echo "Ship to Name:".$record->Ship_To_Name__c. ": " ."<br/>\n"; echo "Postal Code:".$record->Ship_To_Postal_Code__c. ": " ."<br/>\n"; } } catch (SoapFault $exception) { echo $exception->getMessage(); } ?> |
I want to fetch salesforce opportunities and show in my wordpress website, please help me from where can i start.
which API can i use or how to setup API.
Hello yash,
In wordpress create custom page to execute salesforce api call. Include all require files in that custom page.
Ok, Thank You for your response.