任意オブジェクト名を提供することでレコード作成

```
public class createrecordstest {
    public void createrecordstest1(){
        //複数オブジェクトが指定可能
        String[] selectedObj4 = new String[]{
                'Account',
                'Contact'
                };
        createstart(selectedObj4,'36506',[select id from Account Order by SystemModstamp desc limit 1].Id,
                  [select id from Contact Order by SystemModstamp desc limit 1].Id,
                    null,null,null);
    }
    
    public void createstart(String[] selectedObj,String dateflg,Id tmpid,Id tmpid2,Id tmpid3,Id tmpid4,Id tmpid5){
            List<Sobject> lis = new List<Sobject>();
            for(string objname:selectedObj){
                Map <String,Schema.SObjectType> gd = Schema.getGlobalDescribe();
                Schema.SObjectType sobjType = gd.get(objname);
                Schema.DescribeSObjectResult r = sobjType.getDescribe();
                Map<String, Schema.SObjectField> MapofField = r.fields.getMap();
                Sobject recs  = sobjType.newSobject();
                for(String fieldAPIName : MapofField.keySet()) {
                Schema.SObjectField field = MapofField .get(fieldAPIName);
                Schema.DescribeFieldResult F = field.getDescribe();
                    String sname = field.getDescribe().getName();
                    //数式ではないこと
                    if(!field.getDescribe().isCalculated()){
                        if(String.valueof(field.getDescribe().getType())=='STRING'&& field.getDescribe().isCreateable()
                                && !field.getDescribe().isNameField() &&  !field.getDescribe().isUnique()){
                            recs.put(sname,'1');
                        }
                        if(String.valueof(field.getDescribe().getType())=='DATE'
                                    &&  field.getDescribe().isCreateable()){
                            recs.put(sname,Date.today());     
                        }
                        if(String.valueof(field.getDescribe().getType())=='DATETIME'  
                                    &&(sname =='CreatedDate'  || field.getDescribe().isUpdateable()) ){
                                 recs.put(sname,DateTime.newInstance(Date.today().addDays(-1), Time.newInstance(1, 0, 0, 0)));
                        }
                        if(String.valueof(field.getDescribe().getType())=='TEXTAREA'&& field.getDescribe().isCreateable()){
                            recs.put(sname,'1');
                        }
                        if(String.valueof(field.getDescribe().getType())=='DOUBLE'&& field.getDescribe().isCreateable()&&  !field.getDescribe().isUnique()){
                            recs.put(sname,1.0);
                        }
                        if(String.valueof(field.getDescribe().getType())=='PHONE'&& field.getDescribe().isCreateable()){
                            recs.put(sname,'00000001111');
                        }
                        if(String.valueof(field.getDescribe().getType())=='PICKLIST'&& field.getDescribe().isCreateable()){
                            recs.put(sname,field.getDescribe().getPickListValues()[0].getValue());
                        }
                        if(String.valueof(field.getDescribe().getType())=='CURRENCY'&& field.getDescribe().isCreateable()){
                            recs.put(sname,1);
                        }
                        if(String.valueof(field.getDescribe().getType())=='INTEGER'&& field.getDescribe().isCreateable()&&  !field.getDescribe().isUnique()){
                            recs.put(sname,1);
                        }
                        //全角の項目はここで個別に対応する
                        if(sname == 'FormAddress__c'
                          ){
                            recs.put(sname,'ゼンカク');
                        }
                        //参照項目は渡されたパラメータで設定する
                        if(String.valueof(field.getDescribe().getType())=='REFERENCE'){
                            //if(sname == 'teamspirit__JournalId__c'&& objname =='teamspirit__AtkJournalDetail__c'){
                            //   recs.put(sname,tmpid);
                            //}
                        }                        
                      }
                    }
                    //system.debug(field.getDescribe().getType());
                }
                lis.add(recs);
            }
            insert lis;
    }
}