• 留学情報館
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I have an APEX class that ends with a finishURL method; this class is the controller-extension of a VF page.
What they all do is to collect the IDs of the selected items on a related list view, then pass them into a screen flow, and return back to the start point(list view in our case) when the flow is finished.
I am a total noob at writing code and did not have any test class for this controller at first, therefore when I tried to deploy this code into the production, I got an error on the overall code coverage.

So, I tried to write a test class but this time since I was unable to cover the finishURL code I got an error while deploying it.
 
Can you please help me with my code and test class so that I can deploy these codes into the production?

My VF page;
```
<apex:page standardController="OnList__c" recordSetVar="OnlistItem" extensions="NGController" tabstyle="OnList__c" lightningStylesheets="true">
    <apex:outputPanel >
        <p>{!finishURL}</p>
    </apex:outputPanel>
    
    <flow:interview name="NGFlow" finishLocation="{!URLFOR(finishURL)}">
    
        <apex:param name="NGRecordIDs" value="{!SelectedOnlistIDs}" />
    </flow:interview>
    
</apex:page>

```

My Controller;
```
public class  NGController {
    
    public String[] SelectedOnlistIDs{get;set;}
    public String finishURL{get;set;}

    
    public NGController(ApexPages.StandardSetController listcontroller){
        SelectedOnlistIDs = new string[]{};
        for(OnList__c OnlistItem : (OnList__c[])listcontroller.getSelected()){
            SelectedOnlistIDs.add(OnlistItem.Id);
        }
        finishURL = ApexPages.currentPage().getParameters().get('myparameter').substringBefore('#');
    }
}

```

The templated Test Class I tried to write; 
```
@isTest 
public class NGControllerTest 
{
 static testMethod void OnlistDataTest() 
 {
 List <OnList__c> OnlistTestList = new List<OnList__c>();
 
 OnList__c OnlistTestRecord = new OnList__c();
 OnlistTestRecord.NGReason__c='Test Onlist' ;
 OnlistTestList.add(OnlistTestRecord);
 OnList__c OnlistTestRecord1 = new OnList__c();
 OnlistTestRecord1.NGReason__c='Test Onlist1' ;
 OnlistTestList.add(OnlistTestRecord1);

 insert  OnlistTestList;
 
 Test.startTest();
  Test.setCurrentPage(Page.NGPage);
  ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(OnlistTestList);
  stdSetController.setSelected(OnlistTestList);
  NGController ext = new NGController(stdSetController);
 Test.stopTest();
 }
}

```

Here is the error I get when I run this test and also try to deploy these test classes;

```
System.NullPointerException: Attempt to de-reference a null object
Class.NGController.<init>: line 12, column 1
Class.NGControllerTest.OnlistDataTest: line 21, column 1
```

I just would love to get some direction on this and would appreciate any kind of help asap TT
 
I have an APEX class that ends with a finishURL method; this class is the controller-extension of a VF page.
What they all do is to collect the IDs of the selected items on a related list view, then pass them into a screen flow, and return back to the start point(list view in our case) when the flow is finished.
I am a total noob at writing code and did not have any test class for this controller at first, therefore when I tried to deploy this code into the production, I got an error on the overall code coverage.

So, I tried to write a test class but this time since I was unable to cover the finishURL code I got an error while deploying it.
 
Can you please help me with my code and test class so that I can deploy these codes into the production?

My VF page;
```
<apex:page standardController="OnList__c" recordSetVar="OnlistItem" extensions="NGController" tabstyle="OnList__c" lightningStylesheets="true">
    <apex:outputPanel >
        <p>{!finishURL}</p>
    </apex:outputPanel>
    
    <flow:interview name="NGFlow" finishLocation="{!URLFOR(finishURL)}">
    
        <apex:param name="NGRecordIDs" value="{!SelectedOnlistIDs}" />
    </flow:interview>
    
</apex:page>

```

My Controller;
```
public class  NGController {
    
    public String[] SelectedOnlistIDs{get;set;}
    public String finishURL{get;set;}

    
    public NGController(ApexPages.StandardSetController listcontroller){
        SelectedOnlistIDs = new string[]{};
        for(OnList__c OnlistItem : (OnList__c[])listcontroller.getSelected()){
            SelectedOnlistIDs.add(OnlistItem.Id);
        }
        finishURL = ApexPages.currentPage().getParameters().get('myparameter').substringBefore('#');
    }
}

```

The templated Test Class I tried to write; 
```
@isTest 
public class NGControllerTest 
{
 static testMethod void OnlistDataTest() 
 {
 List <OnList__c> OnlistTestList = new List<OnList__c>();
 
 OnList__c OnlistTestRecord = new OnList__c();
 OnlistTestRecord.NGReason__c='Test Onlist' ;
 OnlistTestList.add(OnlistTestRecord);
 OnList__c OnlistTestRecord1 = new OnList__c();
 OnlistTestRecord1.NGReason__c='Test Onlist1' ;
 OnlistTestList.add(OnlistTestRecord1);

 insert  OnlistTestList;
 
 Test.startTest();
  Test.setCurrentPage(Page.NGPage);
  ApexPages.StandardSetController stdSetController = new ApexPages.StandardSetController(OnlistTestList);
  stdSetController.setSelected(OnlistTestList);
  NGController ext = new NGController(stdSetController);
 Test.stopTest();
 }
}

```

Here is the error I get when I run this test and also try to deploy these test classes;

```
System.NullPointerException: Attempt to de-reference a null object
Class.NGController.<init>: line 12, column 1
Class.NGControllerTest.OnlistDataTest: line 21, column 1
```

I just would love to get some direction on this and would appreciate any kind of help asap TT