Global API
...
Code Examples
File Upload for Flow
Class (Apex)
1min
opptyattachmenttons invokable public class opptyattachmenttons invokable { //invokable class to enable attachment upload as files in netsuite cabinets // v0 1 b newbold // note hardcoded internal id for cabinet folder check proper variable passing @invocablemethod(label='upload attachment to netsuite' description='uploads oppty attachments to netsuite invoked by flow (500k max size)' category='opportunity') // the main method to be implemented the flow calls this at run time public static list \<results> execute (list\<requests> requestlist) { //list\<sobject> inputcollection = requestlist\[0] inputcollection; // get the user input from the flow string caption = requestlist\[0] caption; blob contentdata = requestlist\[0] content; string contenturl = requestlist\[0] contenturl; string folder = requestlist\[0] folder; string name = requestlist\[0] name; id currentdocumentid = requestlist\[0] documentid; for (contentdocument docs \[select id, filetype, title, fileextension from contentdocument where id= \ currentdocumentid]) { for (contentversion docversion \[select id, versiondata from contentversion where contentdocumentid =\ currentdocumentid ]) { contentdata = docversion versiondata; } } //testing just sending a file map\<string, object> nsfile = new map\<string, object>(); nsfile put('caption', caption); nsfile put('content', encodingutil base64encode(contentdata)); nsfile put('folder', new map\<string, object>{'internalid'=>'758'}); //internal id of breadwinner uploads in test environment nsfile put('name', name); //create a results object to hold the return values results response = new results(); try{ // initialize the requestjson data to be passed map\<string, object> requestjsonmap = new map\<string, object>(); requestjsonmap put('files', new list\<object>{nsfile}); string reqjson = json serialize(requestjsonmap); map\<string, object> reqobj = new map\<string, object>(); reqobj put('version', '1 0'); reqobj put('action', 'uploadfile'); reqobj put('requestjson', reqjson); // place a request to breadwinner global api map\<string, object> resp = breadwinner ns breadwinnernetsuiteapi call(reqobj); system debug('response ' + resp); //take the netsuite response map and convert to single string string nsresponsestring = ''; for(string key resp keyset()){ if(nsresponsestring length() !=0){ nsresponsestring += ' '; } nsresponsestring += key + '=' + resp get(key); } response netsuiteresponse = nsresponsestring; } catch(exception e) { system debug('exception error ' + e); response netsuiteresponse = 'exception ' + e; } //typical reponse //validrequest=true responsejson={"fileinternalid" "4674","errors" \[],"status" "200"} action=uploadfile version=1 0 timestamp=1682635380113 //wrap the results object in a list container //(an extra step added to allow this interface to also support bulkification) list\<results> responsewrapper= new list\<results>(); responsewrapper add(response); return responsewrapper; } public class requests { //@invocablevariable(label='records for input' description='creates netsuite companies invoked by flow' required=false) //public list\<sobject> inputcollection; @invocablevariable(label='caption' description='file label/caption') public string caption; @invocablevariable(label='content' description='file data (base64encoded)') public blob content; @invocablevariable(label='contenturl' description='public url of content') public string contenturl; @invocablevariable(label='folder' description='internal id of destination folder') public string folder; @invocablevariable(label='name' description='file name (eg test pdf)') public string name; @invocablevariable(label='documentid' description='attachment record id') public string documentid; } public class results { //@invocablevariable(label='records for output' description='creates netsuite companies invoked by flow' required=false) //public sobject outputmember; @invocablevariable(label='netsuiteresponse' description='api response from netsuite') public string netsuiteresponse; } }