+ Reply to Thread
Results 1 to 1 of 1

Thread: Using String or float on Numeric Fields in Salesrforce with PHP

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

    Using String or float on Numeric Fields in Salesrforce with PHP

    I was working on this script over the past few days and in my orginal tutorial none of the fields that I supplied used or discussed any NUMERIC fields. I added two numeric fields to test the extraction process and I could not get the local array that I had created to be populated with the data coming in from the object from salesforce. This is just related to developers that are working with MySQL!

    My orginal tutorial, Salesforce – PHP To MySQL Database Replication Script, did not have any numeric fields to work with, therefore I did not take this into consideration. For that I am sorry. So in order to work with numeric fields, such as currency, from salesforce.com, here is what worked for me:

    Orginal Code:
    PHP Code:
    $pass_this['numeric_field1__c'] = $r->fields->numeric_field1__c;
    $pass_this['numeric_field2__c'] = $r->fields->numeric_field2__c
    the array > $pass_this was not being populated from the $r->fields object and it really threw me for a loop. I could not figure out why the fields were not being passed and it really started to get on my nerve. Then I remember that sometimes you have to tell PHP to cast variables to treat them a specific way. Look at my new php snippet:

    PHP Code:
    $pass_this['numeric_field1__c'] = (string)$r->fields->numeric_field1__c;
    $pass_this['numeric_field2__c'] = (string)$r->fields->numeric_field2__c
    By using the (string) function or cast, this makes PHP treat the object or variable as a string and then the value will pass to the array. You can also use (float) if you want to pass these values as a numeric field with decimals.

    Here is a full example with a complete array being passed from $r to $pass_this (see attached)
    Attached Files

+ 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