I am using a remote action for getting a result of list of information from a sObject. On my page load I am getting populating a map with field api name and label. But after the page load I click for remote action. The value of the map is getting reset. Now i changed the code and calling the method which populate the map from remote action. But still the the map value is null. Can anyone help me hoe to fix it.
public class ConfigurationCtrl {
public static Map<String, String> fieldNameLabel{get; set;}
public static Map<String, String> getfieldNameLabel(){
Schema.SObjectType objects = Configuration_Item__c.SObjectType;
Map<String, String> fieldNameLabel1 = new Map<String, String>();
for(Schema.SObjectField fld: objects.getDescribe().fields.getMap().values()){
System.debug('Ran describe ob '+fld.getDescribe().getlabel());
fieldNameLabel1.put(fld.getDescribe().getname(), fld.getDescribe().getlabel());
}
System.debug('fieldNameLabel: ' + fieldNameLabel1);
return fieldNameLabel1;
}
@RemoteAction
public static List<Configuration_Item__c> fetchFieldsetValues(string idList){
fieldNameLabel = new Map<String, String>();
getfieldNameLabel();
system.debug('fetchFieldsetValues idList '+idList);
List<String> ids = new List<String>();
ids = idList.split(';');
String recordtypeName = '';
integer i=0;
for(String idResult : ids ){
if(idResult.contains('RecTypeName')){
recordtypeName = idResult.remove(':RecTypeName-');
break;
}
i++;
}
ids.remove(i);
System.debug('Record type Name : ' + RecordtypeName );
List<Configuration_Item__c> configurationItemSOQLResult = ConfigurationItemsService.getConfigurationItemList(ids, recordtypeName );
System.debug('configuration Item SOQL Result '+ configurationItemSOQLResult);
//return JSON.serialize(configurationItemSOQLResult);
//Map<String, String> fieldNameLabel2 = new Map<String, String>();
//fieldNameLabel2 = getfieldNameLabel();
for(Configuration_Item__c ci: configurationItemSOQLResult)
System.debug('configuration Item '+ ci);
System.debug('field Name Label information : ' + fieldNameLabel );
return configurationItemSOQLResult;
}
}
VF page :
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.ConfigurationCtrl.fetchFieldsetValues}',
idList,function(result, event) {
console.log(result+' :result ');
//$('.selectionPanel_sec2').html(result);
//var obj = JSON.parse(result);
//var string = result.toString();
//var str = '{"val1": 1, "val2": 2, "val3": 3}';
//var obj = jQuery.parseJSON(string);
//alert(obj.val1);
// console.log(obj);
var resultarray = [];
var i = 0;
var string = '<table>';
$.each( result, function( key, value ) {
if (value.Name != 'PO2')
string +='<tr><td><input type="radio" name="configurationRadio" ></td>';
$.each( value , function( key1, value1 ) {
console.log( key1+'key1' + typeof key1);
key1=key1.replace("__c", " ");
key1=key1.replace("_", " ");
console.log( key1 + ": " + value1 );
// if (typeof value1 != 'undefined')
if (key1 != 'Id' && key1 != 'RecordTypeId' && value1 != 'PO2' ) string +='<td>'+key1 +' :'+value1+'</td>';
//else
//string +='<td>undefnd</td>';
//resultarray[i][key1] = value1;
//string +='<td>'+value1+'</td>';
});
string +='</tr>';
i++;
});
string +='</table>'
console.log('resultarray'+string);
$('.selectionPanel_sec2').html(string);
//obj = JSON.parse(text);
//console.log(obj +' :obj info');
});
}
Can anyone help me what is the reason for this issue. How to fix it? Is their other way by which we can hold the value of the map with out getting reset.