3 answers
Below is a pseudo code : List<String> fieldNames = new List<String>();for(Template_Custom_Setting__c thisCs : Template_Custom_Setting__c.getValues(objectName)){ // Keep your splitting logic for getting the fields name as is. fieldNames.add(thisCs.fieldName);}for(String thisField : fieldNames){ finalFields =+ thisField;}String queryString = 'Select Id'+finalFields+' from Account Where Id ='+' \''+CurrentPageId+'\'';List<sObject> sobjList = Database.query(queryString);// Iterate over the list of field names. for(sObject thisRecord : sobjList){ for(String thisField : fieldNames){ system.debug('⌗⌗⌗⌗ Field Name = '+thisField); system.debug('⌗⌗⌗⌗ Field Value = '+thisRecord.get(thisField)); // you can create your XML structure, with the above values. }}If my suggestion(s) worked, do let me know by marking the answer as "Best Answer" right under the comment.This will help the rest of the community should they have a similar issue in the future. Thank you..