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
Violeta Grigorova 3Violeta Grigorova 3 

Can I update a subscription product field from a visualforce page?

If we have a list of contracts and within a given contract we have a list of subscriptions. Can I change the product field from a VisualForce page? Could you point me to where I shoud read about doing so, if possible.

Thank you!
karthikeyan perumalkarthikeyan perumal
Hello, 

This is sample Product update code which associated with Opp, 

the same you have to use for Contract and associated sub and product. 

in this code insted of Opp try to pass contract and get the related products to update and subscriptions. 

Class: 
public class LineItem_Controller {
   
    //*****Declare GLOBAL variables
    private List <Opportunity> oppList = new List <Opportunity>();
    private List <OpportunityLineItem> prodList = new List <OpportunityLineItem>();
    private List <OpportunityLineItem> addRowList = [SELECT PricebookEntry.Product2.Name, quantity, unitprice, totalprice
                                                    FROM OpportunityLineItem
                                                    WHERE OpportunityID = :ApexPages.currentPage().getParameters().get('id')];
    //********
   
     public LineItem_Controller(ApexPages.StandardController controller)
        {
        }
   
    //Get the Opportunity Detail Inforamation from the Opportunity Detail Page and return a list of that information.
    public List <Opportunity> getOpportunityInfo()
    {
        List <Opportunity> opp_InfoList = [SELECT name, ownerID, createddate, stagename, amount
                               FROM Opportunity
                               WHERE id = :ApexPages.currentPage().getParameters().get('id')];
        oppList = opp_InfoList;
   
    return opp_infoList;
    }
   
    //Get the Product Detail Information associated with the Opportunity. The WHERE queries whatever Opportunity ID is currently in context.
    public List <OpportunityLineItem> getProductInfo()
    {
        List <OpportunityLineItem> prod_InfoList = [SELECT PricebookEntry.Product2.Name, quantity, unitprice, totalprice
                                                    FROM OpportunityLineItem
                                                    WHERE OpportunityID = :ApexPages.currentPage().getParameters().get('id')];
        prodList = prod_InfoList;
       
        return prod_InfoList;
    }
  
   
    //****SAVE AND CANCEL METHODS
    OpportunityLineItem opportunity = new OpportunityLineItem();
    public List <OpportunityLineItem> productID = [SELECT PricebookEntry.Pricebook2ID
                                                   FROM OpportunityLineItem
                                                   WHERE OpportunityID = :ApexPages.currentPage().getParameters().get('id')];

   
//***GET OPPORTUNITY ID
    String opportunityID = ApexPages.currentPage().getParameters().get('id');
   
   
   
    public PageReference cancel() {
       PageReference cancelReference = new ApexPages.StandardController(opportunity).view();
        cancelReference.setRedirect(true);
        return cancelReference;
    }

    public PageReference save() {
        update prodList;
        update oppList;
        PageReference reference = new ApexPages.StandardController(opportunity).view();
        reference.setRedirect(true);
        return reference;
    }
   
   

}

Page: 
 
<apex:page standardController="Opportunity" extensions="LineItem_Controller">
<apex:form >

<style type="text/css">
        .ProductNameField { width: 235px; }
        .OpportunityNameField {width: 200px; }
</style>

<apex:sectionHeader title="Create/Edit Opportunity" />
<apex:pageblock id="OpportunityandProduct_PageBlock">
<apex:pageblocksection columns="1" title="Opportunity Detail">
   
    <apex:pageblocktable value="{!OpportunityInfo}" var="opp">
       
        <apex:column headerValue="Opportunity Name">
            <apex:outputLabel value="{!opp.name}" StyleClass="OpportunityNameField"/>
        </apex:column>
       
        <apex:column headerValue="Opportunity Owner">
            <apex:outputLabel value="{!opp.ownerID}" />
        </apex:column>
       
        <apex:column headerValue="Created Date">
           <apex:outputLabel value="{!opp.createddate}" />
        </apex:column>
       
        <apex:column headerValue="Stage">
            <apex:outputLabel value="{!opp.stagename}"/>
        </apex:column>
        <apex:column value="{!opp.amount}" />
   </apex:pageblocktable>
</apex:pageblocksection>

<apex:pageblocksection columns="1" title="Product Detail">
    <apex:pageblocktable value="{!ProductInfo}" var="prod">
       
        <apex:column headerValue="Product Name">
            <apex:inputField value="{!prod.pricebookentry.product2.name}" styleClass="ProductNameField"/>
        </apex:column>
       
        <apex:column headerValue="Quantity">
            <apex:inputField value="{!prod.quantity}"/>
        </apex:column>
       
        <apex:column headerValue="Unit Price">
            <apex:inputField value="{!prod.unitprice}"/>
        </apex:column>
        <apex:column value="{!prod.TotalPrice}" headerValue="Total Price" />
   </apex:pageblocktable>
</apex:pageblocksection>

    <apex:pageBlockButtons >
        
       <apex:commandButton value="Save" action="{!save}"/>
       <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons>
</apex:pageblock>

</apex:form>
</apex:page>

when you preview visualforce page pass Opp ID in query string like below, 

User-added image

Hope it helps, 

Thanks
karthik