Я хотел клонировать основную запись с двумя связанными списками. Я написал несколько строк кода, сославшись на несколько статей.
настраиваемая кнопка для Clone со связанными элементами Контроллер APex:
public class PricingCloneWithItemsController {
private ApexPages.StandardController controller {get; set;}
private Pricing__c po {get;set;}
public ID newRecordId {get;set;}
public PricingCloneWithItemsController(ApexPages.StandardController controller) {
//initialize the stanrdard controller
this.controller = controller;
// load the current record
po = (Pricing__c)controller.getRecord();
}
// method called from the VF's action attribute to clone the po
public PageReference cloneWithItems() {
// setup the save point for rollback
Savepoint sp = Database.setSavepoint();
system.debug('newPO'+sp);
Pricing__c newPO;
po = [SELECT Contract_Reference_Number_Lookup1__c,CreatedById,CurrencyIsoCode,Currency__c,Effective_Date__c,
Executive_Approval__c,Executive_Comments__c,Executive__c,Expiry_Date__c,Id,LastModifiedById,Name,OwnerId, Pricing_Request_Title__c,Product_Manager_Approval__c,Product_Manager_Comments__c,RecordTypeId,Sales_Manager_Approval__c,Sales_Manager_Comments__c,Sales_Manager__c,State_Manager_Approval__c,State_Manager_Comments__c,State_Manager__c,Successful_Contract__c,
Tender_Reference_Number__c,Within_Parameters__c FROM Pricing__c where id = :po.id];
system.debug('po'+ po);
newPO = po.clone(false);
system.debug('newPO'+newPO);
insert newPO;
// set the id of the new po created for testing
newRecordId = newPO.id;
List<customer__c> items = new List<customer__c>();
for(Customer__c pi: [SELECT p.Account__c,p.CreatedById,p.CreatedDate,p.CurrencyIsoCode,p.Id,p.Name,p.Pricing__c FROM Customer__c p where Pricing__c = :po.id])
{
Customer__c newPI = pi.clone(false);
newPI.Pricing__c = newPO.id;
items.add(newPI);
}
insert items;
return new PageReference('/'+newPO.id+'/e?retURL=%2F'+newPO.id);
} }
визуальная принудительная страница для вызова действия:
<apex:page standardController="Pricing__c"
extensions="PricingCloneWithItemsController" action="{!cloneWithItems}">
<apex:pageMessages />
</apex:page>
Я получаю ошибку ниже, когда нажимаю на свою пользовательскую кнопку:
В списке нет строк для назначения SObject Ошибка в выражении '{! CloneWithItems}' в компоненте в ценообразовании на странице запись клон с соответствующими связями