Happy Business Starts Here

Ability to Display Subscription Number on the Invoice Section in Salesforce

Highlighted
Zuora Staff

Ability to Display Subscription Number on the Invoice Section in Salesforce

QUESTION:

Is there any way to see the relation between an Invoice and Subscription in Salesforce?

It would be very helpful for Customer support to know which invoices i.e which services were not paid yet.






If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Zuora Staff

Re: Ability to Display Subscription Number on the Invoice Section in Salesforce

SOLUTION:

This by design, because Subscription and Invoice objects are not directly connected in Zuora and one single Invoice can include multiple Subscriptions. 

This behaviour is also consistent in Zuora itself. 

From SalesForce, you will be able to see which Billing Account one Invoice belongs to, but you will not be able to tell which Subscription is included in this Invoice.






If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

View solution in original post

4 REPLIES 4
Highlighted
Zuora Staff

Re: Ability to Display Subscription Number on the Invoice Section in Salesforce

SOLUTION:

This by design, because Subscription and Invoice objects are not directly connected in Zuora and one single Invoice can include multiple Subscriptions. 

This behaviour is also consistent in Zuora itself. 

From SalesForce, you will be able to see which Billing Account one Invoice belongs to, but you will not be able to tell which Subscription is included in this Invoice.






If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

View solution in original post

Highlighted
Guru

Re: Ability to Display Subscription Number on the Invoice Section in Salesforce

Workaround / Alternate Solution:

 

We had the same request from our users to be able to see the linkage between the Invoices and Subscriptions. This is especially important in our case because we mostly operate with resellers and so the invoices are not even on the end users account.

 

Disclaimer going into this: This is not a perfect solution, nor is it our final version. We are using this to bridge the gap for our users while we work on a full sync solution using custom objects in Salesforce.

 

Our solution was to create a Visualforce page that can render the invoice details along with a "related list" style view of all subscriptions that appear on it. The result is something that looks like this: 

 

Screenshot 2016-05-04 09.58.53.png

 

This is comprised of two parts. The Apex controller to drive the data and the Visualforce page itself:

 

Apex Controller:

 

public class InvoiceSubscriptionList {
    private List<Zuora__Subscription__c> subscriptions;
    private Zuora__ZInvoice__c invoice;
     
    public InvoiceSubscriptionList(ApexPages.StandardController controller) {
        controller.addFields(new List<String>{'Name'});
        controller.addFields(new List<String>{'Zuora__Zuora_Id__c'});
        this.invoice= (Zuora__ZInvoice__c)controller.getRecord();
    }
    
    public List<Zuora__Subscription__c> getSubscriptions()
    {
        Zuora.zApi zApiInstance = new Zuora.zApi();
        zApiInstance.zlogin();
        
        String zoql = 'select id, invoiceid, subscriptionNumber from InvoiceItem where invoiceId = \'' + invoice.Zuora__Zuora_Id__c + '\'';
        List<Zuora.zObject> zobjs = zApiInstance.zquery(zoql);
        
        Set<String> subNumbers = new Set<String>();
        for (Zuora.zObject o : zobjs) {
            subNumbers.add((String)o.getValue('SubscriptionNumber'));
        }
        
        if (subNumbers.size() == 0) {
            return null;
        }
            
        subscriptions = [Select id, Name, Zuora__TermStartDate__c, Zuora__TermEndDate__c from Zuora__Subscription__c where Name in: subNumbers];
        return subscriptions;
    }
}

 

Visualforce Page:

 

<apex:page standardController="Zuora__ZInvoice__c" extensions="InvoiceSubscriptionList">
<style>
.fewerMore { display: none;}
</style>
<apex:form >
 <apex:pageMessages />
 <apex:detail relatedList="true"></apex:detail>
<apex:pageblock id="CustomList" title="Subscriptions"  >
   <apex:pageBlockTable value="{!subscriptions}" var="i" rendered="{!NOT(ISNULL(subscriptions))}">
        <apex:column value="{!i.Name}"/>
        <apex:column value="{!i.Zuora__TermStartDate__c}"/>
        <apex:column value="{!i.Zuora__TermEndDate__c}"/>
   </apex:pageBlockTable>
   <apex:outputLabel value="No records to display" rendered="{!(ISNULL(subscriptions))}" styleClass="noRowsHeader"></apex:outputLabel>
 </apex:pageblock>
</apex:form>
</apex:page>

The Visualforce page is intended to completely replace the invoice layout. This is done by overriding the "View" button in the Invoice custom object to point to this visualforce page. This does come with some tradeoffs (i.e. your list can only appear at the very bottom, and you lose some handy admin things on the invoice page like "Edit Layout" and the admin tab, but it was better than embedding visualforce in an iframe. If you want the iframe and scroll bars, you can remove the  "apex:pageMessages" and "apex:detail" sections and include the page inline.

 

The controller uses the order builder API to communicate with Zuora via SOAP and retrieve the mapping from Invoice -> Subscription. This is done using the InvoiceItem object which has reference to both the InvoiceId and the SubscriptionNumber. I chose to use SubscriptionNumber since it is a stable value across versions, whereas the SubscriptionId changes on every version and would be harder to refer to.

 

As I mentioned this is v1 to allow our users to look up the information they need. Since its implemented in Visualforce, there is no relation in the salesforce database which makes reporting on the data impossible (since its only fetched at render time). There are also some inherent limits we did not account for in this implementation. For example, the order builder API can return at most 1000 records per call. This code does not account for this, so if you had more than 1000 invoiceitems on your invoice, you might miss things. This could be easily amended to support the queryMore() call, but since our invoices usually contain 4 - 8 items at most, we decided to omit this given it will be a short term implementation.

 

Our future plans in case people are interested (or want to share their own ideas on how best to do this) is to sync in an association between the subscription and the invoice. This would represent a many to many relationship so it requires a junction or association object to be created in salesforce. Example:

 

Subscription <--- SubscriptionInvoiceAssociation ---> Invoice

 

The SubscriptionInvoiceAssociation object would be master-detail to both Subscription and Invoice so that "Subscription" could show all the associated invoices and "Invoice" could show all the related subscriptions.

 

Two main parts to this would be: How to best perform synchronization? We could have triggers on the invoices (which are generally immutable) to perform a sync when an invoice is generated. We could also do periodic sync to update new records.

 

Another challenge is that by default, when a subscription is amended, it is deleted and recreated with the new version. There is a feature support can enable to have sync update the object rather than delete and re-create which we are discussing with them.

 

Hope some people find this useful, and I welcome any discussion on better ways to do this.

 


Cheers,

Jacob

 

Highlighted
Zuora Support Moderator

Re: Ability to Display Subscription Number on the Invoice Section in Salesforce

Thanks for posting this, @feisley!



If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √

Highlighted
Partner

Re: Ability to Display Subscription Number on the Invoice Section in Salesforce

We've done a similiar VisualForce solution, brining in Invoice Items and Adjustments. (screenshot #1).  

Also, we have a service that brings over invoice items into Salesforce, which allows reporting, something that isn't possible with the VF solution.  (ss #2).

 

 

Screenshot #1. Dynamic VisualForce component to show invoice items with subscription number on the invoice page.

VF.jpg

 

 

SS #2: Invoice Items in Salesforce that show the Subscription Number

 

ZIISS.jpg

 

 

Frontera Consulting
Oracle, Salesforce and Zuora Consultants