I am using the REST API to get responses from Data.com. I am able to de-serialize the response, but couldn't find a way to assign it to account fields. A sample response is below:

  "entityType": "DatacloudCompany",
  "errors": [],
  "matchEngine": "DunsRightMatchEngine",
  "matchRecords": [
      "additionalInformation": [
          "name": "matchGrade",
          "value": "AAAAZAAAAAA"
      "fieldDiffs": [],
      "matchConfidence": 10.0,
      "record": {
        "attributes": {
          "type": "DatacloudCompany"
        "Site": "Headquarters",
        "Zip": "ECAB 26",
        "Ownership": "Private",
        "Description": "National Banks",
        "Website": "www.google.com",
        "NumberOfEmployees": 524,
        "NaicsCode": "123456",
        "Name": "Google ABC Inc.",
        "Industry": "Media",
        "IsInactive": false,
        "Phone": "+12.34.5678.9090",
        "TickerSymbol": "",
        "Street": "Mountain View",
        "CompanyId": 1234567,
        "NaicsDesc": "Test Desc",
        "City": "Test City",
        "DunsNumber": "123456789",
        "Sic": "0000",
        "State": "",
        "YearStarted": "1987",
        "TradeStyle": "Test",
        "Country": "United States",
        "SicDesc": "Test Desc",
        "Fax": "+12.34.5678.9009",
        "AnnualRevenue": 4.46E+7
  "rule": "DunsRightMatchRule",
  "size": 1,
  "success": true

I'm trying to auto-clean account records using the REST-API.

  • 1
    Data.com provides its own APIs for matching to Accounts/Objects - is this your usecase? Into what have you deserialized the response? An DatacloudCompany sObject? Something else? In either case you should be able to compare objDataCloudCompany.Name == objAccount.Name or build some dynamic code to get the fields and compare. I might have misunderstood you, so please provide more info what your goal is – Christian Szandor Knapp Jan 14 '17 at 13:48
  • Correct @ChristianSzandorKnapp Am using the API provided by Data.com (/services/data/v38.0/match/DunsRightMatchEngine/DatacloudCompany/DunsRightMatchRule). Able to hit this API and get response back via HttpRequest and HttpResponse. But with the response received, how to parse and assign the values to the account record is where am stuck! I've provided the sample response which am getting in my post itself. Please let me know if you need any other info. – Vignesh V Jan 14 '17 at 15:30

I'd deserialize the response into a DataCloudCompany and proceed like so:

String jsonString = '{"entityType":"DatacloudCompany","errors":[],"matchEngine":"DunsRightMatchEngine","matchRecords":[{"additionalInformation":[{"name":"matchGrade","value":"AAAAZAAAAAA"}],"fieldDiffs":[],"matchConfidence":10.0,"record":{"attributes":{"type":"DatacloudCompany"},"Site":"Headquarters","Zip":"ECAB 26","Ownership":"Private","Description":"National Banks","Website":"www.google.com","NumberOfEmployees":524,"NaicsCode":"123456","Name":"Google ABC Inc.","Industry":"Media","IsInactive":false,"Phone":"+12.34.5678.9090","TickerSymbol":"","Street":"Mountain View","CompanyId":1234567,"NaicsDesc":"Test Desc","City":"Test City","DunsNumber":"123456789","Sic":"0000","State":"","YearStarted":"1987","TradeStyle":"Test","Country":"United States","SicDesc":"Test Desc","Fax":"+12.34.5678.9009","AnnualRevenue":4.46E+7}}],"rule":"DunsRightMatchRule","size":1,"success":true}';

DatacloudCompany deserializedCompany = (DatacloudCompany)JSON.deserialize(jsonString, DatacloudCompany.class);
//Duns Number only as an example of matching criteria
Id idAccountToUpdate = [select id from Account where DunsNumber =: deserializedCompany.DunsNumber].Id;
Account accountToUpdate = new Account(id = idAccountToUpdate,
                             AnnualRevenue = deserializedCompany.AnnualRevenue
                              // ..
update accountToUpdate;
  • Thanks for the inputs @Christian.. I've used the same which you've provided, however, am getting below error message. Could you please guide me solve this? Error: Compile Error: Method does not exist or incorrect signature: [String].deserialize(String, Type). I've also tried Type resultType = Type.forName('Json2ApexForAccountClean'); before de-serializing statement, but it didnt work either! Note: 'Json2ApexForAccountClean' is my class name, equivalent to 'DataCloudCompany' in your code. – Vignesh V Jan 16 '17 at 0:24
  • I understood you built your own class to deserialize the jsonString into. DataCloudCompany is a standard Salesforce Object which save you the trouble to build your own. The code I posted should work instantly in any DEV edition without further editing. The standard syntax should read MyClass objMyClass = (MyClass)JSON.deserialize(jsonString, Myclass.class); – Christian Szandor Knapp Jan 16 '17 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.