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
Bernd BretzelmannBernd Bretzelmann 

Visualforce Error: Unknown method

I created a trigger which should duplicate a record with its child records to another object, which works. Now I want to call that function with a click on a button. I created an Apex Class which has a method now I want to create a Visualforce page which just calls the method but it says the method is unknown

Here my VF
<apex:page controller="CreatInvoiceRecord" 
action="{!createDuplicateOfInvoice}">
 
</apex:page>

Here my code:

public class CreatInvoiceRecord {

        
        
        public static void createDuplicateOfInvoice(List<Invoice_draft__c> records) {
        
            for(Invoice_draft__c a : records){
        
            RECHNUNGEN_TEST__c rechnung = new RECHNUNGEN_TEST__C();
    
            //Create invoice record with the mapped data from the draft invoice
            rechnung.Name = a.Name;
            rechnung.Zu_zahlen_innerhalb_von_Tagen__c = a.Zu_zahlen_innerhalb_von_Tagen__c;
            rechnung.Account_Invoice__c = a.Account_Invoice__c;
            rechnung.Leistungszeitraum_Start2__c = a.Dateofservice_Start__c;
            rechnung.Leistungszeitraum_Ende2__c  = a.Dateofservice_end__c;
            rechnung.Rechnungsstatus__c = 'Offen';
            insert rechnung; 
         
            //Give a list of child records from the invoice draft
            List<LineItemDraftInvoice__c> lineitemdraftlist = [SELECT Name,Service_good_article__c,Price__c,Numberofunits__c FROM LineItemDraftInvoice__c Where Invoicedraft__c = :a.Id]; //Give me all Positions from theDraft Invoice
            List<Artikel__c> invoicelineitemlist = new List<Artikel__c>();
        
            for(Integer i= 0; i< lineitemdraftlist.size();i++){
        
            
                //Copy the inline items of the draft invoice and create duplicates for the new invoice
                Artikel__c newposition = new Artikel__c();
                newposition.Name = lineitemdraftlist[i].Name;
                newposition.Produkt__c  = lineitemdraftlist[i].Service_good_article__c;
                newposition.Einzelpreis__c = lineitemdraftlist[i].Price__c;
                newposition.Menge__c = lineitemdraftlist[i].Numberofunits__c;
                newposition.Rechnung__c = rechnung.Id;
            
                invoicelineitemlist.add(newposition);
            }
            insert invoicelineitemlist;
            
            }
        
        }
}

 
Best Answer chosen by Bernd Bretzelmann
Narender Singh(Nads)Narender Singh(Nads)
Hi Bernd,
The reason you are getting this error is because your createDuplicateOfInvoice() function in controller class is expecting a list of Invoice_draft__c records.