0

I am having a List like this

List<AcctSeed__Account_Payable_Line__c> acctPayLineItems = 
(List<AcctSeed__Account_Payable_Line__c>)System.JSON.deserialize(
strPayableLineItems, List<AcctSeed__Account_Payable_Line__c>.class);
AcctSeed__Account_Payable_Line__c: 
   {
      AcctSeed__Project_Task__c = a0uK0000009Qb7wIAC,
      AcctSeed__Tax_Amount__c = 2.0,
      AcctSeed__Unit_Cost__c = 2.0,
      AcctSeed__Quantity__c = 2.0,
      AcctSeed__Project__c = a0vK0000009vjBQIAY,
      AcctSeed__GL_Account_Variable_2__c = a0DK000000MHgHaMAL, 
      AcctSeed__Tax_Rate__c = 2.0,
      AcctSeed__Product__c = 01tK0000007HuZ8IAK,
      AcctSeed__Sub_Total__c = 2.0,
      AcctSeed__Expense_GL_Account__c = a0kK000000ArWx4IAF,
      AcctSeed__GL_Account_Variable_1__c = a0DK000000MHgHQMA1}

In the above I just have to form a string which have to give only the column name like

      AcctSeed__Project_Task__c,
      AcctSeed__Tax_Amount__c,
      AcctSeed__Unit_Cost__c,
      AcctSeed__Quantity__c......AcctSeed__GL_Account_Variable_1__c

I tried by String.Join(acctPayLineItems,',') but it's giving both column and values, but I need only columns.

1 Answer 1

4

You'll want to create a Set and add the fields from the method getPopulatedFieldsAsMap:

Set<String> fieldNames = new Set<String>();
for(AcctSeed__Account_Payable_Line__c record: acctPayLineItems) {
  fieldNames.addAll(record.getPopulatedFieldsAsMap().keySet());
}
System.debug(String.join((Iterable<String>)fieldNames,','));

You must log in to answer this question.

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