Skip to main content
deleted 43 characters in body
Source Link
Adrian Larson
  • 151.4k
  • 38
  • 247
  • 431

I have a Visualforce page which create a product record, a priceBookEntry record and a opportunityLineItem record.

I don't understand why in only one case, I get this error : enter image description here

In my code, I first create the product then the priceBookEntry and the opportunityLineItem.

If I try to create the OpportunityLineItem record between the opportunity and the pricebook as an other user, it works well, it just doesn't work with one user.

The currency of the opportunity is USD and the currency of the priceBookEntry is AED.

This is my code :

 this.theProductToInsert.IsActive = true;
        
        insert this.theProductToInsert;
    
        PriceBookEntry thePriceBookEntry = new PriceBookEntry(
            IsActive = true,
            Pricebook2Id = this.thePriceBook.Id,
            Product2Id = this.theProductToInsert.Id,
            UnitPrice = 1           
        );
        
        insert thePriceBookEntry;
        
        System.debug('*** thePriceBookEntry: ' + thePriceBookEntry);
        
        insert new OpportunityLineItem(
            OpportunityId = this.theOpportunity.Id,
            PricebookEntryId = thePriceBookEntry.Id,
            Quantity = this.theOpportunityLineItem.Quantity,
            UnitPrice = this.theOpportunityLineItem.UnitPrice,
            Status__c = this.theOpportunityLineItem.Status__c,
            Lead_time__c = this.theOpportunityLineItem.Lead_time__c
        );

How the currency of the priceBookEntry is selected please?

Why it doesn't work please?

Aurélien

I have a Visualforce page which create a product record, a priceBookEntry record and a opportunityLineItem record.

I don't understand why in only one case, I get this error : enter image description here

In my code, I first create the product then the priceBookEntry and the opportunityLineItem.

If I try to create the OpportunityLineItem record between the opportunity and the pricebook as an other user, it works well, it just doesn't work with one user.

The currency of the opportunity is USD and the currency of the priceBookEntry is AED.

This is my code :

 this.theProductToInsert.IsActive = true;
        
        insert this.theProductToInsert;
    
        PriceBookEntry thePriceBookEntry = new PriceBookEntry(
            IsActive = true,
            Pricebook2Id = this.thePriceBook.Id,
            Product2Id = this.theProductToInsert.Id,
            UnitPrice = 1           
        );
        
        insert thePriceBookEntry;
        
        System.debug('*** thePriceBookEntry: ' + thePriceBookEntry);
        
        insert new OpportunityLineItem(
            OpportunityId = this.theOpportunity.Id,
            PricebookEntryId = thePriceBookEntry.Id,
            Quantity = this.theOpportunityLineItem.Quantity,
            UnitPrice = this.theOpportunityLineItem.UnitPrice,
            Status__c = this.theOpportunityLineItem.Status__c,
            Lead_time__c = this.theOpportunityLineItem.Lead_time__c
        );

How the currency of the priceBookEntry is selected please?

Why it doesn't work please?

Aurélien

I have a Visualforce page which create a product record, a priceBookEntry record and a opportunityLineItem record.

I don't understand why in only one case, I get this error : enter image description here

In my code, I first create the product then the priceBookEntry and the opportunityLineItem.

If I try to create the OpportunityLineItem record between the opportunity and the pricebook as an other user, it works well, it just doesn't work with one user.

The currency of the opportunity is USD and the currency of the priceBookEntry is AED.

This is my code :

 this.theProductToInsert.IsActive = true;
        
        insert this.theProductToInsert;
    
        PriceBookEntry thePriceBookEntry = new PriceBookEntry(
            IsActive = true,
            Pricebook2Id = this.thePriceBook.Id,
            Product2Id = this.theProductToInsert.Id,
            UnitPrice = 1           
        );
        
        insert thePriceBookEntry;
        
        System.debug('*** thePriceBookEntry: ' + thePriceBookEntry);
        
        insert new OpportunityLineItem(
            OpportunityId = this.theOpportunity.Id,
            PricebookEntryId = thePriceBookEntry.Id,
            Quantity = this.theOpportunityLineItem.Quantity,
            UnitPrice = this.theOpportunityLineItem.UnitPrice,
            Status__c = this.theOpportunityLineItem.Status__c,
            Lead_time__c = this.theOpportunityLineItem.Lead_time__c
        );

How the currency of the priceBookEntry is selected please?

Source Link
Oupat
  • 731
  • 18
  • 45

Pricebook entry currency code does not match opportunity currency code

I have a Visualforce page which create a product record, a priceBookEntry record and a opportunityLineItem record.

I don't understand why in only one case, I get this error : enter image description here

In my code, I first create the product then the priceBookEntry and the opportunityLineItem.

If I try to create the OpportunityLineItem record between the opportunity and the pricebook as an other user, it works well, it just doesn't work with one user.

The currency of the opportunity is USD and the currency of the priceBookEntry is AED.

This is my code :

 this.theProductToInsert.IsActive = true;
        
        insert this.theProductToInsert;
    
        PriceBookEntry thePriceBookEntry = new PriceBookEntry(
            IsActive = true,
            Pricebook2Id = this.thePriceBook.Id,
            Product2Id = this.theProductToInsert.Id,
            UnitPrice = 1           
        );
        
        insert thePriceBookEntry;
        
        System.debug('*** thePriceBookEntry: ' + thePriceBookEntry);
        
        insert new OpportunityLineItem(
            OpportunityId = this.theOpportunity.Id,
            PricebookEntryId = thePriceBookEntry.Id,
            Quantity = this.theOpportunityLineItem.Quantity,
            UnitPrice = this.theOpportunityLineItem.UnitPrice,
            Status__c = this.theOpportunityLineItem.Status__c,
            Lead_time__c = this.theOpportunityLineItem.Lead_time__c
        );

How the currency of the priceBookEntry is selected please?

Why it doesn't work please?

Aurélien