You need to sign in to do that
Don't have an account?
Field Integrity Exception
Hi,
I'm getting the following error when choosing a price book (custom button) if opportunity has products (OpporutnityLineItems).
|
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 !!
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
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
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
Getting following error
Argument 1 cannot be null
An unexpected error has occurred. Your development organization has been notified
Thanks,
SVP
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
Still Same Error...
Thanks,
SVP
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