---
schema_version: "1"
id: 62d15af0de105c19a1289a810e3bbf0b62e1f7c9c65d2c82fcfae99ccdc14296
title: TaxEngineContext Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_commercetax_TaxEngineContext.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercetax_TaxEngineContext.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 39c109afd5d907d635d63e0c354a4a98b6325cb779db374f02ed3a98f9348793
description: Wrapper class that stores details about the type of a tax calculation request.Learn more about the available constructors with the TaxEngineContext class.Initializes the TaxEngineContext object. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.Learn more about the available methods with the TaxEngineContext class.Retrieves the value of the NamedUri field of the TaxEngineContext class.Gets the value of the TaxEngineContext's Request field.Gets the value of the RequestType field of the TaxEngineContext class.
---
# TaxEngineContext Class

Wrapper class that stores details about the type of a tax calculation request.

## Namespace

[CommerceTax](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_commercetax.htm "Manage the communication between Salesforce and an external tax engine.")

## Example

At the beginning of a tax adapter, use TaxEngineContext class to pass the value of a request type to an instance of RequestType.

global virtual class MockAdapter implements commercetax.TaxEngineAdapter {
 
     global commercetax.TaxEngineResponse processRequest(commercetax.TaxEngineContext taxEngineContext) {
         commercetax.RequestType requestType = taxEngineContext.getRequestType();
         commercetax.CalculateTaxRequest request = (commercetax.CalculateTaxRequest)taxEngineContext.getRequest();

Build the rest of your adapter based on the type of request that you got from TaxEngineContext class.

if(requestType == commercetax.RequestType.CalculateTax){
             commercetax.calculatetaxtype type = request.taxtype;
             String docCode='';
             if(request.DocumentCode == 'simulateEmptyDocumentCode')
                 docCode = '';
             else if(request.DocumentCode != null)
                 docCode =request.DocumentCode;
             else if(request.ReferenceEntityId != null) docCode = request.ReferenceEntityId;
             else docCode =  String.valueOf(getRandomInteger(0,2147483647));
             commercetax.CalculateTaxResponse response = new commercetax.CalculateTaxResponse();
             if(request.isCommit == true) {
                 response.setStatus(commercetax.TaxTransactionStatus.Committed);
             } else {
                 response.setStatus(commercetax.TaxTransactionStatus.Uncommitted);
             }
}

- **[TaxEngineContext Constructors](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercetax_TaxEngineContext.htm#apex_commercetax_TaxEngineContext_constructors)**  
    Learn more about the available constructors with the TaxEngineContext class.
- **[TaxEngineContext Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercetax_TaxEngineContext.htm#apex_commercetax_TaxEngineContext_methods)**  
    Learn more about the available methods with the TaxEngineContext class.

## TaxEngineContext Constructors

Learn more about the available constructors with the TaxEngineContext class.

The TaxEngineContext class includes these constructors.

- **[TaxEngineContext(request, requestType, namedUri)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercetax_TaxEngineContext.htm#apex_commercetax_TaxEngineContext_ctor)**  
    Initializes the TaxEngineContext object. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.

### TaxEngineContext(request, requestType, namedUri)

Initializes the TaxEngineContext object. This constructor is intended for test usage and throws an exception if used outside of the Apex test context.

#### Signature

TaxEngineContext(commercetax.TaxEngineRequest request, commercetax.RequestType requestType, String namedUri)

#### Parameters

- **request**:
    
    Type: TaxEngineRequest Information about
    
    the request.
- **requestType**:
    
    Type: [RequestType](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_commercetax_RequestType.htm "Shows the type of tax request made to the tax engine.")
    
    Whether the tax request is to calculate or estimate tax.
- **namedUri**:
    
    Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")
    
    URI that was called as part of the tax calculation request.

## TaxEngineContext Methods

Learn more about the available methods with the TaxEngineContext class.

The TaxEngineContext class includes these methods.

- **[getNamedUri()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercetax_TaxEngineContext.htm#apex_commercetax_TaxEngineContext_getNamedUri)**  
    Retrieves the value of the NamedUri field of the TaxEngineContext class.
- **[getRequest()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercetax_TaxEngineContext.htm#apex_commercetax_TaxEngineContext_getRequest)**  
    Gets the value of the TaxEngineContext's Request field.
- **[getRequestType()](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercetax_TaxEngineContext.htm#apex_commercetax_TaxEngineContext_getRequestType)**  
    Gets the value of the RequestType field of the TaxEngineContext class.

### getNamedUri()

Retrieves the value of the NamedUri field of the TaxEngineContext class.

#### Signature

global String getNamedUri()

#### Return Value

Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.")

### getRequest()

Gets the value of the TaxEngineContext's Request field.

#### Signature

global commercetax.TaxEngineRequest getRequest()

#### Return Value

Type: TaxEngineRequest

An implemented instance of an external tax engine's interface for processing requests. We've provided the TaxEngineRequest interface for you to test within mock adapters with classes that implement it, such as [CalculateTaxRequest](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_commercetax_CalculateTaxRequest.htm#apex_class_commercetax_CalculateTaxRequest "Represents a request to an external tax engine to calculate tax. Extends the TaxTransactionRequest class and is the top-level request class."). However, don’t use it outside of a testing context.

### getRequestType()

Gets the value of the RequestType field of the TaxEngineContext class.

#### Signature

global commercetax.RequestType getRequestType()

#### Return Value

Type: [RequestType](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_commercetax_RequestType.htm "Shows the type of tax request made to the tax engine.")

Indicates whether the calculation request was for actual or calculated tax.