• admin1.3954222418789446E12
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi,

I have been trying to create a way of allowing my users to edit only the price books I want them to and this has led me down the path of creating a visualforce page and custom controller

Although I have a range of programming experience, I am still relatively new to both VF and Apex.  What I have is something of a cobbled together mash-up of code found through the website, so do please feel free to point out inconsistencies.

Here is my code:
[code]
<apex:page Controller="Custom_pricebookentry_controller">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection >
                <apex:inputField value="{!pricebook_List.pricebook2Id}"/>
                <apex:inputField value="{!SearchCriteria.CurrencyIsoCode}"/>
                <apex:commandButton value="Search" action="{!filterPBEs}" reRender="pbe_section,error"/>
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockSection>

            <apex:pageBlockTable value="{!filteredPBEs}" id="pbe_section" var="pbe">
                <apex:column headerValue="Name"><apex:outputField value="{!pbe.name}"/></apex:column>
                <apex:column headerValue="Ccy"><apex:outputField value="{!pbe.currencyIsoCode}"/></apex:column>
                <apex:column headerValue="Price"><apex:outputField value="{!pbe.unitPrice}"/></apex:column>
                <apex:column headerValue="New Price"><apex:inputField value="{!pbe.unitPrice}"/></apex:column>
            </apex:pageBlockTable>
           
            <apex:pageMessages id="error"></apex:pageMessages>

        </apex:pageBlock>
    </apex:form>
</apex:page>
[/code]

and

[code]
public with sharing class Custom_pricebookentry_controller {
    public List<priceBookEntry> FilteredPBEs{get;set;}
    public priceBookEntry SearchCriteria{get;set;}
    public opportunity pricebook_list{get;set;}
    public Custom_pricebookentry_controller ()
    {
        pricebook_list = new opportunity();
        SearchCriteria = new priceBookEntry();
    }
   
    public void filterPBEs()   
    {
        FilteredPBEs = new List<priceBookEntry>();
       
        FilteredPBEs = [SELECT Name,UnitPrice
                          FROM PricebookEntry
                         WHERE Pricebook2Id =: pricebook_list.Pricebook2Id
                           AND CurrencyIsoCode =: SearchCriteria.CurrencyIsoCode];
         if(FilteredPBEs.size() == 0)
         {
            Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records to Display'));
         }
    }
   
    public void save()   
    {
        priceBookEntry pbe= new priceBookEntry();

        try
        {
            insert pbe.unitPrice;
        }
        catch(Exception ex)
        {
          System.debug('\n\nException ='+ex.getMessage()+'\n\n');
        }

    }
}
[/code]

Right now I get an error "Error: Compile Error: DML requires SObject or SObject list type: Decimal at line 31 column 13", so presumably I have to define the variable type somehow.

Any help would be hugely appreciated.

David
Hi,

I have been trying to create a way of allowing my users to edit only the price books I want them to and this has led me down the path of creating a visualforce page and custom controller

Although I have a range of programming experience, I am still relatively new to both VF and Apex.  What I have is something of a cobbled together mash-up of code found through the website, so do please feel free to point out inconsistencies.

Here is my code:
[code]
<apex:page Controller="Custom_pricebookentry_controller">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection >
                <apex:inputField value="{!pricebook_List.pricebook2Id}"/>
                <apex:inputField value="{!SearchCriteria.CurrencyIsoCode}"/>
                <apex:commandButton value="Search" action="{!filterPBEs}" reRender="pbe_section,error"/>
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockSection>

            <apex:pageBlockTable value="{!filteredPBEs}" id="pbe_section" var="pbe">
                <apex:column headerValue="Name"><apex:outputField value="{!pbe.name}"/></apex:column>
                <apex:column headerValue="Ccy"><apex:outputField value="{!pbe.currencyIsoCode}"/></apex:column>
                <apex:column headerValue="Price"><apex:outputField value="{!pbe.unitPrice}"/></apex:column>
                <apex:column headerValue="New Price"><apex:inputField value="{!pbe.unitPrice}"/></apex:column>
            </apex:pageBlockTable>
           
            <apex:pageMessages id="error"></apex:pageMessages>

        </apex:pageBlock>
    </apex:form>
</apex:page>
[/code]

and

[code]
public with sharing class Custom_pricebookentry_controller {
    public List<priceBookEntry> FilteredPBEs{get;set;}
    public priceBookEntry SearchCriteria{get;set;}
    public opportunity pricebook_list{get;set;}
    public Custom_pricebookentry_controller ()
    {
        pricebook_list = new opportunity();
        SearchCriteria = new priceBookEntry();
    }
   
    public void filterPBEs()   
    {
        FilteredPBEs = new List<priceBookEntry>();
       
        FilteredPBEs = [SELECT Name,UnitPrice
                          FROM PricebookEntry
                         WHERE Pricebook2Id =: pricebook_list.Pricebook2Id
                           AND CurrencyIsoCode =: SearchCriteria.CurrencyIsoCode];
         if(FilteredPBEs.size() == 0)
         {
            Apexpages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,''+'No records to Display'));
         }
    }
   
    public void save()   
    {
        priceBookEntry pbe= new priceBookEntry();

        try
        {
            insert pbe.unitPrice;
        }
        catch(Exception ex)
        {
          System.debug('\n\nException ='+ex.getMessage()+'\n\n');
        }

    }
}
[/code]

Right now I get an error "Error: Compile Error: DML requires SObject or SObject list type: Decimal at line 31 column 13", so presumably I have to define the variable type somehow.

Any help would be hugely appreciated.

David