SFDC REST API From Formyoula

In this guide, we will share an example JavaScript code that will call Salesforce APEX to find duplicate records. The following JavaScript is used to get duplicate record data from Salesforce

// Call Salesforce
call_duplicate_check_salesforce_apex_rest_api({
  data: { 
		"req": {
	    "first_name": "",
	    "last_name": "",
			"email": "",
	    "company": { "name": "" },
	    "address": { "street": "", "post_code": "", "state": "", "country": "" }
	  }
	},
  callback: function(error, response) {
    // Get agency details
    var duplicates = JSON.parse(response);
    // Log results
    console.log(duplicates);
  }
});

function call_duplicate_check_salesforce_apex_rest_api(options) {
  // Call Salesforce APEX REST
  window.formyoula.sfdc.apexrest(
    // Path
    '/Formyoula_Duplicate_Check_API/',
    // Callback
    function(response) {
      // Return Callback 
      return options.callback(null, response);
    },
    // Error
    function(error) {
      // Return Callback 
      return options.callback(error, null);
    },
    // Method
    'POST',
    // Payload
    JSON.stringify(options.data),
    // ParamMap
    null,
    // Retry
    false
  );// END apexrest
}// END call_salesforce_apex

Salesforce APEX REST Class For Duplicate Record Check APEX Method

@RestResource(urlMapping='/Formyoula_Duplicate_Check_API/*')
global with sharing class Formyoula_Duplicate_Check_API {
  
  // Post request to find agency details based on search parameters
  @HttpPost
  global static String doPost( Request_JSON req ) {
    // Call Duty Holder duplicate check
    List<Contact> duplicate_records = Formyoula_Duplicate_Check.Get_Duplicate_Records(JSON.serialize(req));
    // Return records
    return JSON.serialize(duplicate_records);
  }// END doPost
  
  global class Request_JSON {
    global String first_name;
    global String last_name;
    global String email;
    global Company company;
    global Address address;
  }
  
  global class Company {
    global String name;
  }
  
  global class Address {
    global String street;
    global String post_code;
    global String state;
    global String country;
  }
  
}

For any questions, please contact us - at [email protected] or the Formyoula in-app chat 🙂