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
Michael MMichael M 

Help with test code for basic invocable class

Hello, would someone be able to show me how to write test code for this class of mine: 

public with sharing class FetchCurrentURL {

 public class VisitorUrlOutput {
    @InvocableVariable(required=false)
    public String urlOfMostRecentPage;
  }

 @InvocableMethod(label='Get Current URL' description='Returns Current URL')
 public static List<String> getcurrentURL() {
   System.debug(URL.getSalesforceBaseUrl().toExternalForm());
   return new List<String>{URL.getSalesforceBaseUrl().toExternalForm()};
   }
 }
Best Answer chosen by Michael M
Sowjanya Hegde 13Sowjanya Hegde 13
Hi Michael,

@isTest
public class FetchCurrentURLTest {
    static testMethod void myUnitTest(){
        FetchCurrentURL.getcurrentURL();
    }
}

This will give you 100% coverage for FetchCurrentURL class.

All Answers

Sowjanya Hegde 13Sowjanya Hegde 13
Hi Michael,

@isTest
public class FetchCurrentURLTest {
    static testMethod void myUnitTest(){
        FetchCurrentURL.getcurrentURL();
    }
}

This will give you 100% coverage for FetchCurrentURL class.
This was selected as the best answer
Michael MMichael M
Fantastic- thank you!!