global class MaintenanceEstimateCopy { WebService static String copy(String id) { Maintenance_Contract_Estimate__c oldMce = [select Discount_Percentage__c, Discount_Price__c, Maintenance_Contract__c from Maintenance_Contract_Estimate__c where Id = :id]; List oldMcae = [select Asset__c, Asset_Estimate_RMB__c from Maintenance_Contract_Asset_Estimate__c where Maintenance_Contract_Estimate__c = :id]; //try { Maintenance_Contract_Estimate__c newMce = new Maintenance_Contract_Estimate__c( Name = '*', Discount_Percentage__c = oldMce.Discount_Percentage__c, Discount_Price__c = oldMce.Discount_Price__c, Maintenance_Contract__c = oldMce.Maintenance_Contract__c ); insert newMce; List newMcae = new List(); for (Maintenance_Contract_Asset_Estimate__c mcae : oldMcae) { newMcae.add(new Maintenance_Contract_Asset_Estimate__c( Asset__c = mcae.Asset__c, Asset_Estimate_RMB__c = mcae.Asset_Estimate_RMB__c, Maintenance_Contract_Estimate__c = newMce.Id // コピーで作成した時を「継続」にする // New_Or_Old__c = '继承' )); } if (newMcae.size() > 0) insert newMcae; return newMce.Id; //} catch (Exception e) { // return 'NG'; //} } }