• Fred B
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Developer

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hello,

I am trying to get more then 75% code coverage for my custom class but dont know why i am getting stucked.

Here is my class :
 
public class CreatePaymentController {
    
    String opportunityId = '';
    public String selectedInvoiceId {get; set;}
    public List<SelectOption> options {get; set;}
    List<Invoice__c> relatedInvoiceList = new List<Invoice__c>();
    
    public CreatePaymentController(){
        
        selectedInvoiceId = '';
        options = new List<SelectOption>();
        opportunityId = Apexpages.Currentpage().getparameters().get('opptyId');
        relatedInvoiceList = [select Id,Name from Invoice__c where Opportunity__c =:opportunityId];
    }
    
    public Pagereference redirectToPaymentDetail(){
        
        Payment__c payment;
        try{
            
            if(relatedInvoiceList <> null && relatedInvoiceList.size() == 1){
                List<Payment__c> paymentList = [Select Id,Name from Payment__c where Invoice__c =:relatedInvoiceList[0].Id];
                if(paymentList <> null && paymentList.size() > 0){
                    payment = new Payment__c(Id=paymentList[0].Id);
                }
                else{
                    payment = new Payment__c();
                    payment.Invoice__c = relatedInvoiceList[0].Id;
                    upsert payment;
                }
                Payment__c pay = [select Id, Name From Payment__c WHERE Id =:payment.Id];
                PageReference newPaymentDetailPage = new PageReference('/a08/e?CF00N2400000FhfdZ='+pay.Name+'&CF00N2400000FhfdZ_lkid='+pay.Id+'&saveURL=/'+opportunityId);
                newPaymentDetailPage.setRedirect(true);
                return newPaymentDetailPage;
            }
            else if(relatedInvoiceList <> null && relatedInvoiceList.size() > 1){
                
                for (Invoice__c inv : relatedInvoiceList) {
                    
                    options.add(new SelectOption(inv.Id, inv.Name));
                }
                system.debug('@@options : '+ options);
            }
        } catch(Exception ex){
            system.debug('@@ex : '+ ex.getMessage());
        }
        return null;
    }
    
    public PageReference paymentPage(){
        try{
            if(!String.isBlank(selectedInvoiceId)){
                Payment__c payment =  new Payment__c();
                payment.Invoice__c = selectedInvoiceId;
                insert payment;
                Payment__c pay = [select Id, Name From Payment__c WHERE Id =:payment.Id];
                PageReference newPaymentDetailPage = new PageReference('/a08/e?CF00N2400000FhfdZ='+pay.Name+'&CF00N2400000FhfdZ_lkid='+pay.Id+'&saveURL=/'+opportunityId);
                newPaymentDetailPage.setRedirect(true);
                return newPaymentDetailPage;
            }
        } catch(Exception ex){
            system.debug('@@ex : '+ ex.getMessage());
        }
        return null;
    }
}

Here is Test Class :
 
@isTest(SeeAllData=true)
public class CreatePaymentControllerTest{

    static testMethod void MyTest(){
        
        Account a = new Account();        
        a.Name = 'test';
        a.Email__c = 'test@test.com';
        a.CurrencyIsoCode = 'EUR';
        a.Phone = '789642';
        a.BillingCity= 'bhuj';
        a.BillingPostalCode = '370001';
        a.BillingCountry = 'india';
        a.BillingLatitude = 57.5 ;
        a.BillingLongitude = 67.7;
        a.BillingState = 'Gujarat';
        a.BillingStreet = 'Main';
        insert a;
         
        Opportunity opp = new Opportunity();
        opp.Name = 'Test Opportunity';
        opp.StageName = 'Stage 0';
        opp.CloseDate = system.today().addDays(10);
        opp.Accountid = a.id;
        opp.CurrencyIsoCode = 'GBP';
        insert opp;
        
        Invoice__c inv = new Invoice__c();
        inv.Account_Name__c = a.id;
        inv.Opportunity__c = opp.id;
        inv.CurrencyIsoCode = 'GBP';
        insert inv;
        
        Payment__c pm = new Payment__c();
        pm.Invoice__c = inv.id;
        pm.CurrencyIsoCode = 'GBP';
        insert pm;
        
        Payment__c pm1 = new Payment__c();
        pm1.Invoice__c = inv.id;
        pm1.CurrencyIsoCode = 'GBP';
        insert pm1;
        
        PageReference pageRef = new Pagereference('/a08/e?CF00N2400000FhfdZ=pm.Name&CF00N2400000FhfdZ_lkid=pm.Id&saveURL=/opp.Id');
        Test.setCurrentPage(pageRef);

        CreatePaymentController cnt = new CreatePaymentController();
        
        cnt.paymentPage();
        
        Apexpages.currentPage().getParameters().put('id',opp.Id); 
        
        cnt.redirectToPaymentDetail();
    
    }
}

Thanks in Advance..
Hi,
I have a trigger and a class which implements a queueable interface.
When a record gets created the trigger invokes the queueable interface which will make a callout.

Now I'm writing the test class for the same.
In the test class I'm setting the mock response using httpMockCallout and inserting the record.
But I'm getting an exception, Callout loop not allowed.
Any Idea why this is happening?

As a workaround I set the response using test.Isrunningtest and it works fine.

Any pointers would be helpful.
Many Thanks

One can access an Organization's Default Time Zone follow through the following:

 

Administration Setup->Company Profile->Company Information->Default Time Zone

 

However, I cannot find it listed anywhere in the SOQL Explorer (actually I'm browsing through the Force.com IDE) .

 

How can I get this information in an APEX class?