I'm running into a very odd issue and hoping someone else has also experienced this.
I'm trying to build an object to send to an application called Processmaker and it requires very a specific object definition. I'll leave an example from their documentation below. So my idea was to build a class so that I could easily create the structure required and send the request. The example they gave is not in Apex, but I figured I should be able translate it to Apex fairly easy. I seem to be wrong, unless I'm missing something.
The problem I'm having, is that when I run json.serialize(buildCase());
it only serializes the Map variable and not the entire object.
When I do a System.debug(cs1)
it returns the correct object structure, but when I do System.debug(json.serialize(cs1)
it only returns the Map<String,String> variable.
Has anyone else experienced something similar?
Object Structure Needed
The aVars
variable is the structure I need for my object
$aCaseVars = array(
"client" => 'Acme Inc.', //textbox with string variable
"amount" => 23456.99, //textbox with float variable
"address" => "245 Stars Av.\nHollywood CA 12345",//textarea with string variable
"dateDue" => '2015-12-31', //datetime
"dateDue_label" => '12/31/2015', //datetime label in MM/DD/YYYY format
"deliveryTime" => '2015-11-25 17:55:38', //datetime
"serviceType" => 'accounting', //dropdown with string variable
"serviceType_label" => 'Accounting Review', //dropdown label
"hasContract" => array('1'), //checkbox with boolean variable
"hasContract_label" => 'yes', //checkbox label
"howContact" => array('fax', 'email', 'telephone'), //checkbox group with string variable
"howContact_label" => '["Fax","Send Email","Telephone"]', //checkbox group label in JSON string
));
$aVars = array(
'pro_uid' => '325089587550b34ab5471f8086074839',
'tas_uid' => '491406639550b34b27f0b34088369199',
'variables' => $aCaseVars
);
This is what I put together.
Case Structure Class
public class CaseStructure {
public String pro_uid;
public String tas_uid;
public Map<String, String> variables = new Map<String, String>();
}
buildCase()
public static CaseStructure buildCase() {
Processmaker_Create_Case p0 = new Processmaker_Create_Case();
CaseStructure cs1 = new CaseStructure();
cs1.pro_uid = '1234567890';
cs1.tas_uid = '0987654321';
cs1.variables.put('ServiceRep', 'Bob Barker');
cs1.variables.put('SubmitDate', '10-12-2022');
cs1.variables.put('CustomerName', 'Big Guy');
cs1.variables.put('Company', 'CompanyRKHL');
cs1.variables.put('ContactName', 'Steve Harvey');
cs1.variables.put('CustomerContactNumber', '8031234567');
cs1.variables.put('CustomerEmailAddress', '[email protected]');
cs1.variables.put('CustomerAddress', '1234 Magic Lane');
cs1.variables.put('ApartmentSelection', 'AptSelectionApartment');
cs1.variables.put('City', 'Tega Cay');
cs1.variables.put('State', 'StateSC');
cs1.variables.put('Zipcode', '29708');
cs1.variables.put('SubdivisionSelection', 'SubSelectionNA');
cs1.variables.put('RequestTypeMain', 'RequestTypeNewConstruction');
cs1.variables.put('ServiceTypeRequested', 'ServiceTypeRequestedTelephone');
System.debug('PMCase Built: '+cs1);
System.debug(LoggingLevel.ERROR, json.serialize(cs1));
System.debug('PMCase Built Serialized: '+json.serialize(cs1));
return cs1;
}