function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
satheesh8.k1.3890099515516848E12satheesh8.k1.3890099515516848E12 

Dynamic Process

HI All,

Please help me,

SQOLQuery = SQOLQuery+ ' from ' + SelectedObject+ ' where ' +CSVheaderFields[uniquecolumn] +' in:SetExternalid';
       
       System.debug('---------SQOLQuery--------'+SQOLQuery);
       
        // system.debug('= csvmapfield.keyset===:'+ csvmapfield.keyset());
        system.debug('=SQOLQuery===:'+SQOLQuery);
        list<account> resultedRecords=database.query(SQOLQuery);
        
   //     Map<Id, sObject> objRecordsMap = new Map<Id, sObject>();
   //     objRecordsMap.putAll( Database.query( SQOLQuery) );
   //     System.debug('++++++++++objRecordsMap+++++++'+objRecordsMap); 
        
        
    //    map<string,account> mapacc= new map<string,account>();
        map<String, Sobject> mp=new Map<String,Sobject>();
            for(account a:resultedRecords)
            {
                //mapacc.put(a.Ext_Id__c,a);
                mapacc.put(a.Ext_Id__c,a);
               // mp.put(a.Ext_Id__c,a);
            }
          System.debug('++++++++++mapacc+++++++'+mapacc);
        integer pk=1;                                                                  
        for (String s :csvmapfield.keySet())
        {  
            System.debug('++++++++++s+++++++'+s);       
           account accountaccsinglerow = mapacc.get(s);
           // System.debug('++++++++++accountaccsinglerow +++++++'+accountaccsinglerow );
            string SobjsingeleRecord= string.valueof(accountaccsinglerow );
            System.debug('------SobjsingeleRecord-------'+SobjsingeleRecord);
            String[] SobjsingeleRecord_array = SobjsingeleRecord.split(':');
            string SobjsingeleRecord_array1=SobjsingeleRecord_array[1].trim();
            SobjsingeleRecord_array1= SobjsingeleRecord_array1.substring(0,SobjsingeleRecord_array1.length()-1);
            SobjsingeleRecord_array1=SobjsingeleRecord_array1.substring(1);
            SobjsingeleRecord_array =SobjsingeleRecord_array1.split(',');
            
            list<string> cscvsingrow= csvmapfield.get(s);
            // String[] CSVsingeleRecord_array = cscvsingrow.split(',');
            // System.debug(' =CSVsingeleRecord_array ='+CSVsingeleRecord_array );
            
            for(integer i=0;i<CSVheaderFields.size();i++)
            {
                integer flag=0;
                //System.debug(' =cscvsingrow[i] ='+cscvsingrow[i] );
                string csvfiedvalue=cscvsingrow[i];
                string field=CSVheaderFields[i].trim();
                field=field+'='+cscvsingrow[i];
                field=field.replace('\n','');
                field=field.trim();
                field=field.toLowerCase();
                
                
                 System.debug('field:'+field );
                for(integer k=0;k<SobjsingeleRecord_array.size();k++)
                {
                    // System.debug('SobjsingeleRecord_array:'+SobjsingeleRecord_array[k]);
                    string pr=SobjsingeleRecord_array[k].trim().toLowerCase();
                    System.debug('pr:'+pr);
                    
                    if(field==pr){ 
                    flag=1;
                    break;
                }
                
                }
                if(flag==0)
                {
                    fieldsnotmatch.add(csvfiedvalue);
                
                }
            
            }
            
            if(fieldsnotmatch.size()>0)
            {
            
                system.debug('====fieldsnotmatch:'+fieldsnotmatch);
                string kk=string.valueof(fieldsnotmatch);
                
                system.debug('====s:'+s);
                fieldsnotmatchmap.put(s,fieldsnotmatch);
                string loops=string.valueof(fieldsnotmatch);
                Results1[pk++].add(loops);
                fieldsnotmatch= new list<String>();
            }
            else{
                Results1[pk++].add('Match/No Err Found');
            }
        }
        
        for(string a:fieldsnotmatchmap.keyset())
        {
            system.debug('key--:'+a+':value:'+fieldsnotmatchmap.get(a));
        }
        list<string> resultlst = new list<string>();
        resultlst.add('Values didn\'t match ');
        Results1[0].addall(resultlst);
        
        /*for(integer i=1;i<Results1.size();i++)
        {
        //index.add(string.valueof(i));
        Results1[i].add('Match');
        //List<string > tt=Results[i];
        // index.add(tt);
        }
        */
        // system.debug('@@@@@@@@@@'+Results1);
        return allFields;
         
    }


above code will work only for Account Object , but i wanted to do for all object ,

Please help me how to apply for all object like account.

maily focus on below code:

map<String, Sobject> mp=new Map<String,Sobject>();
            for(account a:resultedRecords)
            {
                //mapacc.put(a.Ext_Id__c,a);
                mapacc.put(a.Ext_Id__c,a);
               // mp.put(a.Ext_Id__c,a);
            }
          System.debug('++++++++++mapacc+++++++'+mapacc);
        integer pk=1;                                                                  
        for (String s :csvmapfield.keySet())
        {  
            System.debug('++++++++++s+++++++'+s);       
           account accountaccsinglerow = mapacc.get(s);
           // System.debug('++++++++++accountaccsinglerow +++++++'+accountaccsinglerow );
            string SobjsingeleRecord= string.valueof(accountaccsinglerow );
            System.debug('------SobjsingeleRecord-------'+SobjsingeleRecord);
            String[] SobjsingeleRecord_array = SobjsingeleRecord.split(':');
            string SobjsingeleRecord_array1=SobjsingeleRecord_array[1].trim();
            SobjsingeleRecord_array1= SobjsingeleRecord_array1.substring(0,SobjsingeleRecord_array1.length()-1);
            SobjsingeleRecord_array1=SobjsingeleRecord_array1.substring(1);
            SobjsingeleRecord_array =SobjsingeleRecord_array1.split(',');
            
            list<string> cscvsingrow= csvmapfield.get(s);
            // String[] CSVsingeleRecord_array = cscvsingrow.split(',');
            // System.debug(' =CSVsingeleRecord_array ='+CSVsingeleRecord_array );
            
            for(integer i=0;i<CSVheaderFields.size();i++)
            {
                integer flag=0;
                //System.debug(' =cscvsingrow[i] ='+cscvsingrow[i] );
                string csvfiedvalue=cscvsingrow[i];
                string field=CSVheaderFields[i].trim();
                field=field+'='+cscvsingrow[i];
                field=field.replace('\n','');
                field=field.trim();
                field=field.toLowerCase();
                
                
                 System.debug('field:'+field );
                for(integer k=0;k<SobjsingeleRecord_array.size();k++)
                {
                    // System.debug('SobjsingeleRecord_array:'+SobjsingeleRecord_array[k]);
                    string pr=SobjsingeleRecord_array[k].trim().toLowerCase();
                    System.debug('pr:'+pr);
                    
                    if(field==pr){ 
                    flag=1;
                    break;
                }

Thanks
Satheesh
 
Abhishek BansalAbhishek Bansal
Hi ,

Plesae initialize you Map as follows :
Map<Id, sObject> objRecordsMap = new Map<Id, sObject>(Database.query(SQOLQuery));

Now use Sobject instead of Account everywhere.

You can get all the methods of Sobject and their use in below Link :
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_sobject.htm

Let me know if you have any issue or you need more help.

Regards,
Abhishek.