0

I have a custom object with the API name of Pricing_Range__c. Each account record has a related list of this custom object. I would like to make a visualforce page that would allow us to mass edit the pricing_range records related to individual accounts, by clicking on a button on the related list on the account page that directs to the visualforce page with pricing_range records for that account.

My visualforce page is:

<apex:page standardController="Pricing_Range__c" recordSetVar="Pricing_Range__c" tabStyle="Pricing_Range__c" sidebar="false" extensions="AccountPricingRanges">
    <apex:form >
        <apex:pageBlock id="accountId">
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!Pricing_Range__c}" var="pr">
                <apex:column value="{!pr.Name}"/>
                <apex:column value="{!pr.Pricing_Type__c}"/>
                <apex:column headerValue="Active">
                    <apex:inputField value="{!pr.Active__c}"/>  
                </apex:column>
                <apex:column headerValue="Plus Price">
                    <apex:inputField value="{!pr.Plus_Price__c}"/>  
                </apex:column> 
                <apex:column value="{!pr.PTP_Premium_Price__c}"/>   
                <apex:column value="{!pr.PTP_Prestige_Price__c}"/>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
</apex:page>

This is the AccountPricingRange extension:

public with sharing class AccountPricingRanges {

    private List<Pricing_Range__c> range;
    private Id accountId;

    public AccountPricingRanges(ApexPages.StandardSetController c) {
        c.setPageSize(10);
        this.accountId = ApexPages.currentPage().getParameters().get('id');
    }

    public List<Pricing_Range__c> getrange() {
        range = [Select Id, Name, Pricing_Type__c, Plus_Price__c, Premium_Price__c, Prestige_Price__c, Active__c from Pricing_Range__c where Franchise__c = :this.accountId];
        return range;
    }

    public pageReference save() {
        update range;
        PageReference ret = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
        return ret.setRedirect(true);
    }

    public PageReference cancel() {
        PageReference ret = new PageReference(ApexPages.currentPage().getParameters().get('retURL'));
        return ret.setRedirect(true);
    }

}

Here is a screenshot of the preview:

Preview Page

Obviously, this code is incorrect. It does not allow me to edit pricing ranges for a particular account. How do I fix it?

  • shouldn't this line <apex:pageBlockTable value="{!Pricing_Range__c}" var="pr"> be <apex:pageBlockTable value="{!range}" var="pr"> ? – cropredy Oct 2 '17 at 21:52
  • I tried this and I ended up with no records in the list – Sebastian Oct 3 '17 at 14:16
  • when testing, are you sure that URL param id has a value? – cropredy Oct 3 '17 at 21:29
  • Yes, the URL has the account id – Sebastian Oct 4 '17 at 0:04
0

It works with this:

public with sharing class AccountPricingRanges {

public AccountPricingRanges() {

}

public List<Pricing_Range__c> range;

public AccountPricingRanges(ApexPages.StandardSetController c) {
    c.setPageSize(20);
}

public List<Pricing_Range__c> getrange() {
    range = [Select Name, Franchise__c, Pricing_Type__c, Plus_Price__c, PTP_Premium_Price__c, PTP_Prestige_Price__c, Active__c from Pricing_Range__c  WHERE Franchise__c =:ApexPages.CurrentPage().GetParameters().Get('id')];
    return range;
}

public pageReference save() {
    update range;
    PageReference pageRef = ApexPages.currentPage();
    return pageRef.setRedirect(true);
}

public PageReference cancel() {
    PageReference pageRef = ApexPages.currentPage();
    return pageRef.setRedirect(true);
}

}

And the following page:

<apex:page controller="AccountPricingRanges" sidebar="false">
<apex:form >
    <apex:pageBlock id="accountId">
        <apex:pageMessages />
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}"/>
        </apex:pageBlockButtons>
        <apex:pageBlockTable value="{!range}" var="pr">
            <apex:column value="{!pr.Name}"/>
            <apex:column value="{!pr.Pricing_Type__c}"/>
            <apex:column headerValue="Active">
                <apex:inputField value="{!pr.Active__c}"/>  
            </apex:column>
            <apex:column headerValue="Plus Price">
                <apex:inputField value="{!pr.Plus_Price__c}"/>  
            </apex:column> 
            <apex:column value="{!pr.PTP_Premium_Price__c}"/>   
            <apex:column value="{!pr.PTP_Prestige_Price__c}"/>
        </apex:pageBlockTable>      
    </apex:pageBlock>
</apex:form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.