List<order_batch__c> bcList = new List<order_batch__c>();
    bcList= [select Or_sub_po_number__c,Or_customer_PO_Number__c,
            from order_batch__c  where  Quote_Line_Item__r.Quote1__c= : Apexpages.currentPage().getParameters().get('Id')];


In debug console:

12:39:38:127 USER_DEBUG [44]|DEBUG|(Order_batch__c:{Order_numbering__c=1, [email protected], Or_Nicomatic_p_n__c=123, Or_customerid__c=2, CurrencyIsoCode=CAD, Or_Comments__c=12, Or_invoiceadd1__c=4, Discount__c=false, Requested_Date__c=2014-09-01 00:00:00, Or_sub_po_number__c=BHARAT, Or_invoiceadd4__c=7, Or_Quote_number__c=NINAL140718548, Quote_Line_Item__c=a0LN0000000yWu4MAE, Or_invoiceadd3__c=6, Unit_price__c=11.0000, Or_invoiceadd5__c=8, Or_customer_PO_Number__c=BHARAT, Or_Account_name__c=3, Or_contact_Phone__c=97999999999, Or_Carrier__c=9, Id=a1EN00000001iBQMAY, Or_contact_Fax__c=123333333, Or_invoiceadd2__c=5, Quantity_Ordered__c=1.0000}, Order_batch__c:{Order_numbering__c=3, [email protected], Or_Nicomatic_p_n__c=456, Or_customerid__c=2, CurrencyIsoCode=CAD, Or_Comments__c=12, Or_invoiceadd1__c=4, Discount__c=true, Requested_Date__c=2014-09-02 00:00:00, Or_sub_po_number__c=BHARAT, Or_invoiceadd4__c=7, Or_Quote_number__c=NINAL140718548, Quote_Line_Item__c=a0LN0000000yWu3MAE, Or_invoiceadd3__c=6, Unit_price__c=2.0000, Or_invoiceadd5__c=8, Or_customer_PO_Number__c=BHARAT, Or_Account_name__c=3, Or_contact_Phone__c=97999999999, Or_Carrier__c=9, Id=a1EN00000001iGtMAI, Or_contact_Fax__c=123333333, Or_invoiceadd2__c=5, Quantity_Ordered__c=12.0000}, Order_batch__c:{Order_numbering__c=2, Or_customerid__c=2, Or_Comments__c=12, Discount__c=false, Order_Date__c=2014-09-01 00:00:00, Or_sub_po_number__c=BHARAT, Or_invoiceadd4__c=7, Or_invoiceadd3__c=6, Or_contact_Phone__c=97999999999, Or_invoiceadd2__c=5, [email protected], Or_Nicomatic_p_n__c=123, CurrencyIsoCode=CAD, Or_invoiceadd1__c=4, Requested_Date__c=2014-09-01 00:00:00, Quote_Line_Item__c=a0LN0000000yWu4MAE, Or_Quote_number__c=NINAL140718548, Unit_price__c=1.0000, Or_invoiceadd5__c=8, Or_customer_PO_Number__c=BHARAT, Or_Account_name__c=3, Or_Carrier__c=9, Id=a1EN00000001iBLMAY, Or_contact_Fax__c=123333333, Quantity_Ordered__c=1.0000})

How i can send columns in the same order as specified in the query?

2 Answers 2


UPDATE - I'm now generating the JSON string completely manually. This gives you complete control over how the string appears.

You could loop through each object in the list and build the JSON string incrementally like so:

String JSONString = '';
for (order_batch__c order : bcList) {

String orderJSON = '{\n' +
    ' "Or_sub_po_number__c" :"' + order.Or_sub_po_number__c + '",\n' +
    ' "Or_customer_PO_Number__c" :"' + order.Or_customer_PO_Number__c + '",\n' +
    ' "Or_customerid__c" :"' + order.Or_customerid__c + '",\n' +
    ' "Or_Account_name__c" :"' + order.Or_Account_name__c + '",\n' +
    ' "Or_invoiceadd1__c" :"' + order.Or_invoiceadd1__c + '",\n' +
    ' "Or_invoiceadd2__c" :"' + order.Or_invoiceadd2__c + '",\n' +

    JSONString += orderJSON;

I haven't tested this, but the loop should generate a valid JSON string. You also may need to add a bit more formatting to make it a proper JSON string, ie, put a {[ at the start, add commas and put ]} at the end.

I know it's static, but at least it's all contained in one file so there are no external dependencies.

  • still it is taking as a same order
    – Teja
    Commented Sep 4, 2014 at 8:56
  • it not in json in the bclist level only it is changing the oreder
    – Teja
    Commented Sep 4, 2014 at 9:04

I don't think it is possible to force the columns to come out in any particular order, except by literally forcing them. That is, individually referencing each field in the order that you desire, in your output / JSON encode / whatever.

  • it is possible .i am trying to sort it
    – Teja
    Commented Sep 4, 2014 at 9:27
  • Great, I'll be really interested in how you do it.
    – Dominic
    Commented Sep 4, 2014 at 9:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .