Importing SF attachments (Help!)

Created on 26 February 2013, almost 12 years ago
Updated 27 February 2024, 10 months ago

I need to download/import the attachments saved in salesforce to a node in drupal. What I´m doing is:

Create a content type 'attachments'
Create 2 fields: [attachment_file] [file_name]
Create mapping called also 'attachment'
Map those 2 fields to SF´s 'body' and 'file name' respectively
Create an attachment in SF and run Cron.

I always get this error on record create:
Invalid data value given. Be sure it matches the required data type and format. Processing failed for entity associated with Salesforce Object ID: 00PD000000GA9IzMAL

...and thisobvious one in case of updates:
Failed to update entity file1.png from Salesforce object sfobjectid. Error: Invalid data value given. Be sure it matches the required data type and format.

If i remove the map against SF´s body, everything is ok.

Also, if I map that body field to a normal text field, the import happens, and I find this:
/services/data/v25.0/sobjects/Attachment/00PD000000GA9kCMAT/Body

...this is what SF´s body is? I just don´t get it, I´m sure I´m doing something wrong or maybe I´m expecting too much from SF suite. Can someone point me in the right direction?

Thanks a lot

nico

💬 Support request
Status

Closed: duplicate

Version

3.0

Component

salesforce_pull.module

Created by

🇳🇱Netherlands nicodv

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States darrellduane

    I was able to retrieve a file from the ContentVersion object using PHP and cURL with this code snippet. It is using the Drupal 7 Salesforce Suite module.

    <?php
    
      $fullUrl = 'https://test.sandbox.my.salesforce.com/services/data/v60.0/sobjects/ContentVersion/' . $salesforce_entity_id . '/VersionData';
      
      $accessToken = $sfapi->getAccessToken();    
    
      // Use cURL to make the GET request
    
      $ch = curl_init($fullUrl);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Authorization: Bearer ' . $accessToken,
        'Content-type: application/json',
      ));
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow redirects
      curl_setopt($ch, CURLOPT_FAILONERROR, true); // Report HTTP code > 400 as error
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Do not verify SSL certificate
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Return the transfer as a string
      $image_data = curl_exec($ch);
    
      $directory = 'private://imagefiles/';
    
    
      $uri = $directory .  basename($title) . '.' . $filename; // Set the filename
    
      // Save the file data to the specified location
      $saved_file = file_save_data($image_data, $uri, FILE_EXISTS_REPLACE);
    
      // Save the file to the Drupal file system
      // $saved_file  = file_save($file);
    
      // Check if the file was saved successfully
      if ($saved_file) {
        drupal_set_message("The file has been saved successfully.");
      } else {
        drupal_set_message("There was an error saving the file.", 'error');
      }
    
      // Check for errors
      if (curl_errno($ch)) {
        $error_msg = curl_error($ch);
        ds($error_msg, 'cURL Error');
      }
      // Check if the request was successful and write the file
      curl_close($ch);
    ?>
    
Production build 0.71.5 2024