• linda b
  • NEWBIE
  • 25 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies

Hello everybody,

I have a question for you regarding implementing a certain use-case our company is looking into.

Currently, our sales department uses Opportunities when doing the negotiation process with the Customer.

However, we are thinking of switching to the Contract standard object, and are wondering, how to implement a certain behavior in Salesforce:

Currently all of our products are booked for a certain amount of time, and they have a quantity of how many pieces have been booked/used. What we want to implement however, is per default within our application we give the customer to create a possibility to create an unlimited contract (price is taken from price book entries without any discounts), so he gets booked/invoiced every time he buys one of our products from this contract. My question is, what is the most preferable way to implement this kind of logic in Salesforce? Any help would be deeply appreciated.

 

 

 

 

  • September 12, 2018
  • Like
  • 0

Hello, I have this Apex class:


User-added image
and i am missing coverage for the creation of the case object, this is what I have so far, but i am still only at 53% for some reason:

@isTest
private class CaseGenerator_Test{
    static testmethod void testSchduler() 
    {
        Contract__c ctr = new Contract__c();
        ctr.Jamba_Company__c = '0010Y00001YriCE';
        ctr.Price_per_job_posting__c = 800.00;
        if(ctr.Invoice_Type__c != null){
           ctr.Invoice_Type__c = 'Per Unit';
        }
        insert ctr;
        Billing_Unit__c billingUnit = new Billing_Unit__c();
        billingUnit.Contract__c = ctr.Id;
        billingUnit.Invoicing_Date__c = Date.today();
        billingUnit.Name = 'Test BU1';
        insert billingUnit;
        
        Case cse = new Case(
        subject='Rechnung erstellen: '+billingUnit.Name,
        Contract__c=billingUnit.Contract__c,
        Automatically_generated__c=TRUE,
        Billing_Unit__c=billingUnit.Id,
        Status='New');
        insert cse; 
        
        String CRON_EXP = '0 0 0 15 3 ? *';
        Test.startTest();
        String jobId = System.schedule('CaseGenerator',  CRON_EXP, new CaseGenerator());
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
        System.assertEquals(CRON_EXP, ct.CronExpression);
        System.assertEquals(0, ct.TimesTriggered);
        Test.stopTest();
    }
}

Hello, can someone please help me write a test for this class?

global class CaseGenerator implements Schedulable {
    global void execute(SchedulableContext ctx) {
        createInvoiceCase();
    }
    public void createInvoiceCase() {
        List<Case> newCaseList = new List<Case>();
        List<Billing_Unit__c> invoiceCases = [SELECT Id, Contract__c, Name
                                             FROM Billing_Unit__c
                                             WHERE Invoicing_Date__c = TODAY AND
                                             Unlimited__c = TRUE];
        if(invoiceCases != null){
            for(Billing_Unit__c bgut : invoiceCases){
                Case cseobj = new Case(
                    subject='Rechnung erstellen: '+bgut.Name,
                    Contract__c=bgut.Contract__c,
                    Automatically_generated__c=TRUE,
                    Billing_Unit__c=bgut.Id,
                    Status='New');
                 newCaseList.add(cseobj);
            }
            insert newCaseList;
        }
    }
}


This is what I have so far, but I do not think I am going in the right direction:

public class CaseGeneratorTest{
    public static String CRON_EXP '0 0 6 * * *';
    static testMethod void testScheduledJob(){
        List<Case> newCaseList = new List<Case>();
        Test.startTest();
                    invoiceCasesListTest invcs = new List<Case>
                    invcs.Invoicing_date__c = TODAY,
                    invcs.Unlimited__c = TRUE;


...

I would like to write a scheduled Apex class which checks for certain conditions on a custom object, and if they are true, create a case on the master-detail parent object, here is my code so far:

global class CaseGenerator implements Schedulable {
	global void execute(SchedulableContext ctx) {
        createInvoiceCase();
	}
    public void createInvoiceCase() {
     List<Billing_Unit__c> invoiceCases = new List<Billing_Unit__c>();
     invoiceCases = [SELECT Id, Contract__r.Id
                                  FROM Billing_Unit__c
                                  WHERE Invoicing_Date__c = TODAY AND
                                  Unlimited__c = TRUE];
    for(Billing_Unit__c bgut : invoiceCases) {
        // create case related to Contract__r.id here
       Case cseobj = new Case (subject= 'Rechnung erstellen'; Contract__c=Contract__r) (???)
    }
    update invoiceCases;
    }
}
I don't know how to create the case on the parent object in the for loop, any help/tips would be greatly appreciated! :)

Hello everybody,

I have a question for you regarding implementing a certain use-case our company is looking into.

Currently, our sales department uses Opportunities when doing the negotiation process with the Customer.

However, we are thinking of switching to the Contract standard object, and are wondering, how to implement a certain behavior in Salesforce:

Currently all of our products are booked for a certain amount of time, and they have a quantity of how many pieces have been booked/used. What we want to implement however, is per default within our application we give the customer to create a possibility to create an unlimited contract (price is taken from price book entries without any discounts), so he gets booked/invoiced every time he buys one of our products from this contract. My question is, what is the most preferable way to implement this kind of logic in Salesforce? Any help would be deeply appreciated.

 

 

 

 

  • September 12, 2018
  • Like
  • 0

I would like to write a scheduled Apex class which checks for certain conditions on a custom object, and if they are true, create a case on the master-detail parent object, here is my code so far:

global class CaseGenerator implements Schedulable {
	global void execute(SchedulableContext ctx) {
        createInvoiceCase();
	}
    public void createInvoiceCase() {
     List<Billing_Unit__c> invoiceCases = new List<Billing_Unit__c>();
     invoiceCases = [SELECT Id, Contract__r.Id
                                  FROM Billing_Unit__c
                                  WHERE Invoicing_Date__c = TODAY AND
                                  Unlimited__c = TRUE];
    for(Billing_Unit__c bgut : invoiceCases) {
        // create case related to Contract__r.id here
       Case cseobj = new Case (subject= 'Rechnung erstellen'; Contract__c=Contract__r) (???)
    }
    update invoiceCases;
    }
}
I don't know how to create the case on the parent object in the for loop, any help/tips would be greatly appreciated! :)