Sunday, February 14, 2021

Insert attachments in salesforce with rest api

In this blog we will learn how to insert file type attachment in salesforce by Rest API with the help of workbench :

There is basically four subfields of file field in salesforce :

  1.  FieldName__Name__s  : Name of the attachment file.
  2.  FieldName__Body__s  :  Body of the attachment file.
  3.  FieldName__Length__s  : Length of the attachment file.
  4. FieldName__ContentType__s  : Type of the attachment file.  It is a picklist field which means it accepts only the values that are listed in picklist values. It has values like :
    application/html
    application/java-archive
    application/javascript
    application/msword
    application/octet-stream
    application/octet-stream;type=unknown
    application/pdf .... etc....

When inserting attachment with rest api only three subfields are required Name, Body and ContentType. Length will automatically generated after insertion of record. In The place of  Body__s subfield you have to give Base64 of that file which you want to insert. In the place of Name__s you have to give the name of the file and In the place of  ContentType__s you have to give the type of that file. Let's get Start :

Create a record with attachment :

Here i am creating one record with and inserting text file as attachment :

Method :- Post
URL:- /services/data/v50.0/sobjects/Knowledge__kav
Request Body :-

Insert attachment with rest api salesforce

In the place of Attachment__Body__s , I am giving converted base64 of text file.

Response :-

insert attachment with rest api salesforce

Record Created:-

insert attachment in salesforce


Thanks, 
Lovesalesforceyes

Get selected radio button value in LWC

This post explains how to get selected radio button in LWC. Below is demo of output : To use the radio button in LWC you have to use the  li...