+ Reply to Thread
Results 1 to 5 of 5
This is a discussion on Upsert with a Parent Account within the Salesforce PHP Tutorials forums, part of the Salesforce category; Hi there, I have resolved many issues with the upsert. I do
  1. #1
    Kevin Davis is offline Junior Member
    Join Date
    Aug 2010
    Posts
    5

    Upsert with a Parent Account

    Hi there,

    I have resolved many issues with the upsert. I do have a question. I'm uploading another file over two the same account object, however, I seem to be having an issue with parent field. I put Parent:field_name and of course that didn't work.

    Any ideas in how to upsert with parent field??

    Thanks!

  2. #2
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    Kevin,

    I am sorry I just do not get what you are asking.

    Can you show me some code or try and explain it a little more

  3. #3
    Kevin Davis is offline Junior Member
    Join Date
    Aug 2010
    Posts
    5
    Hi there,

    Sorry for the delay.. Here is some source code to help you.

    $all_fields = array();
    $i = 0;

    while ($rec_1 = mysql_fetch_assoc($rec))
    {
    $all_fields[$i]['main_id'] = htmlspecialchars($acct_1['id']);
    $all_fields[$i]['Name'] = htmlspecialchars($acct_1['account_name']);
    $all_fields[$i]['Phone'] = htmlspecialchars($acct_1['phone']);
    $all_fields[$i]['BillingStreet'] = htmlspecialchars($acct_1['premise_address_1']);
    $all_fields[$i]['BillingCity'] = htmlspecialchars($acct_1['premise_city']);
    $all_fields[$i]['Parent:main_id'] = htmlspecialchars($acct_1['parent_account']);


    }

    foreach ($all_fields as $fieldset)
    {
    $sObject = new sObject();
    $sObject->type = 'Account'; // Salesforce Table or object that you will perform the upsert on
    $sObject->fields = $fieldset;
    array_push($sObjects, $sObject);
    }

    $success = upsert_accounts($client, $sObjects, $file_updated, $file_created, $file_failed);

    if (is_array($success))
    {
    $accounts_created = $accounts_created + $success[0];
    $accounts_updated = $accounts_updated + $success[1];
    $accounts_failed = $accounts_failed + $success[2];

    }

    $starting_record = $starting_record + $number_records;

    ob_start();
    $total_record_count = $total_record_count + $record_count;
    echo $total_record_count." records processed.<br />";
    ob_end_flush();


    I don't know if you need any more. But the main problem is that I can't seem to bound the parent field with the record field.

    Let me know if you need any more code.

  4. #4
    Adam Best is offline Junior Member
    Join Date
    Apr 2011
    Posts
    10
    Hi Kevin,

    It looks like you have your own functions in there so it will be hard to tell exactly what is going on.

    From a first glance i can see that you have wrong field names on your left hand side.

    Let me try and give you an example with correct fields names:

    PHP Code:
    ## ONLY USE WHEN UPSERTING ##
       
    $all_fields[$i]['Id']                         = htmlspecialchars($acct_1['id']); 

    ## BE CAREFUL - IF YOUR SALESFORCE ORG IS CONFIGURED FOR PERSON ACCOUNTS
    ## THEN THIS FIELD SHOULD NOT BE WRITTEN TO
       
    $all_fields[$i]['Name']                            = htmlspecialchars($acct_1['account_name']);

    ## THESE FIELDS LOOK OK ##
       
    $all_fields[$i]['Phone']                           = htmlspecialchars($acct_1['phone']);
       
    $all_fields[$i]['BillingStreet']                   = htmlspecialchars($acct_1['premise_address_1']);     
       
    $all_fields[$i]['BillingCity']                     = htmlspecialchars($acct_1['premise_city']);     

    ## THIS IS THE PARENT ACCOUNT FIELD NAME
    ## PLEASE NOTE THAT YOU NEED TO INSERT A PROPER 18 
    ## CHARACTER VALID ACCOUNT ID FOR THIS TO BE SUCCESSFUL 
       
    $all_fields[$i]['ParentId']                  = htmlspecialchars("00190000001xH0FAAU"); 
    As I do not have a copy of your function,

    PHP Code:
    $success upsert_accounts($client$sObjects$file_updated$file_created$file_failed); 
    I'm not able to verify if there are more issues that lie in there. I am assuming by your $client in that function you are declaring your Id field when upserting?

    PHP Code:
    $upsertResponse $mySforceConnection->upsert("Id", array ($sObject)); 
    Here is the developerforce.com page for Upsert if you haven't come across it yet.
    PHP Toolkit 13.0 Upsert Sample (Partner) - developer.force.com
    Regards,
    Adam

    Into Joomla! and SalesForce?
    Check us out below at
    http://www.miiworks.com/

  5. #5
    Kevin Davis is offline Junior Member
    Join Date
    Aug 2010
    Posts
    5
    Thank you Adam..

+ 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.2