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
svpsvp 

Field Integrity Exception

Hi,

I'm getting the following error when choosing a price book (custom button) if opportunity has products (OpporutnityLineItems).

 

Errors
 
  • java.sql.SQLException: ORA-20067: ORA-06512: at "BASHFUL.GUTIL", line 42 ORA-06512: at "BASHFUL.SOPPORTUNITY", line 2327 ORA-06512: at line 1
  • Price Book: field integrity exception: Pricebook2Id (cannot change pricebook on opportunity with line items)



It's urgent, any help must be highly appreciated.

<apex:page standardcontroller="Opportunity" extensions="ChoosePricebook_Ext" id="thepage">
    <apex:sectionHeader title="{!Opportunity.Name}" subtitle="Choose a Pricebook"/>
    <apex:form id="theform">
         <apex:pageBlock title="Available Pricebooks">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!Cancel}" value="Cancel"/>
                <apex:commandButton action="{!Save}" value="Save"/>
            </apex:pageBlockButtons>
             <apex:pageBlockSection showheader="false" columns="1">                
                <apex:pageblocksectionitem >
                    <apex:outputLabel value="Select a Pricebook"/>
                    <apex:selectRadio value="{!Opportunity.Pricebook2Id}" layout="pageDirection">
                        <apex:selectOptions value="{!pricebooks}"/>
                    </apex:selectRadio>
                </apex:pageblocksectionitem>    
                <apex:pageMessages />    
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


public with sharing class ChoosePricebook_Ext {

  private final Opportunity opp;
  public ChoosePricebook_Ext(Apexpages.StandardController stdController){
    this.opp = (Opportunity)stdController.getRecord();
  }

  List<SelectOption> pricebooks;
  public List<Selectoption> getPricebooks(){
    if(pricebooks == null){
    
      pricebooks = new List<SelectOption>{};
      
      pricebooks.add(new selectoption('', 'None'));
      
      User u = [select id, Region__c From User where id =: Userinfo.getUserId()];  
      List<String> regions = new List<String>{};
      if(U.Region__c != null)regions = u.Region__c.split(';');
    
    //  Get the pricebooks
      Map<String, Id> nTOb = new Map<String, Id>{};
      for(Pricebook2 book : [select id, name from Pricebook2]){
        nTOb.put(book.name, book.id);
      }
      
    //  Get the applicable pricebooks
      for(PricebookSelect__c pbs : [Select Id, Region__c,PricebookId_c__c From PricebookSelect__c
                      where Region__c in: regions]){
          

            pricebooks.add(new selectoption(nTOb.get(pbs.Pricebook_Name__c), pbs.Pricebook_Name__c));
                            
      }
      
      if(pricebooks.size() == 1){
        Apexpages.Message nobooks = new apexpages.message(Apexpages.SEVERITY.INFO, 'No pricebooks ');
        Apexpages.addMessage(nobooks);
      }
              
    }
    
    return pricebooks;    
    
  }

 

Thanks a lot in advance !!

asish1989asish1989

Hi

     Try this

              

Map<String, Id> nTOb = new Map<String, Id>{};
for(Pricebook2 book : [select id, name from Pricebook2 ]){
nTOb.put(book.name, book.id);
}

// Get the applicable pricebooks
for(PricebookSelect__c pbs : [Select Id, Region__c,PricebookId_c__c From PricebookSelect__c
where Region__c in: regions]){

pricebooks.add(new selectoption(nTOb.get(String), pbs.Pricebook_Name__c));

 

 

Did this solve your issue if so please mark it solved

 

thanks

asish

svpsvp

Hi,

Thank you for your reply, it doesn't worked, getting below error:

 

Error: Compile Error: Variable does not exist: String at line 40 column 72

 

 

Thanks& Regards

 

asish1989asish1989

Hi

   Try by writing this

       pricebooks.add(new selectoption(nTOb.get('String'), pbs.Pricebook_Name__c));

 

       put single quote..and ..Let me know  

 

 

Did this post solve your problem..if so please mark it solved ...so that others get benifited.

 

 

Thanks

asish

svpsvp

Getting following error

 

Argument 1 cannot be null
An unexpected error has occurred. Your development organization has been notified

 

 

 

Thanks,

SVP

asish1989asish1989

Hi

   Try this

 

    // your code....

         if(nTOb.size() >0){

             for(PricebookSelect__c pbs : [Select Id, Region__c,PricebookId_c__c From PricebookSelect__c where Region__c in: regions]){

            pricebooks.add(new selectoption(nTOb.get('String'), pbs.Pricebook_Name__c));

        //your code......

 

       }

}

if some error comes please highlight the code where error is comming... 

Did this post solve your problem if so please mark it solved so that others can get benifited

 

Thanks

asish

svpsvp

Still Same Error...

 

 

 

Thanks,

SVP

asish1989asish1989

Hi

     Try this ..It may work

                 if(nTOb.size() >0){

             for(PricebookSelect__c pbs : [Select Id, Region__c,PricebookId_c__c From PricebookSelect__c where Region__c in: regions]){

            pricebooks.add(new selectoption(nTOb.values()) , pbs.Pricebook_Name__c));

        //your code......

 

       }

}

 

Did this post solve your issue.if so please mark it solved

 

Thanks

asish