+ Reply to Thread
Results 1 to 5 of 5

Thread: Arrowpointe tutorial help with web services and PHP

  1. #1
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15

    Arrowpointe tutorial help with web services and PHP

    Scott per your request I thought that this would be an easier place to post the issues that I was having. The tutorial that you posted, Calling Apex Web Services from PHP | Perspectives on Salesforce.com, well I actually was able to get it to work somewhat. The cURL is actually working now.

    What I am having a hard time trying to understand is what benefit do you get from this. I actually just started to code in APEX, writing triggers and classes, but I am trying to find better ways to integrate this with other internal systems and code.

    In your example, what do you actually get out of using PHP with a web service. Off the top of my head I cannot conceive anything that would be of value.

    Maybe if you posted some examples of what exactly you can do or what you have done, that would be great. Not code examples, I will go to your site for that, but just some ideas on what is it that you have done.

    Here is the code that I borrowed from your site and actually was able to get it to work

    PHP Code:
    <?php
    ini_set
    ('soap.wsdl_cache_enabled''0');
    ini_set('soap.wsdl_cache_ttl''0');  
    require_once (
    '/users/msimonds/public_html/includes/sandbox_new.inc');


    $parsedURL parse_url($client->getLocation());

    //echo '<pre>' . print_r($parsedURL, true) . '</pre>';

    define ("_SFDC_SERVER_"substr($parsedURL['host'],0,strpos($parsedURL['host'], '.')));
    define ("_WS_NAME_"'MyWebService');
    define ("_WS_WSDL_"_WS_NAME_ '.xml');
    define ("_WS_ENDPOINT_"'https://' _SFDC_SERVER_ '.salesforce.com/services/wsdl/class/' _WS_NAME_);
    define ("_WS_NAMESPACE_"'http://soap.sforce.com/schemas/class/' _WS_NAME_);


    // SOAP Client for Web Service
    $client1 = new SoapClient(_WS_WSDL_);
    $sforce_header = new SoapHeader(_WS_NAMESPACE_"SessionHeader", array("sessionId" => $client->getSessionId()));
    $client1->__setSoapHeaders(array($sforce_header));

    // Setup fake data to send into the web service
    $prodAmtArray = array();
    $prodAmtArray[] = array('productId'=>'01t40000001RiKC','amount'=>100);
    $prodAmtArray[] = array('productId'=>'01t40000001RiKD','amount'=>200);

    $wrkArray = array(
                    
    'contactId'=>'0036000000nVtpT',
                    
    'inputs'=>$prodAmtArray
                    
    );

    // Call the web service
    $response $client1->myMethod($wrkArray);

    // Output results to browser
    //echo "<p><pre>" . print_r($response, true) . "</pre></p>";
    //echo "Contact Id is " . $response->result->contactId;

    $ch curl_init();
    $fp fopen(_WS_WSDL_"w");
    curl_setopt($chCURLOPT_URL_WS_ENDPOINT_);
    curl_setopt($chCURLOPT_FILE$fp);
    curl_setopt($chCURLOPT_HEADER0);
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
    curl_setopt($chCURLOPT_COOKIE'sid='.$client->getSessionId());
    setcookie("sid"$client->getSessionId(), 0"/"".salesforce.com"0);
    curl_setopt($chCURLOPT_TIMEOUT30);
    curl_exec($ch);
    fclose($fp);
    curl_close($ch);
     
      
      
      
    ?>
    it works like a charm, but I do not understand what you are exactly trying to accomplish here

  2. #2
    hemmeter is offline Junior Member
    Join Date
    May 2008
    Posts
    12
    The point is to have all your logic in Apex rather than PHP. In Apex it runs native on the Salesforce server. If you delete a field or make changes to one, the system will either stop you (in the case of deleting) or an Apex test will fail (if a destructive change was made). Using the API, you don't know something is wrong until it fails on your site.

    Think of Apex web services as creating a custom API to your Salesforce Org that can be called from PHP. Rather than create a new Account record using the insert method in the toolkit, maybe you have a method that sets all the defaults for you and you only need to pass in less data.

    A better example would be one I have used. I use Google Checkout to collect payments. When I send someone to a shopping cart, it passes in a unique ID to checkout. When a payment is made, Google Checkout has the ability to notify a URL with XML messages. I have a PHP page sitting there waiting for the XML. Once retrieved and confirmed it comes from Google, the PHP code passes the XML into Apex. The Apex code then archives the XML in a Salesforce record and also proceeds to update my Opportunity record and update the License record in Salesforce. I could do this same thing via PHP, but it's much faster and cleaner to do in Apex.

    To be honest, though, I have eliminated PHP for the above use case altogether. I used to do it that way, but now I expose a Visualforce Page on my Salesforce Site for Google to communicate with and it catches the XML and calls the same Apex code. It's all native now and I don't have to login with a username and password anymore! Even better.

  3. #3
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    So let me see if this example would work.

    If we have an internal system that our Sales team uses to create accounts, we could have a service that would connect to and APEX web service and then insert that account into the Accounts object with all the data that is required, etc....

  4. #4
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    557
    Blog Entries
    15
    In your examples I can see a need to PHP to work with APEX and now you even have switched that off, but for our needs I do not and cannot see any reason for an integration between PHP and APEX.

    I am just trying to understand where it would become viable so I would want to learn the integrations.

    I hope that makes sense

  5. #5
    sfisher is offline Junior Member
    Join Date
    Feb 2010
    Posts
    7
    One reason for using an Apex web service I encountered recently. I found I was bumping up against my 24 hour API request limit (the number of API requests you can make in a 24 hour period). I was able to replace 7 API requests with one request by moving the code from PHP onto Apex.

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.1