This example builds a flow that copies the files attached to Salesforce accounts into the NetSuite File Cabinet and links each file to the NetSuite record created for its account. It's for builders who move files between applications that store them as attachments, not on a file server. The flow exports the accounts, retrieves each attachment, writes each file to NetSuite, and then imports the records. The same pattern works with an HTTP connection in place of either connector.
Flow steps
The flow has four steps. Each step adds a value to the record that the next step uses.
| Step | Step type | Adds to the record |
|---|---|---|
| Export the accounts | Export records from source application | The account, with an Attachments array |
| Retrieve each attachment | Look up additional files (per record) |
blobKey on each attachment |
| Write each file to NetSuite | Transfer files into destination application |
fileid on each attachment |
| Import the records | Import records into destination application | Nothing |
To add each step to a flow, see Add lookup, transfer, and other steps to a flow.
Export the accounts
The Salesforce export selects the accounts and, for each account, the ID and name of every attachment.
SELECT id, Name, phone, fax, (SELECT id, name FROM attachments), (SELECT id, title, body FROM notes) FROM Account WHERE name LIKE 'VL_T%'
Preview the export to see the structure of a record. Each account carries its files in the Attachments array, and the later steps process that array one item at a time.
{
"attributes": {
"type": "Account",
"url": "/services/data/v40.0/sobjects/Account/0015A00002LxEoFQAV"
},
"Id": "0015A00002LxEoFQAV",
"Name": "VL_TEST",
"Phone": "(510) 555-5555",
"Fax": null,
"Attachments": [
{
"attributes": {
"type": "Attachment",
"url": "/services/data/v40.0/sobjects/Attachment/00P5A00001EeqHDUAZ"
},
"Id": "00P5A00001EeqHDUAZ",
"Name": "file-amendment.pdf"
},
{
"attributes": {
"type": "Attachment",
"url": "/services/data/v40.0/sobjects/Attachment/00P5A00001EeqH8UAJ"
},
"Id": "00P5A00001EeqH8UAJ",
"Name": "file-contract.pdf"
}
],
"Notes": null
}Retrieve each attachment
The Salesforce lookup retrieves the file for each item in Attachments and stores a reference to it on that item.
-
One to many — Yes (advanced), because
Attachmentsis an array. -
Path to many —
Attachments, the array that the step processes once per item. -
sObject type — Attachment, the value of
typeon each item. -
Id —
{{record.attachmentId}}, the ID of the attachment. The step works on one item at a time, so the expression needs no array notation.
The lookup returns an array of objects, and the object for each file has a blobKey value that refers to the file. In the results mapping of the lookup, map data[0].blobKey to a new field named blobKey. The results mapping wraps the returned array in data, which is why the path starts with data[0].
Use the name blobKey because the NetSuite transfer step reads that field by default. After this step, each attachment has the new field.
{
"attributes": {
"type": "Attachment",
"url": "/services/data/v40.0/sobjects/Attachment/00P5A00001EeqHDUAZ"
},
"Id": "00P5A00001EeqHDUAZ",
"Name": "file-amendment.pdf",
"blobKey": "a2949b1546ca420798b77297a48a1950"
}Write each file to NetSuite
The NetSuite transfer step writes the file for each item in Attachments to a folder in the File Cabinet and returns the ID of the new file.
- One to many — Yes (advanced).
-
Path to many —
Attachments. - Operation — Add.
-
Name —
{{data.Name}}, the file name from the attachment. - Folder — The File Cabinet folder for the files.
-
Blob key path —
blobKey, the field that the lookup added.
For the other File Cabinet settings, see Import or lookup files from the NetSuite File Cabinet.
In the response mapping of the transfer step, map the ID of the new file from the response to a new field named fileid. After this step, each attachment has both new fields.
{
"attributes": {
"type": "Attachment",
"url": "/services/data/v40.0/sobjects/Attachment/00P5A00001EeqHDUAZ"
},
"Id": "00P5A00001EeqHDUAZ",
"Name": "file-amendment.pdf",
"blobKey": "a2949b1546ca420798b77297a48a1950",
"fileid": "7304"
}Import the records
The NetSuite import creates one record for each Salesforce account and attaches the files to it.
- One to many — No, because one exported account becomes one NetSuite record.
-
Mapping — Map
Attachments[*].fileidto the field on the NetSuite record that holds its attached files. The[*]passes the ID of every file in the array.