-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
2Questions
-
0Replies
I have the above code that gets fields off the OpportunityLineItem... my client would like for it to get different fields if the opportunity has a certain field populated.
public with sharing class BookingReviewPageControllerSynced { public Opportunity myOpp {get;set;} public List<OpportunityLineItem> opportunityProductList{get;set;} /*public String url_redirect {get;set;} public String selectedRedirectProduct{get;set;} public Boolean reloadNeeded{get;set;} */ public BookingReviewPageControllerSynced(ApexPages.StandardController stdController) { this.myOpp = (Opportunity)stdController.getRecord(); getOpportunityProductList(); } public void getOpportunityProductList() { opportunityProductList = new List<OpportunityLineItem>(); System.debug('FARGLE myOpp.ID: ' + myOpp.Id ); for (OpportunityLineItem opL:[SELECT Id, formula_Line_Number__c, Product2Id, ProductCode, Product2.Name, Product2.Supplier_Name__c, Product2.Supplier_Name__r.Name, Product2.Supplier_Name__r.Business_Designation__c, Product2.Hazard_Class__c, Product2.NSN__c, Product2.Reporting_Category__c, Product2.Manufacturer_Product_Number__C, Quantity, Unburdened_Unit_Price_Quote_Line__c, Burdened_Unit_Price_Quote_Line__c, formula_GSA_Remarks__c, Quote_Line_Item__r.GSA_Price__c, Quote_Line_Item__r.Calculated_Usual_Days_to_Ship__c, Product2.ADS_Cost__c, Quote_Line_Item__r.ADS_Cost__c, Quote_Line_Item__r.UnitCost__c, Supplier_Quote_Number__c, Quote_Line_Item__r.Berry_Compliance_Status__c, Quote_Line_Item__r.Country_of_Origin__c, Quote_Line_Item__r.Compliance_Code__c, Quote_Line_Item__r.Supplier_Quote_Number__c FROM OpportunityLineItem WHERE OpportunityId =:myOpp.id ORDER BY Quote_Line_Item__r.Number__c ASC]) { if (opl.Supplier_Quote_Number__c != null && opl.Product2.ADS_Cost__c != opl.Quote_Line_Item__r.UnitCost__c){ opl.Quote_Line_Item__r.ADS_Cost__c = null; } else { opl.Quote_Line_Item__r.UnitCost__c = null; } opportunityProductList.add(opl); } } /* public PageReference redirectToURL(){ // debug String strDebugUrl = '/' + selectedRedirectProduct + '/e?retURL=' + myOpp.id; System.debug('Product ID: ' + opportunityProductList[0].SBQQ__Product__r.Id + ' -- COMPARE -- 01tL0000004XFK8'); System.debug('URL Redirect: ' + strDebugUrl); url_redirect = '/' + selectedRedirectProduct + '/e?retURL=' + myOpp.id; reloadNeeded = true; return null; } */ }how do i set a condition to switch between these
public void getOpportunityProductList() { opportunityProductList = new List<OpportunityLineItem>(); System.debug('FARGLE myOpp.ID: ' + myOpp.Id ); for (OpportunityLineItem opL:[SELECT Id, formula_Line_Number__c, Product2Id, ProductCode, Product2.Name, Product2.Supplier_Name__c, Product2.Supplier_Name__r.Name, Product2.Supplier_Name__r.Business_Designation__c, Product2.Hazard_Class__c, Product2.NSN__c, Product2.Reporting_Category__c, Product2.Manufacturer_Product_Number__C, Quantity, Unburdened_Unit_Price_Quote_Line__c, Burdened_Unit_Price_Quote_Line__c, formula_GSA_Remarks__c, SBQQ__QuoteLine__r.GSA_Price__c, SBQQ__QuoteLine__r.Calculated_Usual_Days_to_Ship__c, Product2.ADS_Cost__c, SBQQ__QuoteLine__r.ADS_Cost__c, SBQQ__QuoteLine__r.SBQQ__UnitCost__c, Supplier_Quote_Number__c, SBQQ__QuoteLine__r.Berry_Compliance_Status__c, SBQQ__QuoteLine__r.Country_of_Origin__c, SBQQ__QuoteLine__r.Compliance_Code__c, SBQQ__QuoteLine__r.Supplier_Quote_Number__c FROM OpportunityLineItem WHERE OpportunityId =:myOpp.id ORDER BY SBQQ__QuoteLine__r.SBQQ__Number__c ASC]) { if (opl.Supplier_Quote_Number__c != null && opl.Product2.ADS_Cost__c != opl.SBQQ__QuoteLine__r.SBQQ__UnitCost__c){ opl.SBQQ__QuoteLine__r.ADS_Cost__c = null; } else { opl.SBQQ__QuoteLine__r.SBQQ__UnitCost__c = null; } opportunityProductList.add(opl); } }
- Joshua Anderson 44
- August 04, 2020
- Like
- 0
Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, The price book entry is in a different price book than the one assigned to the Quote, or Quote has no price book assigned. I cant Figure out what I'm doing wrong
@isTest public class TestBookingReviewPageControllerSynced { @testSetup static void setup(){ Id pbId = Test.getStandardPricebookId(); Pricebook2 stdPb = new Pricebook2(Name = 'Standard Price Book', Id = pbId, isActive = true); upsert stdPb; System.debug('Standard pricebook list just inserted ' + stdPb); Map<String, Id> rtMap = new Map<String, Id>(); List<RecordType> rtList = new List<RecordType>([SELECT Id, Name FROM RecordType]); for(RecordType rt : rtList){ rtMap.put(rt.Name, rt.Id); } List<Account> aList = new List<Account>(); Account newAccount = new Account(Name = 'Test Account', Phone = '(555) 555-5555', Customer_Class__c = 'Defense Industry', Entity_Type__c = 'Domestic', Finalization_Status__c = 'Finalized', RecordTypeId = rtMap.get('US Federal Government Customer')); Account newSupplier = new Account(Name = 'Test Supplier Account', Phone = '(555) 777-4242', Entity_Type__c = 'Domestic', Finalization_Status__c = 'Finalized', RecordTypeId = rtMap.get('Partner Supplier')); aList.add(newAccount); aList.add(newSupplier); insert aList; List<Address__c> adList = new List<Address__c>(); Address__c newBillingAddress = new Address__c( Account_Name__c = newAccount.Id, Address_Line_1__c = '536 Viking Dr', Address_Line_2__c = 'Building 1', City__c = 'Virginia Beach', State__c = 'Virginia', State_Code__c = 'VA', Postal_Code__c = '23452', Country__c = 'United States', Country_Code__c = 'US', Type__c = 'Billing', Primary__c = true ); Address__c newShippingAddress = new Address__c( Account_Name__c = newAccount.Id, Address_Line_1__c = '621 Lynnhaven Pkwy', Address_Line_2__c = 'Suite 160', City__c = 'Virginia Beach', State__c = 'Virginia', State_Code__c = 'VA', Postal_Code__c = '23452', Country__c = 'United States', Country_Code__c = 'US', Type__c = 'Shipping' ); adList.add(newBillingAddress); adList.add(newShippingAddress); insert adList; Contact newContact = new Contact(FirstName='Erik', LastName='Rodgers', AccountID = newAccount.Id, Phone='(555) 555-55555'); insert newContact; List<Sales_Rep__c> srList = new List<Sales_Rep__c>(); Sales_Rep__c insideRep = new Sales_Rep__c(Name = 'Inside Sales Rep Jane', Type__c = 'ISR', Active__c = true, Oracle_ID__c = '900237164'); Sales_Rep__c outsideRep = new Sales_Rep__c(Name = 'Outside Sales Rep John', Type__c = 'OSR', Active__c = true, Oracle_ID__c = '900055045'); srList.add(insideRep); srList.add(outsideRep); List<Product2> productList = new List<Product2>(); Product2 productA = new Product2( Name = 'Item A', ProductCode = '78542-856-8547', Supplier_Product_Number__c = '78542-856-8547', Supplier_Name__c = newSupplier.Id, GSA_Price__c = 10.50, ADS_Cost__c = 8.50, IsActive = true, Product_Status__c = 'Prospective', Category__c = 'TBD', Sub_Category__c = 'To Be Determined', Berry_Compliance_Status__c = 'No', Country_of_Origin__c = 'United States', Hazard_Class__c = 'EXP 2', Reporting_Category__c = 'APPAREL', NSN__c = '4520-01-649-2495', Manufacturer_Product_Number__C = '78542-856-8547' ); productList.add(productA); insert productList; System.debug('Product list just inserted ' + productList); List<PricebookEntry> entry = [ SELECT ID FROM PricebookEntry WHERE Pricebook2Id = :stdPb.id]; System.debug('PricebookEntry list just inserted ' + entry); // Set<Id> pbEntryid = new Map<Id, PricebookEntry>([SELECT Id FROM PricebookEntry WHERE Pricebook2Id = :stdPb.id]).keySet(); // System.debug('PricebookEntry list just inserted ' + pbEntryid); Opportunity opp = new Opportunity(Name = 'Test Opportunity', AccountId = newAccount.Id, CloseDate = date.Today(), StageName = 'Quoted', Pricebook2Id = stdPb.Id); insert opp; System.debug('Opportunity list just inserted ' + opp); Contract newContract = new Contract( AccountId = newAccount.Id, Name = 'Contract Name', Status = 'Draft', StartDate = date.Today(), ADS_Contract_Number__c = 'ADS Number', Customer_Contract_Number__c = 'Customer Number', Quote_Enabled__c = true, Pricebook2 = [SELECT Id FROM Pricebook2 WHERE Id= :stdPb.Id], Participating_Customer_Class__c = 'Air Force;Army', Berry_Compliance__c = 'No' ); insert newContract; Quote newQuote = new Quote( Name = 'Test Name', OpportunityId = opp.Id, Opportunity2__c = opp.Id, Type__c = 'Quote', Status__c = 'Draft', Contract__c = newContract.Id, Bill_To_Address__c = newBillingAddress.Id, Ship_To_Address__c = newShippingAddress.Id, Bill_To_Contact__c = newContact.Id, Ship_To_Contact__c = newContact.Id, Bill_To_Account__c = newAccount.Id, Ship_To_Account__c = newAccount.Id, Primary__c = true, Account__c = newAccount.Id, PriceBook__c = stdPb.id ); insert newQuote; System.debug('New Quote list just inserted ' + newQuote); QuoteLineItem newQuoteLineI = new QuoteLineItem( QuoteId = newQuote.Id, // Product__c = productA.Id, Deal_Strategy__c = 'Some Deal Strategy', Quantity__c = 175, Number__c = 1, GSA_Price__c = 10.50, ADS_Cost__c = 8.50, Quantity = 1, // UnitPrice = 11.50, // Product2Id = productA.Id, PricebookEntryId = '01ur0000000j1oiAAA', UnitCost__c = 8.50 ); insert newQuoteLineI; System.debug('New Quote line item list just inserted ' + newQuoteLineI); } @istest static void testController(){ Opportunity opp = [SELECT Id FROM Opportunity LIMIT 1]; // Retrieve the standard controller for the opportunity ApexPages.standardController opportunityController = new ApexPages.standardController(opp); BookingReviewPageController controller = new BookingReviewPageController(opportunityController); System.assert( controller.opportunityProductList.size() == 1 ); } }
- Joshua Anderson 44
- July 23, 2020
- Like
- 0