Global API

Quick Start Guide

2min
use case when i change the name on the salesforce account i also want that to change the company name on the breadwinner company record and on the customer record in netsuite this can be done by creating a trigger to update the customer record in netsuite any time the account name changes on the salesforce account the below code was created using our apex generator and then modified slightly to fit our use case create an apex class to fill in the json request needed to update the netsuite customer record apex class // start future method class called from trigger 'bw accounttrigger' public class writenetsuitecustomerfuture { @future (callout=true) public static void updatenetsuitecustomer(string accountrecords) { list\<account> accountlist = new list\<account>(); try{ accountlist = (list\<account>)json deserialize(accountrecords , list\<account> class); map\<string, string> mapofaccountidvsnetsuitecustomerinternalid = new map\<string, string>(); for(breadwinner ns bw company c accountvar \[select id, breadwinner ns internalid c, breadwinner ns salesforce account c from breadwinner ns bw company c where breadwinner ns entity type c = 'customer' and breadwinner ns salesforce account c in accountlist ]){ mapofaccountidvsnetsuitecustomerinternalid put(accountvar breadwinner ns salesforce account c, accountvar breadwinner ns internalid c); } list\<object> netsuitecustomerlist = new list\<object>(); // iterate over all the passed in account records for(account accountvar accountlist){ map\<string, object> netsuitecustomermap = new map\<string, object>(); // assign the values of account to netsuite customer if(mapofaccountidvsnetsuitecustomerinternalid containskey(accountvar id)) { netsuitecustomermap put('internalid',mapofaccountidvsnetsuitecustomerinternalid get(accountvar id)); &#x9; netsuitecustomermap put('companyname',accountvar name); netsuitecustomerlist add(netsuitecustomermap); &#x9; } } 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' , 'updatecustomer'); finalreqmap put('requestjson' , reqjson); system debug('request ' + finalreqmap); map\<string, object> respmap = breadwinner ns breadwinnernetsuiteapi call(finalreqmap); system debug('response ' + respmap); }catch(exception e) { system debug('exception error ' + e); } } } // end future method class called from trigger "bw accounttrigger" next create a trigger to run the above method only if the account name has changed updated trigger // start trigger // trigger executed after account record is update trigger bw accounttrigger on account (after update) { if(!system isfuture() && !system isbatch() && trigger isupdate && trigger isafter){ list\<account> accountlist = new list\<account>(); for(account accountvar trigger new){ // compare the new account name to the old one // and add that to the account list only if something has changed if(accountvar name != trigger oldmap get(accountvar id) name){ accountlist add(accountvar); } } if(!accountlist isempty()){ writenetsuitecustomerfuture updatenetsuitecustomer(json serialize(accountlist)); } } } // end trigger now when i change eastern mills corp on the salesforce account to eastern mills enterprises and click 'save', the change happens in all 3 places