I have a below code

public PageReference SyncCandidatewithMirror(map<Id, cxsrec__cxsCandidate__c> NewMap,Map<Id, List<String>> fieldChangedMapChanged, List<cxsrec__cxsCandidate__c> candidateList) {
     map<Schema.SObjectField,Schema.SObjectField> mapFieldWiseSchema=new map<Schema.SObjectField,Schema.SObjectField>();

        list<Candidate_Mirror__c> listCandidateMirrorToUpdate=new list<Candidate_Mirror__c>();

        for(cxsrec__cxsCandidate__c can : candidateList){

            Candidate_Mirror__c mirrorCandidate = new Candidate_Mirror__c();
            for(Schema.SObjectField sjobApp:fieldChangedMapChanged.get(can.Id)){
                 Schema.SObjectField sJobAppBackup=mapFieldWiseSchema.get(sjobApp);
                 mirrorCandidate.put(sJobAppBackup, can.get(sjobApp));


Here I am passing Map<Id, List<String>> fieldChangedMapChanged in method. I want to use this inside this for loop for(Schema.SObjectField sjobApp:fieldChangedMapChanged.get(can.Id)){

But I am getting this error Invalid loop variable type expected String was Schema.SObjectField. So I want to Convert List<String> into List<Schema.SObjectField>. Please anyone help me to solve this.

2 Answers 2


You can use the below code to get Schema.SObjectField type value corresponds to a String type. No need to convert List<String> into List<Schema.SObjectField>.

//Get all field of cxsrec__cxsCandidate__c in a map
SObjectType objectName = Schema.getGlobalDescribe().get('cxsrec__cxsCandidate__c');
Map<String, Schema.SObjectField> fields = objectName.getDescribe().fields.getMap();

//Loop through fieldChangedMapChanged with a string variable
for(String sjobApp :fieldChangedMapChanged.get(can.Id)){
    //Get Schema.SObjectField type based on string value
    Schema.SObjectField sJobAppBackup = fields.get(sjobApp);
    //-----your code-----

The problem is your map is having data type as Map<Id, List<String>> so fieldChangedMapChanged.get(can.Id) will return List<String> and the for loop is having a variable of type Schema.SObjectField sjobApp. Both need to of same data type.

You must log in to answer this question.

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