Showing posts with label Salesforce code corner. Show all posts
Showing posts with label Salesforce code corner. Show all posts

Wednesday, April 25, 2018

Creating Multiple Record in single rest request -Composite API

Hi

we have seen how can we create a record using  single rest request using OOB rest feature as below
/services/data/v40.0/sbjects/account

Method - POST
Body  - JSON
{
  "Name" :"testaccount"
}

Response will return with Id-
{
"Id":"001xxxxxxxxxxx"
}


Now if there is a need to insert data in tree structure in single request then which OOB Rest API need to follow, For this purpose we have Composite Tree API
Account -->contact (need to inset account and Contact in single oob rest req)
Here you go for tree API -
Url- /services/data/v41.0/composite/tree/account(Considering account to be parent node)
Method -Post
Body-
{
"records" :[{
    "attributes" : {"type" : "Account", "referenceId" : "ref1"},
    "name" : "ACC1",
    "phone" : "1234567890",
    "website" : "www.testtst.com",
    "industry" : "Banking",
    "Contacts" : {
      "records" : [
        {
         "attributes" : {"type" : "Contact", "referenceId" : "ref2"},
         "lastname" : "TestFname",
         "Title" : "TestLName",
         "email" : "sample@test.com"
         },
         {
         "attributes" : {"type" : "Contact", "referenceId" : "ref3"},
         "lastname" : "TestDLname",
         "title" : "Dev",
         "email" : "sample@testdev.com",
         "Camping_Item__r" :
             {
                "records" : [{
                "attributes" : {"type" : "Camping_Item__c", "referenceId" : "refCamping"},
                "name" : "mohicamplist"
                }]
             }
         }]
      }
    }]
}

Now the above example shows how can we create a tree structure(account-->contact-->campinglist) in single rest call  which will take automatic references from parent to child record.


Now what if we need to create record in tree structure with population of references from parent to child dynamically- Then Composite request is solution .

-In this approach a series of rest request executes in a single call

Url-
/services/data/v41.0/composite/

{
"compositeRequest" : [
  {
  "method" : "POST",
  "url" : "/services/data/v38.0/sobjects/Account",
  "referenceId" : "refAccount",
  "body" : { "Name" : "mohit composit1 Acc" }
  },
  {
  "method" : "POST",
  "url" : "/services/data/v38.0/sobjects/Contact",
  "referenceId" : "refContact",
  "body" : {
    "LastName" : "Sample composit Contact1",
    "AccountId" : "@{refAccount.id}"
    }
  },
  {
  "method" : "POST",
      "url" : "/services/data/v38.0/sobjects/Camping_Item__c",
       "referenceId" : "campingitem",
        "body" : {
        "name" : "ampingFnl",
        "Account__c" : "@{refAccount.id}",
         "Contact__c" : "@{refContact.id}",
         }
  } ]
}








Saturday, April 18, 2015

Email-to-Case Salesforce Engine

Email-to-Case functionality works like  success factor for company where customer can connect efficiently with quick interaction via email.
Customer can create ticket/cases while sending email to company support process  mail , ticket/inquiries can direct be placed to customer account in CRM.

It is process by which customer query can be resolved via interaction through email.

Process Flow Email-to Case SFDC:

  • When Customer send any  product malfunction/outage/breakdown  inquiries through email , Salesforce automatically logged a case and link the Account(Customer) and Contact(found by Email) to Case.
Feature can be setup:

Customize->Case->Email-to-case

  • Enable Email to Case
  • Enable Notify Case Owner on new Email

When sending Email from Case : Thread Id in subject & In Body

Thread Id : An id which is used for communication to & from for case to identify case related email thread.
if Customer reply to the mail having thread id in subject and in body, Email will automatically be linked to the Case.
All the email activities gone through this email(having ThreadID) communication will be recorded on case.

In Section Routing Address : 
Provide  support@company domain  in email,click on save--> an email notification will be received on "support@company domain"-->verify link-->
there will be email service address.

Set Email FWD setting on "support@company domain" -->Enter Email Service address (Recieived in  Section Routing Address).

Here its all done.

So when a customer send email @support it will forward email to Salesforce Email Service Address and Salesforce Engine eventually create a Case.