Error while executing a CRM action
-
I have a button on a page, and I needed to delete a CRM record by clicking this button. I have added the below code function.php file in child theme.
function ajax_delete_record() {
if ( ! isset( $_POST['entity'], $_POST['id'] ) ) {
error_log( 'Missing parameters: ' . print_r( $_POST, true ) );
wp_send_json_error( 'Invalid parameters' );
return;
}
$entity = sanitize_text_field( $_POST['entity'] );
$id = sanitize_text_field( $_POST['id'] );
error_log( "Attempting to delete record: Entity = $entity, ID = $id" );
try {
// Perform deletion logic
//$ref = new \AlexaCRM\CRMToolkit\Entity\EntityReference( $entity, $id );
$request = [
[
'key' => 'id',
'type' => 'string',
'value' => $id,
]
];
$response = ASDK()->executeAction( 'new_WPDeleteSessionAction', $request );
if ( $response ) {
wp_send_json_success( 'Record deleted successfully.' );
} else {
wp_send_json_error( 'Failed to delete record.' );
}
} catch ( Exception $e ) {
error_log( 'Error: ' . $e->getMessage() );
wp_send_json_error( 'Error: ' . $e->getMessage() );
}
}
add_action( 'wp_ajax_delete_record', 'ajax_delete_record' );
add_action( 'wp_ajax_nopriv_delete_record', 'ajax_delete_record' );It code returns error “HTTP error! status: 500” on following lines:
$ref = new \AlexaCRM\CRMToolkit\Entity\EntityReference( $entity, $id );
$response = ASDK()->executeAction( ‘new_WPDeleteSessionAction’, $request );I’ve also added below namespace, but not worked:
use AlexaCRM\CRMToolkit\Entity\EntityReference;
and the js code working fine, as I can get the logs back.
Is there any namespaces are missing? Please helpThanks
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
The topic ‘Error while executing a CRM action’ is closed to new replies.