I am new to Apex and am trying to build a Map object which contains all the order information. Ideally, I would like to serialize this into JSON and send to a webservice. I have got to the point where I can query the different part of the order and fetch them, but I cannot create the final map.
My code upto this point is -
Order order = [SELECT Id, TotalAmount, AccountId, BillToContactId FROM Order]; Id orderId = order.Id; Decimal amount = order.TotalAmount; Id accountId = order.AccountId; Id contactId = order.BillToContactId; Account account = [select Name from Account where Id=:accountId]; //i understand that this should be Contact contact but i wanted to try and convert to map when fetching to make things simpler if possible? Map<string, string> contact = (Map<string, string>)[select Name, Email, MobilePhone from Contact where Id=:contactId]; List<OrderItem> items = [select OrderItemNumber, Product2Id, Quantity, TotalPrice, UnitPrice from OrderItem where OrderId=:orderId]; Map<String, Map<String, Object>> data = new Map<String, Map<String, Object>>(); data.put('contact', contact); data.put('account', account); //tried this too but errors out since map expects the second variable to be map system.debug(data);
I have left the error parts as well as comments on where I am getting stuck as part of the code. Any help is appreciated.
Please let me know if you need any details and point out any rookie mistakes.