Global API
...
Code Examples
Invokable Class for Flow

Class (Apex)

1min
bw createnetsuitecompany invokable public class bw createnetsuitecompany invokable { @invocablemethod(label='create netsuite company' description='creates netsuite companies invoked by flow' category='account') // the main method to be implemented the flow calls this at run time public static list \<results> execute (list\<requests> requestlist) { // get the user input from the flow string testmode = requestlist\[0] testmode; string firstname = requestlist\[0] firstname; string lastname = requestlist\[0] lastname; string companyname = requestlist\[0] companyname; string accountnumber = requestlist\[0] accountnumber; //accountnumber string phone = requestlist\[0] phone; //phone string website = requestlist\[0] website; //url string billingstreet = requestlist\[0] billingstreet; string billingcity = requestlist\[0] billingcity; string billingstate = requestlist\[0] billingstate; string billingpostalcode = requestlist\[0] billingpostalcode; string shippingstreet = requestlist\[0] shippingstreet; string shippingcity = requestlist\[0] shippingcity; string shippingstate = requestlist\[0] shippingstate; string shippingpostalcode = requestlist\[0] shippingpostalcode; string subsidiaryid = requestlist\[0] subsidiaryid; //string taxnumber = requestlist\[0] taxnumber; //example of custom field sf ncf entity tax reg no c ns custentity tax reg no //create a results object to hold the return values results response = new results(); if (testmode == 'sendtonetsuite') { //using the testmode parameter filled with 'sendtonetsuite' is required for this class, as a security feature you may want to remove this for production deploy try{ list\<object> netsuitecustomerlist = new list\<object>(); map\<string, object> netsuitecustomermap = new map\<string, object>(); netsuitecustomermap put('subsidiary', new map\<string, object>{'internalid'=>'8'}); //subsidiaryid); //assign value of account to netsuite customer netsuitecustomermap put('accountnumber',accountnumber); netsuitecustomermap put('companyname',companyname); netsuitecustomermap put('phone',phone); netsuitecustomermap put('url',website); //netsuitecustomermap put('custentity tax reg no',taxnumber); //custom field example string billingaddr = string isnotblank(billingstreet) ? billingstreet ''; string billingaddr1 = ''; string billingaddr2 = ''; string billingaddr3 = ''; if(billingaddr length() >= 0 && billingaddr length() <= 150){ billingaddr1 = billingaddr substring(0,billingaddr length()); }else if(billingaddr length() > 150 && billingaddr length() <= 300){ billingaddr1 = billingaddr substring(0,150); billingaddr2 = billingaddr substring(150,billingaddr length()); }else if(billingaddr length() > 300 && billingaddr length() <= 450){ billingaddr1 = billingaddr substring(0,150); billingaddr2 = billingaddr substring(150,300); billingaddr3 = billingaddr substring(300,billingaddr length()); }else if(billingaddr length() > 450){ billingaddr1 = billingaddr substring(0,150); billingaddr2 = billingaddr substring(150,300); billingaddr3 = billingaddr substring(300,450); } map\<string, object> billingaddrfieldmap = new map\<string, object>(); billingaddrfieldmap put('addr1' , billingaddr1); billingaddrfieldmap put('addr2' , billingaddr2); billingaddrfieldmap put('addr3' , billingaddr3); billingaddrfieldmap put('city' , billingcity); billingaddrfieldmap put('state' , billingstate); billingaddrfieldmap put('zip' , billingpostalcode); map\<string, object> abaaddressforbillingmap = new map\<string, object>(); abaaddressforbillingmap put('addressbookaddress' , billingaddrfieldmap); string shippingaddr = string isnotblank(shippingstreet) ? shippingstreet ''; string shippingaddr1 = ''; string shippingaddr2 = ''; string shippingaddr3 = ''; if(shippingaddr length() >= 0 && shippingaddr length() <= 150){ shippingaddr1 = shippingaddr substring(0,shippingaddr length()); }else if(shippingaddr length() > 150 && shippingaddr length() <= 300){ shippingaddr1 = shippingaddr substring(0,150); shippingaddr2 = shippingaddr substring(150,shippingaddr length()); }else if(shippingaddr length() > 300 && shippingaddr length() <= 450){ shippingaddr1 = shippingaddr substring(0,150); shippingaddr2 = shippingaddr substring(150,300); shippingaddr3 = shippingaddr substring(300,shippingaddr length()); }else if(shippingaddr length() > 450){ shippingaddr1 = shippingaddr substring(0,150); shippingaddr2 = shippingaddr substring(150,300); shippingaddr3 = shippingaddr substring(300,450); } map\<string, object> shippingaddrfieldmap = new map\<string, object>(); shippingaddrfieldmap put('addr1' , shippingaddr1); shippingaddrfieldmap put('addr2' , shippingaddr2); shippingaddrfieldmap put('addr3' , shippingaddr3); shippingaddrfieldmap put('city' , shippingcity); shippingaddrfieldmap put('state' , shippingstate); shippingaddrfieldmap put('zip' , shippingpostalcode); map\<string, object> abaaddressforshippingmap = new map\<string, object>(); abaaddressforshippingmap put('addressbookaddress' , shippingaddrfieldmap); map\<string, object> abbillingshippingmap = new map\<string, object>(); abbillingshippingmap put('addressbook' , new list\<object>{abaaddressforbillingmap,abaaddressforshippingmap}); netsuitecustomermap put('addressbooklist' , abbillingshippingmap); //enable this section for custom fields / // initializing the custom fields list\<object> custcustomfieldlist = new list\<object>(); map\<string, object> custcustomfield1 = new map\<string, object>(); custcustomfield1 put('fieldtype', 'string'); custcustomfield1 put('scriptid', 'custentity tax reg no'); custcustomfield1 put('value', taxnumber); custcustomfieldlist add(custcustomfield1); // adding the customer custom fields netsuitecustomermap put('customfieldlist', new map\<string, object>{'customfield'=>custcustomfieldlist}); / netsuitecustomerlist add(netsuitecustomermap); map\<string, object> reqjsonmap = new map\<string, object>(); reqjsonmap put('customers' , netsuitecustomerlist); string reqjson = json serialize(reqjsonmap); map\<string, object> finalreqmap = new map\<string, object>(); finalreqmap put('version' , '1 0'); finalreqmap put('action' , 'createcustomer'); finalreqmap put('requestjson' , reqjson); system debug('request ' + finalreqmap); //namespace should be same as breadwinner objects in this org //map\<string, object> respmap = ns rc 02 breadwinnernetsuiteapi call(finalreqmap); map\<string, object> respmap = breadwinner ns breadwinnernetsuiteapi call(finalreqmap); system debug('response ' + respmap); response companyinternalid = 'blank'; //take the netsuite response map and convert to single string string nsresponsestring = ''; for(string key respmap keyset()){ if(nsresponsestring length() !=0){ nsresponsestring += ' '; } nsresponsestring += key + '=' + respmap get(key); } response netsuiteresponse = nsresponsestring; } catch(exception e) { system debug('exception error ' + e); response netsuiteresponse = 'exception ' + e; } } //only executes if test mode set correctly this should be removed/reworked prior to production deploy // send return values to flow //add the return values to the results object //response outputmember = outputmember; response testmode = testmode; response firstname = 'name'; response lastname = 'changes'; response companyname = companyname; //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='testmode') public string testmode; @invocablevariable(label='firstname') public string firstname; @invocablevariable(label='lastname') public string lastname; @invocablevariable(label='companyname') public string companyname; @invocablevariable(label='accountnumber') public string accountnumber; @invocablevariable(label='phone') public string phone; @invocablevariable(label='website') public string website; @invocablevariable(label='billingstreet') public string billingstreet; @invocablevariable(label='billingcity') public string billingcity; @invocablevariable(label='billingstate') public string billingstate; @invocablevariable(label='billingpostalcode') public string billingpostalcode; @invocablevariable(label='shippingstreet') public string shippingstreet; @invocablevariable(label='shippingcity') public string shippingcity; @invocablevariable(label='shippingstate') public string shippingstate; @invocablevariable(label='shippingpostalcode') public string shippingpostalcode; @invocablevariable(label='subsidiaryid') public string subsidiaryid; //custom field example / @invocablevariable(label='taxnumber') public string taxnumber; / } public class results { //@invocablevariable(label='records for output' description='creates netsuite companies invoked by flow' required=false) //public sobject outputmember; @invocablevariable(label='testmode') public string testmode; @invocablevariable(label='firstname') public string firstname; @invocablevariable(label='lastname') public string lastname; @invocablevariable(label='companyname') public string companyname; @invocablevariable(label='companyinternalid') public string companyinternalid; @invocablevariable(label='netsuiteresponse') public string netsuiteresponse; } } //original from https //mukulmahawariya11 medium com/calling invocable apex from flow 838879a332f7 //retooled for standard @invokable according to sf docs https //developer salesforce com/docs/atlas en us apexcode meta/apexcode/apex classes annotation invocablemethod htm