Tag Archive for: invoicing

From Indrajeet Sengupta: Example to implement e-invoicing with Revenue Cloud

So for the sake of clarity, we will use an example for Vertex Netherlands to comply with E-Invoicing

Let’s prepare the org. 

The first thing that we do is create fields on the Invoice level to get the org ready. 

Help article showing how to create custom fields in Salesforce: https://help.salesforce.com/s/articleView?language=en_US&id=platform.adding_fields.htm&type=5 

Here are the fields that we will create on the Invoice Object:

  1. E-Invoicing Status:
    1. Pending: The invoice has been created but is not yet ready for submission.(Draft Status of Invoice)
    2. Canceled: DRAFT invoice not used, so canceled it.
    3. Ready for E-Invoicing: The invoice has been finalized and is ready to be sent to the network. This status will be our trigger.
    4. Sent to Network: The middleware has successfully sent the invoice data.
    5. Acknowledged by Network: The network has received the invoice and confirmed its validity.
    6. Approved: The invoice has been approved by the tax authority (for clearance models).
    7. Rejected: The invoice was rejected by the network due to errors.
    8. Correction Needed: Data needs correction.
    9. Correction Addressed: Correction has been made and can be resent for Approval.
    10. Error: The integration process failed.
    11. Exempt: Invoice is exempted from E-Invoicing Process.
    12. Voided invoice 
  2. Document Number
  3. Idempotency Key 
  4. Document ID
  5. Issue Date
  6. Transmission DateTime

Assuming these fields to be present:

  1. VAT ID: Account Object
  2. PEEPOL ID: Account Object
  3. Company ID: Account Object

Now that we have the relevant fields we want to capture for Netherlands, we will move to the next step

Create Invoice Event

This event is a lightweight message containing key identifiers, like the InvoiceId and AccountId.

  1. Go to Setup > Integrations > Platform Events.
  2. Click New Platform Event.
  3. Name it something clear, like Invoice Posted Event.
  4. Add a custom field to carry the necessary information. The most important one is Invoice ID (Text). You can also add Account ID.

Create Trigger for the Event

  1. Go to Setup > Process Automation > Flows.
  2. Click New Flow and select Record-Triggered Flow.
  3. Configure the Trigger:
    • Object: Invoice
    • Trigger the Flow When: A record is updated
    • Set Entry Conditions:
      • Status Is Changed True
      • Status Equals Posted
    • Optimize the Flow for: Actions and Related Records

Upon firing, the trigger doesn’t call the middleware directly. Instead, it publishes a Custom Platform Event within Salesforce which can be read by the middleware or Mulesoft. This decouples Salesforce from the middleware, making the system more robust and scalable.

  1. Click the + icon on the path.
  2. Select the Create Records element.
  3. Configure the Element:
    • How Many Records to Create: One
    • How to Set the Record Fields: Use separate resources, and literal values
    • Object: Select your new Platform Event, Invoice Posted Event.
    • Set Field Values: Map the fields you created on your event.
      • Invoice ID (your event field) Equals $Record > Id (the ID of the invoice that triggered the flow).
  4. Save and Activate

Save your flow and activate it. That’s it!

You org is now generating a salesforce event whenever an Invoice is posted. All we now need is a middleware to read this message and consume it.

Consume Salesforce Event

import queue
import threading
import time
from salesforce_streaming import SalesforceStreamingClient

# --- Configuration (Same as before) ---
SF_USERNAME = "your.name@example.com"
SF_PASSWORD = "your_password"
SF_SECURITY_TOKEN = "your_security_token"
IS_SANDBOX = False
CONSUMER_KEY = "YOUR_CONNECTED_APP_CONSUMER_KEY"
CONSUMER_SECRET = "YOUR_CONNECTED_APP_CONSUMER_SECRET"
EVENT_API_NAME = "My_Custom_Event__e"

# 1. Create a thread-safe queue to hold incoming event payloads
event_queue = queue.Queue()

# 2. Modify the callback to put messages into the queue
def queueing_callback(message):
    """Callback to add the event payload to a processing queue."""
    print("🚀 New event received by listener...")
    event_payload = message.get('payload', {})
    event_queue.put(event_payload) # <-- Put the payload into the queue


def process_events_from_queue():
    """
    This is the 'worker' function.
    It runs in a separate thread and processes payloads from the queue.
    """
    print("✅ Worker thread started. Waiting for events...")
    while True:
        try:
            # The .get() method will wait here until an item is in the queue
            payload = event_queue.get(block=True)
            
            print("\n--- Worker picked up an event for processing ---")
            print(f"   Payload: {payload}")
            
            # --- THIS IS WHERE YOU ADD YOUR PROCESSING LOGIC ---
            # For example, get a specific field and call another system.
            invoice_id = payload.get('Invoice_ID__c')
            if invoice_id:
                print(f"   Action: Calling another API for Invoice ID: {invoice_id}")
                # e.g., result = composite_api_call(invoice_id)
            
            # Simulate work being done
            time.sleep(2)
            print("--- Finished processing event ---\n")

        except Exception as e:
            print(f"Error in worker thread: {e}")


# --- Main script logic ---

if __name__ == "__main__":
    # 3. Start the worker thread
    # The 'daemon=True' means the thread will exit when the main script exits.
    worker_thread = threading.Thread(target=process_events_from_queue, daemon=True)
    worker_thread.start()

    # Initialize and subscribe the Salesforce client
    client = SalesforceStreamingClient(
        consumer_key=CONSUMER_KEY,
        consumer_secret=CONSUMER_SECRET,
        username=SF_USERNAME,
        password=SF_PASSWORD + SF_SECURITY_TOKEN,
        sandbox=IS_SANDBOX
    )
    
    channel = f"/event/{EVENT_API_NAME}"
    print(f"Listener subscribing to channel: {channel}")
    client.subscribe(channel, queueing_callback)

    # Start listening
    print("Listener connected. Press Ctrl+C to stop.")
    try:
        client.connect()
    except KeyboardInterrupt:
        print("Script terminated gracefully.")
        client.disconnect()

Extract Invoice and associated details using the event message

From the event, we can extract the Invoice ID and use it to call a composite API in Salesforce org to receive the details of the invoice. Note: You can modify the request body to add/remove more fields and objects as needed.

Here is an example of Composite API Call Request Body:

POST: /services/data/v64.0/composite

{
  "allOrNone": false,
  "compositeRequest": [
    {
      "method": "GET",
      "url": "/services/data/v62.0/sobjects/Invoice/3ttSG000000Q0SbYAK",
      "referenceId": "Invoice"
    },
    {
      "method": "GET",
      "url": "/services/data/v62.0/query?q=SELECT+Id,Name,InvoiceId,ChargeAmount,Quantity,UnitPrice,LegalEntityId+FROM+InvoiceLine+WHERE+InvoiceId='3ttSG000000Q0SbYAK'",
      "referenceId": "InvoiceLines"
    },
    {
      "method": "GET",
      "url": "/services/data/v62.0/query?q=SELECT+Id,TaxName,InvoiceLineId,TaxAmount,TaxCode+FROM+InvoiceLineTax+WHERE+InvoiceLineId+IN+(SELECT+Id+FROM+InvoiceLine+WHERE+InvoiceId='3ttSG000000Q0SbYAK')",
      "referenceId": "InvoiceLineTaxes"
    },
    {
      "method": "GET",
      "url": "/services/data/v62.0/query?q=SELECT+Id,Name,BillingStreet,BillingCity,BillingPostalCode,BillingCountry+FROM+Account+WHERE+Id+IN+(SELECT+BillingAccountId+FROM+Invoice+WHERE+Id='3ttSG000000Q0SbYAK')",
      "referenceId": "Account"
    },
    {
      "method": "GET",
      "url": "/services/data/v62.0/query?q=SELECT+Id,FirstName,LastName,Email,Phone+FROM+Contact+WHERE+Id+IN+(SELECT+BillToContactId+FROM+Invoice+WHERE+Id='3ttSG000000Q0SbYAK')",
      "referenceId": "Contact"
    },
    {
      "method": "GET",
      "url": "/services/data/v62.0/query?q=SELECT+Id,Name,CompanyName,LegalEntityCity,LegalEntityAddress,LegalEntityCountry,Status+FROM+LegalEntity+WHERE+Id+IN+(SELECT+LegalEntityId+FROM+InvoiceLine+WHERE+InvoiceId='3ttSG000000Q0SbYAK')",
      "referenceId": "LegalEntity"
    }
  ]
}

 Note: Please add and remove more fields/objects in the request as necessary.

Transform the request for Vertex Netherlands

Here is an example of Netherlands request for Vertex:

Here is an example request for Netherlands Invoice Request. https://developer.vertexinc.com/einvoicing/docs/netherlands-examples

Here is an explanation of the fields needed in the Netherlands Invoice Request

XML Path (Key)Description / PurposeSalesforce Availability
Routing & Header
RoutingDetails > SenderThe sender’s VAT registration number.Yes
RoutingDetails > ReceiverA static code telling Vertex the target format (e.g., Netherlands PEPPOL).In Middleware
CustomizationIDA Vertex-specific ID for the billing specification. Static Value: urn:vertexinc:vrbl:billing:1Static Value: urn:vertexinc:vrbl:billing:1
ProfileIDA Vertex-specific ID for the business process profile. Static Value: urn:vertexinc:vrbl:billing:1.0Static Value: urn:vertexinc:vrbl:billing:1.0
IDYour unique invoice number.Yes
IssueDateThe date the invoice was created.Yes
IssueTimeThe time the invoice was created.Yes
DueDateThe date payment is due.Yes
InvoiceTypeCodeThe standard code for the document type (e.g., 380 for an invoice).In Middleware: 380-Invoice , 381-Credit Note
NoteA general, free-text note for the entire invoice.Yes
DocumentCurrencyCodeThe three-letter ISO currency code (e.g., EUR).Yes
BuyerReferenceA reference number from the buyer (e.g., a contact person or department code).Yes
InvoicePeriod > StartDateThe start date of the service or billing period.Yes
InvoicePeriod > EndDateThe end date of the service or billing period.Yes
InvoicePeriod > DescriptionA text description of the billing period (e.g., “Monthly”).Yes
OrderReference > IDThe buyer’s Purchase Order (PO) Number.Yes
OrderReference > SalesOrderIDThe seller’s internal sales order number.Yes
DespatchDocumentReference > IDThe reference number for the despatch or delivery note.Yes
Supplier (Your Company) Details
AccountingSupplierParty > EndpointIDYour company’s PEPPOL ID for electronic routing.Company Specific, in Middleware
AccountingSupplierParty > PartyIdentification > IDYour company’s identifier (often the VAT number).Yes
AccountingSupplierParty > PartyName > NameYour company’s common trading name.Yes
AccountingSupplierParty > PostalAddress > StreetNameYour company’s street address.Yes
AccountingSupplierParty > PostalAddress > CityNameYour company’s city.Yes
AccountingSupplierParty > PostalAddress > PostalZoneYour company’s postal code.Yes
AccountingSupplierParty > PostalAddress > Country > IdentificationCodeYour company’s two-letter country code (e.g., NL).Yes
AccountingSupplierParty > PartyTaxScheme > CompanyIDYour company’s VAT registration number.Yes
AccountingSupplierParty > PartyLegalEntity > RegistrationNameYour company’s full, official registered name.Yes
AccountingSupplierParty > PartyLegalEntity > CompanyIDYour company’s official registration number (e.g., Chamber of Commerce).Yes
AccountingSupplierParty > Contact > NameThe name of a contact person or department at your company.Yes
Customer (Buyer) Details
AccountingCustomerParty > EndpointIDThe customer’s PEPPOL ID for electronic routing.Custom Field on Account Object
AccountingCustomerParty > PartyName > NameThe customer’s company name.Yes
AccountingCustomerParty > PostalAddress > StreetNameThe customer’s street address.Yes
AccountingCustomerParty > PostalAddress > CityNameThe customer’s city.Yes
AccountingCustomerParty > PostalAddress > PostalZoneThe customer’s postal code.Yes
AccountingCustomerParty > PostalAddress > Country > IdentificationCodeThe customer’s two-letter country code.Yes
AccountingCustomerParty > PartyTaxScheme > CompanyIDThe customer’s VAT registration number.Yes
AccountingCustomerParty > PartyLegalEntity > RegistrationNameThe customer’s full, official registered name.Yes
AccountingCustomerParty > PartyLegalEntity > CompanyIDThe customer’s official registration number.Yes
AccountingCustomerParty > Contact > TelephoneThe customer’s telephone number.Yes
AccountingCustomerParty > Contact > ElectronicMailThe customer’s email address.Yes
Delivery & Payment
Delivery > ActualDeliveryDateThe actual date goods were delivered or services were completed.Order Start Date
Delivery > DeliveryLocation > Address > StreetNameThe street address of the delivery location.Yes
Delivery > DeliveryLocation > Address > CityNameThe city of the delivery location.Yes
Delivery > DeliveryParty > PartyName > NameThe name of the party receiving the delivery.Yes
PaymentMeans > PaymentMeansCodeA standard code for the payment method.https://developer.vertexinc.com/einvoicing/docs/netherlands-payment-means
PaymentMeans > PayeeFinancialAccount > IDYour bank account number (IBAN) for payment.Middleware or Custom Object in Salesforce
PaymentMeans > PayeeFinancialAccount > NameThe name of the bank account owner.Middleware or Custom Object in Salesforce
PaymentMeans > PayeeFinancialAccount > FinancialInstitutionBranch > IDYour bank’s identifier code (BIC/SWIFT).Middleware or Custom Object in Salesforce
PaymentTerms > NoteA text note describing the payment terms.Middleware or Custom Object in Salesforce
Invoice Line Items
InvoiceLine > IDThe unique identifier for the invoice line (line number).Yes
InvoiceLine > NoteA free-text description for the line item.Yes
InvoiceLine > InvoicedQuantityThe quantity of the item sold.Yes
InvoiceLine > LineExtensionAmountThe total amount for the line (Quantity x Price), excluding tax.Yes
InvoiceLine > OrderLineReference > LineIDThe corresponding line number from the original purchase order.Yes
InvoiceLine > Item > NameThe name of the product or service.Yes
InvoiceLine > Item > SellersItemIdentification > IDYour internal product code or SKU.Yes
InvoiceLine > Item > StandardItemIdentification > IDA standard product identifier like a GTIN or EAN code.Custom Field on Object
InvoiceLine > Item > ClassifiedTaxCategory > IDA standard code for the tax category (e.g., ‘S’ for standard rate).https://developer.vertexinc.com/einvoicing/docs/classifiedtaxcategory
InvoiceLine > Item > ClassifiedTaxCategory > PercentThe tax rate percentage applicable to this item.Calculated in Middleware
InvoiceLine > Item > AdditionalItemProperty > NameThe name of an additional property for the item.Yes
InvoiceLine > Item > AdditionalItemProperty > ValueThe value of the additional property (e.g., the PO number again).Yes
InvoiceLine > Price > PriceAmountThe net unit price of the item (price for one piece).Yes
InvoiceLine > Price > BaseQuantityThe quantity the unit price applies to (usually 1).Middleware
Invoice Totals
TaxTotal > TaxAmountThe total VAT/tax amount for the entire invoice.Yes
TaxSubtotal > TaxableAmountThe total base amount subject to a specific tax rate.Yes
TaxSubtotal > TaxAmountThe total tax amount for that specific tax rate.
LegalMonetaryTotal > LineExtensionAmountThe subtotal of all line amounts, before tax and document-level charges.Yes
LegalMonetaryTotal > TaxExclusiveAmountThe total amount of the invoice, excluding tax.Yes
LegalMonetaryTotal > TaxInclusiveAmountThe total amount of the invoice, including tax.Yes
LegalMonetaryTotal > AllowanceTotalAmountThe total of all document-level discounts/allowances.
LegalMonetaryTotal > ChargeTotalAmountThe total of all document-level extra charges/fees.
LegalMonetaryTotal > PayableAmountThe final, total amount due for the invoice.Yes

Post the request for Vertex Netherlands

This is code in python

"""

Simple script to:
  1) get an access token from Vertex
  2) POST a VRBL/UBL XML invoice to Vertex Send Document endpoint

"""

import argparse
import json
import os
import sys
import uuid
import time
import requests

DEFAULT_TOKEN_URL = "https://auth.vertexcloud.com/oauth/token"
DEFAULT_BASE_URL = "https://e-invoicing-service.vertexcloud.com"

def get_access_token(client_id: str, client_secret: str, token_url: str = DEFAULT_TOKEN_URL, audience: str = "verx://migration-api", timeout: int = 10):
    """
    Request an access token using client_credentials.
    Returns (access_token, expires_in, retrieved_at_timestamp)
    See Vertex docs for required params. :contentReference[oaicite:4]{index=4}
    """
    payload = {
        "client_id": client_id,
        "client_secret": client_secret,
        "audience": audience,
        "grant_type": "client_credentials"
    }
    headers = {"Content-Type": "application/json"}

    resp = requests.post(token_url, json=payload, headers=headers, timeout=timeout)
    resp.raise_for_status()
    j = resp.json()
    token = j.get("access_token")
    expires_in = j.get("expires_in", 0)
    if not token:
        raise RuntimeError(f"Failed to obtain access_token. Response: {j}")
    return token, int(expires_in), int(time.time())

def send_document(xml_path: str, access_token: str, base_url: str = DEFAULT_BASE_URL, idempotency_key: str = None, timeout: int = 30):
    """
    Send a single VRBL XML file to Vertex Send Document endpoint.
    The VRBL XML must be posted as raw XML with Content-Type=application/xml. :contentReference[oaicite:5]{index=5}
    Returns requests.Response
    """
    if idempotency_key is None:
        idempotency_key = str(uuid.uuid4())

    url = base_url.rstrip("/") + "/customers/v2/documents"
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/xml",
        "Accept": "application/json",
        "Idempotency-Key": idempotency_key
    }

    with open(xml_path, "rb") as fh:
        xml_bytes = fh.read()

    resp = requests.post(url, data=xml_bytes, headers=headers, timeout=timeout)
    return resp, idempotency_key

def main():
    parser = argparse.ArgumentParser(description="Get Vertex access token and send VRBL XML invoice.")
    parser.add_argument("--xml-file", required=True, help="Path to VRBL XML invoice file (UBL XML).")
    parser.add_argument("--client-id", default=os.getenv("VERTEX_CLIENT_ID"), help="OAuth client_id (or set VERTEX_CLIENT_ID).")
    parser.add_argument("--client-secret", default=os.getenv("VERTEX_CLIENT_SECRET"), help="OAuth client_secret (or set VERTEX_CLIENT_SECRET).")
    parser.add_argument("--base-url", default=DEFAULT_BASE_URL, help="Base URL for send document endpoint.")
    parser.add_argument("--token-url", default=DEFAULT_TOKEN_URL, help="OAuth token URL.")
    args = parser.parse_args()

    if not args.client_id or not args.client_secret:
        print("Error: client_id and client_secret must be provided either via args or env vars VERTEX_CLIENT_ID and VERTEX_CLIENT_SECRET.", file=sys.stderr)
        sys.exit(2)

    # 1) Get token
    try:
        token, expires_in, retrieved_at = get_access_token(args.client_id, args.client_secret, token_url=args.token_url)
        expiry_time = retrieved_at + expires_in
        print(f"Obtained access token (expires in {expires_in}s at epoch {expiry_time})")
    except Exception as e:
        print(f"Failed to obtain access token: {e}", file=sys.stderr)
        sys.exit(1)

    # 2) Send document
    try:
        resp, idem_key = send_document(args.xml_file, token, base_url=args.base_url)
    except Exception as e:
        print(f"Error sending document: {e}", file=sys.stderr)
        sys.exit(1)

    # 3) Process response
    print(f"Idempotency-Key used: {idem_key}")
    print(f"HTTP {resp.status_code}")

    # Vertex typically returns JSON for the response; print it if possible
    content_type = resp.headers.get("Content-Type", "")
    if "application/json" in content_type:
        try:
            print(json.dumps(resp.json(), indent=2))
        except Exception:
            print(resp.text)
    else:
        print(resp.text)

    if not resp.ok:
        sys.exit(3)

if __name__ == "__main__":
    main()

Update the Org with the Response

Here is an example of how you can update back your org:

PATCH: {instance_url}/services/data/{version}/sobjects/Invoice/{INVOICE_ID}

{
  "Document_ID__c": "123e4567-e89b-12d3-a456-426614174000",
  "E-invoicing_Status__c": "Sent to Network",
  "Idempotency_Key__c": "2a8f6d0c-1f5a-4b6b-b9a0-3f4e3c9d7f12"
}

Poll Vertex for Approval

Vertex Document: https://developer.vertexinc.com/einvoicing/docs/get-document-status 

GET: https://e-invoicing-service.vertexcloud.com/customers/v2/documents/{documentId}

Capture fields to update the salesforce org on Approval:

OutputTypeDescription
documentIdGUIDThe GUID of the document you requested to view the status of.
Document NumberStringThe logical invoice number from within the invoice body.
Issue DateDateTimeThe issue date time from the invoice body.
StatusStatusCodeThe document workflow status as listed in Document Workflow Status.
Transmission DateTimeDateTimeThe timestamp at which the invoice was transmitted to Vertex e-Invoicing.
ErrorDetailsObjectAn object providing structured details about any errors encountered in document processing.
EndpointsObjectAn object providing structured information about the routing information for the document.

Follow the same API call made above to update the Salesforce Org with the exact status and other relevant information.

Transaction Journals

Considering you implement the accounting features as outlined here https://help.salesforce.com/s/articleView?id=ind.billing_financial_accounting.htm&type=5 ; the system will automatically generate the transaction journals for your transactions.  Key things to configure 

  • Enable accounting under Billing Settings
  • Setup you Legal Entity
  • Setup your Accounting periods and assign to Legal Entity
  • Setup your Chart of Accounts (General Ledger Accounts)
  • Define the automations to generate journal entries (Setup General Ledger Accounting Assignment Rules) 

From Indrajeet Sengupta: E-Invoicing with Revenue Cloud

What is E-Invoicing?

Imagine instead of printing an invoice, putting it in an envelope, and mailing it or emailing it, you create it in your accounting software and send it directly to your customer’s accounting software in a structured digital format. That’s e-invoicing in a nutshell.

E-invoicing is the issuance and exchange of invoices in a structured electronic data format, designed for machine-to-machine readability and automated processing. Crucially, a true e-invoice is not simply a PDF or scanned document; it is a structured file, often in XML, UBL, or EDI formats, that can be automatically validated, consumed, and posted directly into a recipient’s accounting or ERP system. The exchange typically occurs through standardized Peppol networks or dedicated government portals. This systematic approach eliminates manual data entry and establishes a transparent, auditable flow of fiscal transaction data between trading partners.

For any multinational enterprise, implementing einvoicing correctly and efficiently is an imperative compliance measure. Governments—particularly those with VAT/GST systems—are imposing mandates to gain real-time or near real-time visibility into business transactions, a strategy designed to combat fraud and close the tax gap. Failure to comply with country-specific standards results in penalties and can prevent a business from legally trading in key jurisdictions. Operationally, this required automation reduces significant administrative costs (paper, postage, labor), eliminates manual data entry errors, and accelerates Accounts Receivable and Accounts Payable cycles, directly improving cash flow.


2. The Benefits of Going Digital

Why are businesses and governments so excited about e-invoicing? The advantages are clear:

  • Cost Savings: Say goodbye to expenses on paper, printing, and postage. More importantly, you save countless hours of manual processing time.
  • Faster Payments: Because e-invoices are received and processed instantly, the approval and payment cycle is significantly shorter. This greatly improves cash flow.
  • Reduced Errors: Manual data entry is prone to human error. E-invoicing eliminates this, ensuring accuracy and reducing the back-and-forth of correcting mistakes.
  • Enhanced Security: E-invoices are exchanged over secure networks, drastically reducing the risk of invoice fraud, phishing scams, and interception compared to paper or PDF invoices sent via email.
  • Improved Compliance: With governments increasingly mandating e-invoicing for tax purposes, adopting it ensures you stay compliant with tax regulations automatically.
  • Environmental Friendliness: Less paper means a smaller carbon footprint. 

3. The Global Trend: E-Invoicing Mandates

Governments worldwide are recognizing the power of e-invoicing to combat tax evasion and digitize their economies. This has led to a wave of mandates requiring businesses to adopt e-invoicing. The trend is moving from a “post-audit” model (where tax authorities check records later) to a “clearance” model (where invoices must be cleared by the government in real-time).

Here’s a snapshot of the global landscape:

Country/RegionMandate StatusKey Go-Live DatesOfficial Source Link
Americas
BrazilMandatory (Fragmented)NFCom: 1 Nov 2025; National NFS-e: 2026http://www.nfe.fazenda.gov.br/portal
MexicoMandatoryLive (CFDI 4.0 since 1 Apr 2023)https://www.sat.gob.mx/portal/public/tramites/factura-electronica
ChileMandatoryLive (since Feb 2018)https://www.sii.cl/servicios_online/
ColombiaMandatoryLive (since Nov 2020)https://micrositios.dian.gov.co/sistema-de-facturacion-electronica/
PeruMandatoryLive (since 2022)https://cpe.sunat.gob.pe/
ArgentinaMandatoryLive (since 2019 for most sectors)https://www.afip.gob.ar/fe/
Costa RicaMandatoryLive (since 2019)https://www.hacienda.go.cr/ATV/login.aspx
Europe
FrancePhased MandateReception: 1 Sep 2026; Issuance (Large/Mid): 1 Sep 2026; Issuance (SME): 1 Sep 2027https://www.impots.gouv.fr/professionnel/je-decouvre-la-facturation-electronique
GermanyPhased MandateReception: 1 Jan 2025; Issuance (Large): 1 Jan 2027; Issuance (All): 1 Jan 2028https://en.e-rechnung-bund.de/
ItalyMandatoryLive (since 1 Jan 2019)https://www.agenziaentrate.gov.it/portale/aree-tematiche/fatturazione-elettronica/fatturazione-elettronica-site-area
PolandPhased MandateIssuance (Large): 1 Feb 2026; Issuance (All): 1 Apr 2026https://www.podatki.gov.pl/ksef/
SpainMandate Pending RegsProjected 2027/2028https://www.facturae.gob.es/factura-electronica/Paginas/factura-electronica.aspx
DenmarkB2G(Mandatory) / B2B (Phased)1 January 2005: B2G , 1 January 2024 – 1 January 2026: Phased Implementation for B2Bhttps://danishbusinessauthority.dk/requirements-digital-bookkeeping-systems
BelgiumMandatory1 Jan 2026https://einvoice.belgium.be/en
RomaniaMandatoryReporting: 1 Jan 2024; E-invoicing: 1 Jul 2024https://www.anaf.ro/anaf/internet/ANAF/despre_anaf/strategii_anaf/proiecte_digitalizare/e.factura
SerbiaMandatoryLive (since 1 Jan 2023)https://www.efaktura.gov.rs/
AustriaB2G MandatoryLive (B2G since 1 Jan 2014)https://www.usp.gv.at/en.html
BulgariaB2G MandatoryLive (B2G since 1 Jul 2017)https://www.e-docs.bgsait.com/
Canary IslandsMandate Pending RegsSame as Spain (Projected 2027/2028)https://www.gobiernodecanarias.org/tributos/
CroatiaB2G MandatoryLive (B2G since 1 Jul 2019)https://www.fina.hr/servis-e-racun
CyprusB2G MandatoryLive (B2G since 1 Apr 2020)https://www.uat.gov.cy/
Czech RepublicB2G MandatoryLive (B2G since 1 Oct 2016)https://www.nakh.cz/cs/
DenmarkMandatoryLive (B2G since 2005, B2B since 2024 for bookkeeping)https://erhvervsstyrelsen.dk/
EstoniaB2G MandatoryLive (B2G since 1 Jul 2019)https://www.rtk.ee/
FinlandB2G MandatoryLive (B2G since 1 Apr 2020)https://www.valtiokonttori.fi/
Great Britain (UK)B2G (NHS) MandatoryLive (NHS since 2019)https://www.gov.uk/government/publications/public-procurement-policy-note-0318
IcelandMandatoryLive (B2G since 2015, B2B since 2016)https://www.fjs.is/
IrelandB2G MandatoryLive (B2G since 18 Apr 2020)https://ogp.gov.ie/e-invoicing-in-ireland/
LuxembourgPhased MandateLive (Large: May 2022; Mid: Oct 2022; Small: Mar 2023)https://gouvernement.lu/en/dossiers/2021/facturation-electronique.html
NetherlandsB2G MandatoryLive (B2G since 18 Apr 2019)https://www.logius.nl/producten/e-factureren
NorwayB2G MandatoryLive (B2G since 1 Jan 2019)https://www.digdir.no/
PortugalPhased MandateLive (B2G since Jan 2021; B2B since Jan 2023)https://www.espap.gov.pt/
SloveniaB2G MandatoryLive (B2G since 1 Jan 2015)https://www.ujp.gov.si/
SwedenB2G MandatoryLive (B2G since 1 Apr 2019)https://www.digg.se/
APAC & Middle East
Saudi ArabiaPhased MandatePhase 2 (Integration) live since 1 Jan 2023 in waveshttps://zatca.gov.sa/en/E-Invoicing/Pages/default.aspx
IndiaPhased MandateLive (Threshold: AATO > Rs. 5 Crore)https://einvoice1.gst.gov.in/
JapanQualified Invoice SystemLive (since 1 Oct 2023)https://www.nta.go.jp/taxes/shiraberu/zeimokubetsu/shohi/keigenzeiritsu/invoice_about.htm
AustraliaPhased MandateB2G Live (since 1 Jul 2022)https://www.ato.gov.au/Business/eInvoicing/
New ZealandPhased MandateB2G Capability: 1 Jan 2026https://www.einvoicing.govt.nz/
MalaysiaPhased MandateIssuance (Large): 1 Aug 2024; Issuance (All): 1 Jul 2025https://www.hasil.gov.my/en/e-invoice/

4. How Does It Work? The E-Invoicing Process

The process involves a few key steps and players for both the seller and the buyer.

For the Seller:

  1. Invoice Creation: The seller creates an invoice in their ERP or accounting system as usual.
  2. Tax Determination: Often, a specialized tax vendor solution is integrated to automatically calculate the correct VAT/GST based on the transaction details, ensuring tax accuracy.
  3. Conversion & Validation: The invoice data is converted into a structured e-invoice format (like XML).
  4. Sending to Partner: The seller sends this e-invoice to their chosen invoicing partner (e.g., Vertex, Sovos, Pagero, Avalara). This partner acts as an access point to the e-invoicing network.
  5. Transmission: The partner validates the invoice against country-specific rules and transmits it securely through the required network (like PEPPOL or a government portal) to the buyer’s access point. In “clearance” models, this step includes sending the invoice to the tax authority for real-time approval before it’s sent to the buyer.

For the Buyer:

  1. Receiving: The buyer’s invoicing partner receives the e-invoice from the network.
  2. Data Ingestion: The partner sends the structured data directly into the buyer’s ERP or accounts payable (AP) system.
  3. Automated Processing: The AP system automatically processes the invoice, matching it against purchase orders and goods receipts without any manual keying.
  4. Approval & Payment: The invoice is routed for digital approval and scheduled for payment, all within the same system.

5. Common Formats for E-Invoices

Because e-invoices are meant for machines to read, they use structured data formats. You’ll often hear these terms:

  • XML (eXtensible Markup Language): The foundation for many e-invoice standards.
  • UBL (Universal Business Language): A popular library of standard XML business documents, widely used in e-invoicing.
  • Factur-X / ZUGFeRD: A hybrid format popular in France and Germany that embeds an XML file within a human-readable PDF.
  • PEPPOL BIS Billing 3.0: The standard format used across the PEPPOL network.

6. Common E-Invoicing Networks

E-invoices don’t just travel over the open internet; they use secure, standardized networks.

  • PEPPOL (Pan-European Public Procurement On-Line): The most widespread international network. It’s not just for Europe; countries like Australia, New Zealand, Singapore, and Japan have adopted it. It works as a “four-corner model” where the seller (corner 1) sends to their Access Point (corner 2), which sends to the buyer’s Access Point (corner 3), which delivers to the buyer (corner 4).
  • Government-Centralized Platforms: Many countries, particularly in Latin America (e.g., Mexico’s CFDI, Brazil’s NF-e) and Europe (e.g., Italy’s SdI), operate a centralized government hub. All invoices must pass through this single platform for validation and clearance.
  • Service Provider Networks: Companies like Sovos, Tungsten, and Tradeshift operate large networks that can connect businesses to each other and to various government platforms, simplifying compliance across multiple countries.

7. How do you do it in Revenue Cloud

Salesforce Revenue Cloud is a powerful engine for managing complex billing, and can be functionality expanded where needed to connect to government portals and standardized networks such as PEPPOL. Additionally, Revenue Cloud can connect to and utilize external service providers to manage e-invoicing requirements across the globe

So, how do you bridge this gap? The answer lies in a well-architected middleware integration. While Salesforce’s recommended IPaaS (Integration Platform as a Service) is MuleSoft, you can also build a custom solution. This guide breaks down the entire process, showing you how to turn Revenue Cloud into a compliant, global e-invoicing machine.

The Foundation in Salesforce

Before you can build any bridges, you need a solid foundation. This involves preparing your Salesforce org to hold all the necessary data and track the e-invoicing lifecycle.

Data Capture

Ensure all required data points for e-invoicing are captured in Salesforce. This data often lives across multiple objects. Key objects include Invoice, Account, Billing Schedule Group, InvoiceLine, InvoiceLineTax, Contact, BillingProfile.

E-Invoicing Status Field

On the Invoice object, create a custom picklist field named “E-Invoicing Status”. This field is crucial for tracking the invoice’s journey and triggering the automation.

Example Statuses:

  • Pending: The invoice has been created but is not yet ready for submission.(Draft Status of Invoice)
  • Canceled: DRAFT invoice not used, so canceled it.
  • Ready for E-Invoicing: The invoice has been finalized and is ready to be sent to the network. This status will be our trigger.
  • Sent to Network: The middleware has successfully sent the invoice data.
  • Acknowledged by Network: The network has received the invoice and confirmed its validity.
  • Approved: The invoice has been approved by the tax authority (for clearance models).
  • Rejected: The invoice was rejected by the network due to errors.
  • Correction Needed: Data needs correction.
  • Correction Addressed: Correction has been made and can be resent for Approval.
  • Error: The integration process failed.
  • Exempt: Invoice is exempted from E-Invoicing Process.
  • Voided invoice – No need to send for E-Invoicing.

This can be made more granular based on the country level specifications

E-Invoicing Fields on Invoice

There can be various details that might need to be captured, creating fields for these. Here are some example fields:

  1. E-Invoicing Status
  2. Idempotency Key
  3. Issue Date
  4. Document Number
  5. Document ID
  6. IRN Number (India)
  7. IdSdi (Italy)
  8. UUID (Mexico)
  9. Chave de Acesso (Brazil)
  10. Transmission DateTime
  11. PDF Document (or use Invoice Files)

Create Custom Salesforce Event for Invoice Posted

Salesforce does not generate an event whenever a custom field like “E-Invoicing Status” field is set to a particular value. To do this, we will create an event that is a lightweight message containing key identifiers, like the InvoiceId and AccountId. Using this the middleware will be able to fetch the invoice details

The Integration Process: A Detailed Breakdown

Here’s how the magic happens, step by step, following an event-driven architecture.

1. Trigger

The process kicks off inside Salesforce. An automation rule (using a Salesforce Flow or Apex Trigger) monitors the Invoice object. When a user updates an invoice’s “E-Invoicing Status” to “Ready for E-Invoicing” or “Correction Addressed”, the trigger fires. This E-Invoicing Status could change automatically once the Invoice is in Posted State or manually depending on business conditions. Customers can write flows to change this based on their business requirements.

2. Event

Upon firing, the trigger doesn’t call the middleware directly. Instead, it publishes a Custom Platform Event within Salesforce which can be read by the middleware or Mulesoft. This decouples Salesforce from the middleware, making the system more robust and scalable.

3. Listen

Your middleware layer is continuously listening for this specific Platform Event from Salesforce. When it catches a new event, it knows it has a new e-invoice to process.

4. Extract

The middleware takes the InvoiceId from the event message and makes a Composite API call back to Salesforce. This is highly efficient, as it allows the middleware to query the Invoice record and all its related parent records (like the Account for the Tax ID and the BSG for the PO number) in a single, consolidated API call.

5. Transform

This is the middleware’s primary job. It takes the JSON data extracted from Salesforce and transforms it into the required e-invoicing format for the target country. This usually means mapping the Salesforce fields to a structured XML format, such as UBL (Universal Business Language) or a country-specific standard like Factur-X.

6. Send

Once the e-invoice file is created, the middleware authenticates with the external E-Invoicing Network’s API and sends the transformed payload. The middleware then updates the “E-Invoicing Status” in Salesforce to Sent to Network.

7. Reconcile

The E-Invoicing Network will respond. This can happen in two ways:

  • Synchronous Response: An immediate reply confirming the file was received and is structurally valid. The middleware can use this to update the status in Salesforce to Acknowledged by Network.
  • Asynchronous Response: The final approval or rejection from a government tax authority may come minutes or hours later. The network typically sends this status back via a webhook, which is a URL pointing to your middleware. The middleware listens for this incoming webhook to receive the final status.

8. Update Back SF

Upon receiving the final reconciliation status (e.g., Approved or Rejected), the middleware makes one last API call to Salesforce. It updates the Invoice record with:

  • The final “E-Invoicing Status” (Approved or Rejected).
  • The unique Reference Number provided by the tax authority.
  • Any error messages in case of rejection.
  • Any other necessary fields that needs to be captured.

9. Accounting

Considering you implement the accounting features on the org, as outlined here https://help.salesforce.com/s/articleView?id=ind.billing_financial_accounting.htm&type=5, you will be able to find the journal entries generated to the transaction journal.

You can look at the following post for an example how this is done.