• Jan Aertgeerts
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 5
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Hi 

I'm currently stuck writing a test class for the following code:
 
global class CreateRecurringInvoice {
  @InvocableMethod(label='Create Recurring Invoice')
  global static List<CreateRecurringInvoiceResult> createInvoices(List<CreateRecurringInvoiceRequest> requests) {
    List<CreateRecurringInvoiceResult> results = new List<CreateRecurringInvoiceResult>();
    for (CreateRecurringInvoiceRequest request : requests) {
      results.add(createInvoices(request));
    }
    return results;
  }

  public static CreateRecurringInvoiceResult createInvoices(CreateRecurringInvoiceRequest request) {
      Factuur__c nieuweFactuur = new Factuur__c();
      Factuur__c oudeFactuur;
      Factuurlijn__c factuurlijn;

      
        List<String> factuurlijnFields = new List<String> (Factuurlijn__c.SObjectType.getDescribe().fields.getMap().keySet());
      
        List<String> factuurFields = new List<String> (Factuur__c.SObjectType.getDescribe().fields.getMap().keySet());
        String soqlParent = '' + 'select ' + String.join(factuurFields, ',') + ', (SELECT ' + String.join(factuurlijnFields, ',') + ' FROM Factuurlijnen__r) from Factuur__c' + ' where id = \'' + request.oldInvoiceId + '\'';
        for (Factuur__c obj: Database.query(soqlParent)) {
            oudeFactuur = obj;
        }

      nieuweFactuur.Name = oudeFactuur.Name;
      nieuweFactuur.Klant__c = oudeFactuur.Klant__c;
      nieuweFactuur.Datum__c = date.today();
      nieuweFactuur.Herhalingstermijn__c = oudeFactuur.Herhalingstermijn__c;
      nieuweFactuur.Recurrente_factuur__c = oudeFactuur.Recurrente_factuur__c;
      nieuweFactuur.Info__c = oudeFactuur.Info__c;
      nieuweFactuur.Referentie__c = oudeFactuur.Referentie__c;
      nieuweFactuur.Project__c = oudeFactuur.Project__c;
      nieuweFactuur.Betalingstermijn__c = oudeFactuur.Betalingstermijn__c;

      insert nieuweFactuur;
      
      String soqlChild = '' + 'select ' + String.join(factuurlijnFields, ',') + ' from Factuurlijn__c' + ' where Factuur__c = \'' + request.oldInvoiceId + '\'';
        for (Factuurlijn__c obj: Database.query(soqlChild)) {
            Factuurlijn__c nieuweFactuurlijn = new Factuurlijn__c();
            nieuweFactuurlijn.Name = obj.Name;
            nieuweFactuurlijn.Factuur__c = nieuweFactuur.Id;
            nieuweFactuurlijn.Aantal__c = obj.Aantal__c;
            nieuweFactuurlijn.Bedrag__c = obj.Bedrag__c;
            nieuweFactuurlijn.BTW__c = obj.BTW__c;
            nieuweFactuurlijn.Info__c = obj.Info__c;
            insert nieuweFactuurlijn;
        }
      
      CreateRecurringInvoiceResult result = new CreateRecurringInvoiceResult();
      return result;
  }

  global class CreateRecurringInvoiceRequest {
    @InvocableVariable(required=true)
    public ID oldInvoiceId;
  }

  global class CreateRecurringInvoiceResult {
    @InvocableVariable
    public ID newInvoiceId;
  }
}

My current test class is like this, but it has 0/0:
@isTest
Private class CreateRecurringInvoiceTest {
    Static testMethod void myUnitTest() {
        Test.StartTest();
        CreateRecurringInvoice cri = new CreateRecurringInvoice();
        CreateRecurringInvoice.CreateRecurringInvoiceRequest request = new CreateRecurringInvoice.CreateRecurringInvoiceRequest();
        CreateRecurringInvoice.CreateRecurringInvoiceResult result = new CreateRecurringInvoice.CreateRecurringInvoiceResult();
        Account acc = new Account(Name = 'Test');
        insert acc;
        Factuur__c oldfact = new Factuur__c(Name = 'Test', Klant__c = acc.Id, Datum__c = date.today());
        insert oldfact;
        request.oldInvoiceId = oldfact.Id;
        Factuur__c newfact = new Factuur__c(Name = 'Test', Klant__c = acc.Id, Datum__c = date.today());
        insert newfact;
        result.newInvoiceId = newfact.Id;
        List<CreateRecurringInvoice.CreateRecurringInvoiceResult> results = new List<CreateRecurringInvoice.CreateRecurringInvoiceResult>();
        List<CreateRecurringInvoice.CreateRecurringInvoiceRequest> requests = new List<CreateRecurringInvoice.CreateRecurringInvoiceRequest>();
        
        
        Test.StopTest();
    }
}

Can someone help me on the way?

Thanks in advance.

Kind regards
Is it possible to show the direct download links (e.g. Attachment 1, Attachment 2) of attachments on a view?
I have an invoice object where the original invoice (pdf) is uploaded. But to make it easier to get an overview it would be useful to have a button/link on the list view of all invoices to get the document directly instead of opening the invoice, clicking on the attachment(s) and click view file for every invoice.

Can someone help me along on how to implement this, or tell me if this is possible?
I'm having trouble accessing the attachments from the object via code.
I have an approval process. When I reach a certain point in this process, I need to make sure certain fields (of the child object) are filled in. I have a roll-up summary of (invoice lines) amounts that should equal the total invoice amount that was filled in in the header information.
So basically: someone shouldn't be allowed to approve something when Total_invoice_lines__c  does not equal Final_Amount__c.

Can someone please advise?
Hello

I was wondering if it is possible to create a copy of the record (with all child-records) to another object when the approval process reaches a certain point.
The case is as following: I have an Invoice object, this invoice has multiple Invoice lines (child). When someone approves the invoice for payment, a copy should be made to the object Invoice_copy (& Invoice_Lines_copy) so that there is a fixed/frozen record of the invoice. This to be certain that it has been booked / paid correctly when approved (so we have proof). 

Is this possible in the way that I describe with a copy to another object, if so - can someone head me in the right direction to create this trigger?

Thanks in advance.

Kind regards
I have an approval process. When I reach a certain point in this process, I need to make sure certain fields (of the child object) are filled in. I have a roll-up summary of (invoice lines) amounts that should equal the total invoice amount that was filled in in the header information.
So basically: someone shouldn't be allowed to approve something when Total_invoice_lines__c  does not equal Final_Amount__c.

Can someone please advise?
Hello

I was wondering if it is possible to create a copy of the record (with all child-records) to another object when the approval process reaches a certain point.
The case is as following: I have an Invoice object, this invoice has multiple Invoice lines (child). When someone approves the invoice for payment, a copy should be made to the object Invoice_copy (& Invoice_Lines_copy) so that there is a fixed/frozen record of the invoice. This to be certain that it has been booked / paid correctly when approved (so we have proof). 

Is this possible in the way that I describe with a copy to another object, if so - can someone head me in the right direction to create this trigger?

Thanks in advance.

Kind regards
Hi 

I'm currently stuck writing a test class for the following code:
 
global class CreateRecurringInvoice {
  @InvocableMethod(label='Create Recurring Invoice')
  global static List<CreateRecurringInvoiceResult> createInvoices(List<CreateRecurringInvoiceRequest> requests) {
    List<CreateRecurringInvoiceResult> results = new List<CreateRecurringInvoiceResult>();
    for (CreateRecurringInvoiceRequest request : requests) {
      results.add(createInvoices(request));
    }
    return results;
  }

  public static CreateRecurringInvoiceResult createInvoices(CreateRecurringInvoiceRequest request) {
      Factuur__c nieuweFactuur = new Factuur__c();
      Factuur__c oudeFactuur;
      Factuurlijn__c factuurlijn;

      
        List<String> factuurlijnFields = new List<String> (Factuurlijn__c.SObjectType.getDescribe().fields.getMap().keySet());
      
        List<String> factuurFields = new List<String> (Factuur__c.SObjectType.getDescribe().fields.getMap().keySet());
        String soqlParent = '' + 'select ' + String.join(factuurFields, ',') + ', (SELECT ' + String.join(factuurlijnFields, ',') + ' FROM Factuurlijnen__r) from Factuur__c' + ' where id = \'' + request.oldInvoiceId + '\'';
        for (Factuur__c obj: Database.query(soqlParent)) {
            oudeFactuur = obj;
        }

      nieuweFactuur.Name = oudeFactuur.Name;
      nieuweFactuur.Klant__c = oudeFactuur.Klant__c;
      nieuweFactuur.Datum__c = date.today();
      nieuweFactuur.Herhalingstermijn__c = oudeFactuur.Herhalingstermijn__c;
      nieuweFactuur.Recurrente_factuur__c = oudeFactuur.Recurrente_factuur__c;
      nieuweFactuur.Info__c = oudeFactuur.Info__c;
      nieuweFactuur.Referentie__c = oudeFactuur.Referentie__c;
      nieuweFactuur.Project__c = oudeFactuur.Project__c;
      nieuweFactuur.Betalingstermijn__c = oudeFactuur.Betalingstermijn__c;

      insert nieuweFactuur;
      
      String soqlChild = '' + 'select ' + String.join(factuurlijnFields, ',') + ' from Factuurlijn__c' + ' where Factuur__c = \'' + request.oldInvoiceId + '\'';
        for (Factuurlijn__c obj: Database.query(soqlChild)) {
            Factuurlijn__c nieuweFactuurlijn = new Factuurlijn__c();
            nieuweFactuurlijn.Name = obj.Name;
            nieuweFactuurlijn.Factuur__c = nieuweFactuur.Id;
            nieuweFactuurlijn.Aantal__c = obj.Aantal__c;
            nieuweFactuurlijn.Bedrag__c = obj.Bedrag__c;
            nieuweFactuurlijn.BTW__c = obj.BTW__c;
            nieuweFactuurlijn.Info__c = obj.Info__c;
            insert nieuweFactuurlijn;
        }
      
      CreateRecurringInvoiceResult result = new CreateRecurringInvoiceResult();
      return result;
  }

  global class CreateRecurringInvoiceRequest {
    @InvocableVariable(required=true)
    public ID oldInvoiceId;
  }

  global class CreateRecurringInvoiceResult {
    @InvocableVariable
    public ID newInvoiceId;
  }
}

My current test class is like this, but it has 0/0:
@isTest
Private class CreateRecurringInvoiceTest {
    Static testMethod void myUnitTest() {
        Test.StartTest();
        CreateRecurringInvoice cri = new CreateRecurringInvoice();
        CreateRecurringInvoice.CreateRecurringInvoiceRequest request = new CreateRecurringInvoice.CreateRecurringInvoiceRequest();
        CreateRecurringInvoice.CreateRecurringInvoiceResult result = new CreateRecurringInvoice.CreateRecurringInvoiceResult();
        Account acc = new Account(Name = 'Test');
        insert acc;
        Factuur__c oldfact = new Factuur__c(Name = 'Test', Klant__c = acc.Id, Datum__c = date.today());
        insert oldfact;
        request.oldInvoiceId = oldfact.Id;
        Factuur__c newfact = new Factuur__c(Name = 'Test', Klant__c = acc.Id, Datum__c = date.today());
        insert newfact;
        result.newInvoiceId = newfact.Id;
        List<CreateRecurringInvoice.CreateRecurringInvoiceResult> results = new List<CreateRecurringInvoice.CreateRecurringInvoiceResult>();
        List<CreateRecurringInvoice.CreateRecurringInvoiceRequest> requests = new List<CreateRecurringInvoice.CreateRecurringInvoiceRequest>();
        
        
        Test.StopTest();
    }
}

Can someone help me on the way?

Thanks in advance.

Kind regards
Hello

I was wondering if it is possible to create a copy of the record (with all child-records) to another object when the approval process reaches a certain point.
The case is as following: I have an Invoice object, this invoice has multiple Invoice lines (child). When someone approves the invoice for payment, a copy should be made to the object Invoice_copy (& Invoice_Lines_copy) so that there is a fixed/frozen record of the invoice. This to be certain that it has been booked / paid correctly when approved (so we have proof). 

Is this possible in the way that I describe with a copy to another object, if so - can someone head me in the right direction to create this trigger?

Thanks in advance.

Kind regards