• esource8
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies

I'm having some trouble adding attachments to a salesforce case. I'm pretty new to developing on salesforce, and our system uses a custom implementation using the Drupal CMS to send and retreive data from salesforce.

 

We have a form system that, upon submit, executes a function that inserts data into a salesforce case. What I'm trying to do is add some code that takes a file (an array with a filename, path, mimetype, filesize), and adds it to a salesforce case. I have not been able to find any documentation that explains how this works with any sort of clarity, and again, please note that I am pretty unfamilair with the salesforce API.

 

The insertion currently works fine, I just need to figure out how to add attachments to it. Any help you could give me would be greatly appreciated.

 

Here is the function that handles the salesforce insertion:

 

function esource_inquiry_form_submit($form_id, $form_values) {
	global $user;
	global $sf_retrieve;
	global $form_values;
	profile_load_profile($user);
	
	$first_name = $user->profile_sf_FirstName;
	$last_name = $user->profile_sf_LastName;
	$user_name = $first_name ." ". $last_name;
	if (strlen($first_name) == 0 && strlen($last_name) == 0) {
		$user_name = $user->name;
	}
	$user_email = $user->mail;
	$user_phone = $user->profile_sf_Phone;

	$rid = 0;
	$user_company = $user->profile_sf_AccountName;

	//get the user's Salesforce ID, to map to ContactId in Salesforce case; added BJ 12/07/07
	
	$user_contactId = $user->profile_sf_Id;
	$idLen = strlen($user_contactId);
	$user_contactId = substr($user_contactId,0,$idLen-3);
	//////////

	$fields = array(
		'ContactId' => $user_contactId,
		'SuppliedName' => htmlspecialchars($user_name),
		'SuppliedPhone' => htmlspecialchars($form_values['phone']),
		'SuppliedEmail' => htmlspecialchars($user_email),
		'SuppliedCompany' =>htmlspecialchars($user_company),
		'Description' => htmlspecialchars($form_values['description']),
		'Priority' => htmlspecialchars($form_values['priority']),
		'Subject' => htmlspecialchars($form_values['subject']),
		'Origin' => "Web",
		'Detail__c' => $form_values['detail'],
//but attachments aren't fields, can't use this
 ); //This is the attachment array $attachment = $form_values['attachment']; $case_created = false; $test_mode = false; try {
//This works just fine, but how to add attachments to the case?
 $sf = new salesforce("modules/sf/partner.wsdl.xml", $test_mode); $sf_caseid = $sf->insert_case($fields);

//Where do I add attachments to the case insert?

 if ($sf_caseid === false) { watchdog('esource', "Failed to add case to salesforce; adding to sf_update_q", WATCHDOG_ERROR); } else { watchdog('esource', "Added case ".$sf_caseid." to salesforce"); $case_created = true; } } catch (Exception $e) { // connection failed watchdog('esource', "Connection to salesforce.com failed: ".$e->getMessage(), WATCHDOG_ERROR); } if ($case_created == false) { db_query("INSERT INTO {sf_update_q} (sf_table, value) VALUES ('Case', '%s')", serialize ($fields)); $message .= 'Name: ' . $user_name . '<br>'; $message .= 'Phone: ' . $form_values['phone'] . '<br>'; $message .= 'Email: ' . $user_email . '<br>'; $message .= 'Company: ' . $user_company . '<br><br>'; $message .= 'Your Question: ' . $form_values['description'] . '<br>'; $message .= 'Priority: ' . $form_values['priority'] . '<br>'; $message .= 'Subject: ' . $form_values['subject'] . '<br>'; $message .= 'Detail: ' . $form_values['detail'] . '<br>'; notify_user('webmaster@esource.com', 'Failed to add a case to Salesforce; adding to sf_update_q', $message); } else if ($case_created == true) { $message .= '<b>Thank you for your inquiry. The following information has been submitted to our Member Inquiry Service:</b><br>'; $message .= 'Name: ' . $user_name . '<br>'; $message .= 'Phone: ' . $form_values['phone'] . '<br>'; $message .= 'Email: ' . $user_email . '<br>'; $message .= 'Company: ' . $user_company . '<br><br>'; $message .= 'Your Question: ' . $form_values['description'] . '<br>'; $message .= 'Priority: ' . $form_values['priority'] . '<br>'; $message .= 'Subject: ' . $form_values['subject'] . '<br>'; $message .= 'Detail: ' . $form_values['detail'] . '<br>'; //notify_user(variable_get('member_inquiry_email_address', get_default_member_inquiry_email_address()), 'New Case Added by Member', $message); //message no longer being sent to Leland, because it duplicates a Salesforce notification. Changed 12/07/07 BJ } $_SESSION['inquiry_values'] = $form_values; return 'esource/inquiry_land'; }

 
Thanks in advance to anyone who can offer help.

I'm having some trouble adding attachments to a salesforce case. I'm pretty new to developing on salesforce, and our system uses a custom implementation using the Drupal CMS to send and retreive data from salesforce.

 

We have a form system that, upon submit, executes a function that inserts data into a salesforce case. What I'm trying to do is add some code that takes a file (an array with a filename, path, mimetype, filesize), and adds it to a salesforce case. I have not been able to find any documentation that explains how this works with any sort of clarity, and again, please note that I am pretty unfamilair with the salesforce API.

 

The insertion currently works fine, I just need to figure out how to add attachments to it. Any help you could give me would be greatly appreciated.

 

Here is the function that handles the salesforce insertion:

 

function esource_inquiry_form_submit($form_id, $form_values) {
	global $user;
	global $sf_retrieve;
	global $form_values;
	profile_load_profile($user);
	
	$first_name = $user->profile_sf_FirstName;
	$last_name = $user->profile_sf_LastName;
	$user_name = $first_name ." ". $last_name;
	if (strlen($first_name) == 0 && strlen($last_name) == 0) {
		$user_name = $user->name;
	}
	$user_email = $user->mail;
	$user_phone = $user->profile_sf_Phone;

	$rid = 0;
	$user_company = $user->profile_sf_AccountName;

	//get the user's Salesforce ID, to map to ContactId in Salesforce case; added BJ 12/07/07
	
	$user_contactId = $user->profile_sf_Id;
	$idLen = strlen($user_contactId);
	$user_contactId = substr($user_contactId,0,$idLen-3);
	//////////

	$fields = array(
		'ContactId' => $user_contactId,
		'SuppliedName' => htmlspecialchars($user_name),
		'SuppliedPhone' => htmlspecialchars($form_values['phone']),
		'SuppliedEmail' => htmlspecialchars($user_email),
		'SuppliedCompany' =>htmlspecialchars($user_company),
		'Description' => htmlspecialchars($form_values['description']),
		'Priority' => htmlspecialchars($form_values['priority']),
		'Subject' => htmlspecialchars($form_values['subject']),
		'Origin' => "Web",
		'Detail__c' => $form_values['detail'],
//but attachments aren't fields, can't use this
 ); //This is the attachment array $attachment = $form_values['attachment']; $case_created = false; $test_mode = false; try {
//This works just fine, but how to add attachments to the case?
 $sf = new salesforce("modules/sf/partner.wsdl.xml", $test_mode); $sf_caseid = $sf->insert_case($fields);

//Where do I add attachments to the case insert?

 if ($sf_caseid === false) { watchdog('esource', "Failed to add case to salesforce; adding to sf_update_q", WATCHDOG_ERROR); } else { watchdog('esource', "Added case ".$sf_caseid." to salesforce"); $case_created = true; } } catch (Exception $e) { // connection failed watchdog('esource', "Connection to salesforce.com failed: ".$e->getMessage(), WATCHDOG_ERROR); } if ($case_created == false) { db_query("INSERT INTO {sf_update_q} (sf_table, value) VALUES ('Case', '%s')", serialize ($fields)); $message .= 'Name: ' . $user_name . '<br>'; $message .= 'Phone: ' . $form_values['phone'] . '<br>'; $message .= 'Email: ' . $user_email . '<br>'; $message .= 'Company: ' . $user_company . '<br><br>'; $message .= 'Your Question: ' . $form_values['description'] . '<br>'; $message .= 'Priority: ' . $form_values['priority'] . '<br>'; $message .= 'Subject: ' . $form_values['subject'] . '<br>'; $message .= 'Detail: ' . $form_values['detail'] . '<br>'; notify_user('webmaster@esource.com', 'Failed to add a case to Salesforce; adding to sf_update_q', $message); } else if ($case_created == true) { $message .= '<b>Thank you for your inquiry. The following information has been submitted to our Member Inquiry Service:</b><br>'; $message .= 'Name: ' . $user_name . '<br>'; $message .= 'Phone: ' . $form_values['phone'] . '<br>'; $message .= 'Email: ' . $user_email . '<br>'; $message .= 'Company: ' . $user_company . '<br><br>'; $message .= 'Your Question: ' . $form_values['description'] . '<br>'; $message .= 'Priority: ' . $form_values['priority'] . '<br>'; $message .= 'Subject: ' . $form_values['subject'] . '<br>'; $message .= 'Detail: ' . $form_values['detail'] . '<br>'; //notify_user(variable_get('member_inquiry_email_address', get_default_member_inquiry_email_address()), 'New Case Added by Member', $message); //message no longer being sent to Leland, because it duplicates a Salesforce notification. Changed 12/07/07 BJ } $_SESSION['inquiry_values'] = $form_values; return 'esource/inquiry_land'; }

 
Thanks in advance to anyone who can offer help.

Could somebody provide me with sample code on how to upload attachments to cases in asp or aspx?