Obj Class - mkplabs/systogether-quickbooks GitHub Wiki
Obj is an Apex Wrapper that provides methods to interact with Quickbooks
Constructors
The following are constructors for Obj.
- STQB.Obj( sObject sfRecord )
Creates a new instance of the Obj class setting the sfRecord to the supplied sObject.
- STQB.Obj( String qbObject, Map<String,Object> qbRecord )
Creates a new instance of the Obj class setting the qbObject to the supplied String and the qbRecord to the supplied Map.
Properties
Obj Properties can only be accessed via the get and set methods
- String qbResourceName
- Map<String,Object> qbRecord
- List<Map<String,Object>> mappings
- sObject sfRecord
qbResourceName
The name of the Quickbooks Resource this Obj corresponds to. Values can be found at: https://developer.intuit.com/docs/api/accounting
qbRecord
A Map representation of the Quickbooks record's JSON structure.
mappings
A List containing the mapping of Quickbooks schema to Salesforce schema. If not provided, Custom Metadata will automatically be used. If you are going to provide you own mappings in Apex, each entry should use the following design:
Map<String,Object> mapping = new Map<String,Object>();
mapping.put('Salesforce_Object__c','Account');
mapping.put('Salesforce_Field__c','Quickbooks_Id__c');
mapping.put('Quickbooks_Object__c','Customer');
mapping.put('Quickbooks_Field__c','Id');
sfRecord
A Salesforce sObject
Methods
- get(String attribute)
- set(String attribute, Object value)
- set(Map<String,Object> attributes)
- fromSObject()
- toSObject()
- read()
- write()
- write(Boolean sparse)
- del()
get
\\Get the current value of the qbResourceName property
String qbResourceName = (String)obj.get('qbResourceName');
\\Get the current value of the mappings property
List<Map<String,Object>> mappings = (List<Map<String,Object>>)obj.get('mappings');
\\Get the current value of the qbRecord property
Map<String,Object> qbRecord = (Map<String,Object>)obj.get('qbRecord');
\\Get the current value of the sfRecord property
sObject sfRecord = (sObject)obj.get('sfRecord');
\\Get the current value of one of the qbRecord property attributes
String quickbooksId = (String)obj.get('Id');
set
\\Set the current value of the qbResourceName property
obj.set('qbResourceName','Invoice');
\\Set the current value of the qbRecord property
obj.set('qbRecord',new Map<String,Object>());
\\Set the current value of the mappings property
obj.set('mappings',new List<Map<String,Object>>());
\\Set the current value of the sfRecord property
obj.set('sfRecord',new Account());
\\Set the current value of one of the qbRecord property attributes
obj.set('Id','1');
\\Set multiple attributes on the qbRecord property
obj.set(new Map<String,Object>{'Id'=>'1','Name'=>'Customer'});
fromSObject
\\Populate qbRecord based on an sObject
Account acc = new Account(Name='Test',Quickbooks_Id__c='1');
STQB.obj obj = new ST4QB.obj(acc);
obj.fromSObject();
system.assert( obj.get('Id') == acc.Quickbooks_Id__c );
toSObject
Map<String,Object> qbRecord = new Map<String,Object>{'Id'=>'1'};
STQB.Obj obj = new STQB.Obj('Customer',qbRecord);
Account acc = (Account)obj.toSObject();
system.assert( acc.Quickbooks_Id__c == qbRecord.get('Id') );
read
Reads the record in Quickbooks and populates the qbRecord on the Obj
Map<String,Object> qbRecord = new Map<String,Object>();
qbRecord.put('Id','1');
STQB.Obj obj = new STQB.Obj('Customer',qbRecord);
obj.read();
system.assert( obj.get('CompanyName') != null );
write
\\Create a new record in Quickbooks
Map<String,Object> qbRecord = new Map<String,Object>{'DisplayName'=>'MK Partners'};
STQB.Obj obj = new STQB.Obj('Customer',qbRecord);
obj.write()
\\Overwrite all values on an existing record in Quickbooks
Map<String,Object> qbRecord = new Map<String,Object>{'Id'=>'1','DisplayName'=>'MK Partners'};
STQB.Obj obj = new STQB.Obj('Customer',qbRecord);
obj.write()
\\Update provided values on an existing record in Quickbooks by setting the Sparse boolean to true
Map<String,Object> qbRecord = new Map<String,Object>{'Id'=>'1','DisplayName'=>'MK Partners'};
STQB.Obj obj = new STQB.Obj('Customer',qbRecord);
obj.write(true)
del
\\Create a new record in Quickbooks
Map<String,Object> qbRecord = new Map<String,Object>{'Id'=>'1'};
STQB.Obj obj = new STQB.Obj('Customer',qbRecord);
obj.del()