• Gaurav kumar 34
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hello Guys,
Try to insert opportunityline item, getting error like 

"System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is in a different pricebook than the one assigned to the opportunity): [PricebookEntryId]"


List<Opportunity> opp = [Select id From Opportunity o where id = 'XXXXXXXX'];
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
    List<PriceBookEntry> priceBookList = [SELECT Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry WHERE Product2Id='XXXXX(productId)' AND PriceBook2.isStandard=true LIMIT 1];

    for (Opportunity oppty: opp) {
            OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=oppty.Id,PricebookEntryId=priceBookList[0].Id,Quantity = 1,UnitPrice = 120);
                oliList.add(oli);
    }
     
    insert oliList;

Regards,
G
Hello Guys,
Try to insert opportunityline item, getting error like 

"System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId (pricebook entry is in a different pricebook than the one assigned to the opportunity): [PricebookEntryId]"


List<Opportunity> opp = [Select id From Opportunity o where id = 'XXXXXXXX'];
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
    List<PriceBookEntry> priceBookList = [SELECT Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry WHERE Product2Id='XXXXX(productId)' AND PriceBook2.isStandard=true LIMIT 1];

    for (Opportunity oppty: opp) {
            OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=oppty.Id,PricebookEntryId=priceBookList[0].Id,Quantity = 1,UnitPrice = 120);
                oliList.add(oli);
    }
     
    insert oliList;

Regards,
G
The challenge is:

You've been given a requirement to keep Contact addresses in sync with the Account they belong to. Use Process Builder to create a new process that updates all child Contact addresses when the address of the Account record is updated. This process:Can have any name.
Must be activated.
Must update Contact mailing address fields (Street, City, State, Post Code, Country) when the parent Account shipping address field values are updated.

I start with Accounts when records is created or edited.
Filter criteria where accounts shipping address (street, city, state, zip code) is changed (used "or" logic).

I am stuck on the next step "add action".  I started with action type "Update Records".
On objects, I can't seem to change Accounts to Contacts.  Why?