Created
July 7, 2020 05:35
-
-
Save verygoodplugins/2df7537981e0906324e58370849541c1 to your computer and use it in GitHub Desktop.
Create a custom object in Salesforce after a Gravity Forms submission
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*********************************************************************** | |
* Salesforce Create Inquiry | |
***********************************************************************/ | |
function red_new_business_inquiry_submission( $entry, $form ) { | |
// Switch Salesforce integration to the Inquiry_Form__c object type | |
add_filter( 'wpf_crm_object_type', function( $object_type ) { | |
return 'Inquiry_Form__c'; | |
} ); | |
// Get contact ID from the entry created by the WP Fusion feed | |
$contact_id = gform_get_meta( $entry['id'], 'wpf_contact_id' ); | |
// Build the array of Inquiry data | |
$inquiry_data = array( | |
'Contact__c' => $contact_id, | |
'Name' => rgar( $entry, '4' ), | |
'Name__c' => rgar( $entry, '1.3' ), // First Name | |
'Last_Name__c' => rgar( $entry, '1.6' ), | |
'Project_Name__c' => rgar( $entry, '4' ), | |
'Project_Mission__c' => rgar( $entry, '5' ), | |
'Programming_Location__c' => rgar( $entry, '10' ), | |
'Anticipated_Budget__c' => rgar( $entry, '6' ), | |
'People_Served_Annually__c' => rgar( $entry, '11' ), | |
'Years_Operating__c' => rgar( $entry, '7' ), | |
'Staffing_Model__c' => rgar( $entry, '12' ), | |
'How_did_you_hear_about_us__c' => rgar( $entry, '13' ), | |
'Committee_Established__c' => rgar( $entry, '9' ), | |
'Experience_with_Fiscal_Sponsor__c' => rgar( $entry, '8' ), | |
'Program_website__c' => rgar( $entry, '17' ), | |
'Submitted_Date__c' => date( 'Y-m-d' ), | |
); | |
// Log the data being sent to Salesforce | |
wp_fusion()->logger->handle( 'info', wp_get_current_user()->ID, 'Adding Inquiry: ', array( 'meta_array_nofilter' => $inquiry_data ) ); | |
// Create the new Inquiry object | |
$inquiry_id = wp_fusion()->crm->add_contact( $inquiry_data, false ); | |
// If Inquiry Form submission fails in Salesforce, log it to the WPF logs | |
if ( is_wp_error( $inquiry_id ) ) { | |
wp_fusion()->logger->handle( $inquiry_id->get_error_code(), wp_get_current_user()->ID, 'Error adding object to ' . wp_fusion()->crm->name . ': ' . $inquiry_id->get_error_message() ); | |
} | |
} | |
add_action( 'gform_post_submission_1', 'red_new_business_inquiry_submission', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment