You need to sign in to do that
Don't have an account?
Kenn K.
Direction in solving multi-object query/Update
I am trying to build a trigger that does a few things and I was hoping I could get the best direction in handling this.
I have 2 objects ("Quote" and "QuoteLine") and a custom setting called "ServiceDate__c" which basically stores 2 information, Country__c and numberOfDays__c. The goal of the trigger is to query aCountry__c field on the QuoteLine object, compare it to country field on the ServiceDate__c object to get the number.
Finally, since there will be a number of closeDate__c fields on the QuoteLine, I would like to query only the UNIQUE CloseDate__c values and update the Quote object.
Sample code would be appreciated.
Tl:dr. Get unique date values on the Quote after calculation happens on the Quoteline object that references a custom setting for more information.
Here is what I have so a far;
I have 2 objects ("Quote" and "QuoteLine") and a custom setting called "ServiceDate__c" which basically stores 2 information, Country__c and numberOfDays__c. The goal of the trigger is to query aCountry__c field on the QuoteLine object, compare it to country field on the ServiceDate__c object to get the number.
For Example, on the quote line, we store country names like USA. On the Custom setting, we have a map that stores Country, USA with a ServiceDate value of 50. 50 is the number of days that needs to be added to the close date on the quote line. So it's be closeDate 2016-01-20 + 50.
Finally, since there will be a number of closeDate__c fields on the QuoteLine, I would like to query only the UNIQUE CloseDate__c values and update the Quote object.
Sample code would be appreciated.
Tl:dr. Get unique date values on the Quote after calculation happens on the Quoteline object that references a custom setting for more information.
Here is what I have so a far;
trigger SB_QuoteAdditionalUpdates on SBQQ__Quote__c (before insert, before update) { Set<id> QuoteIds = New Set<id>(); for (SBQQ__Quote__c SBQuotes : trigger.new){ QuoteIds.add(SBQuotes.id); SBQQ__QuoteLine__c[] SBQuoteLines = [Select country__c, country_code__c, close_date__c, country_employee_construct__c, Employee_CountFormula__c from SBQQ__QuoteLine__c where id IN: QuoteIds]; if(SBQuoteLines.size()>0){ for(SBQQ__QuoteLine__c SBQuoteLine : SBQuoteLines ){ map<id, OperationalStartDate__c> NumberOfDaysMap = new map <id, OperationalStartDate__c>([select name, Number_Of_Days__c from OperationalStartDate__c where name =: SBQuoteLine.country__c ]); } } } }
NOTE: This code has not been tested and may contain typographical or logical errors
All Answers
SBQQ__QuoteLine__c is the child of SBQQ__Quote__c
Ideally, it woud be SBQQ__Quote__c but it'll be both. SBQQ__Quote__c should be updated with the unique values i.e. the quote line will have multiple lines of CloseDate and I would like to update SBQQ__Quote__c with unique values.
I think after insert trigger will help.
I am somewhat stuck and I am pretty sure the code isn't bulkified. Any help whatsoever would be appreciated.
Thanks.
- In the QuoteLine Object, there is a field called Country__c and CloseDate__c.
- There is also a custom setting called OperationalStartDate__c that has 2 fields; Name (this is country name) and Number_Of_Days__c.
- I would like to Update the value of the close date on the quoteLine. So if the Country__c on the QuoteLine is USA, I would query the custo setting and look for USA, get the Number_Of_Days__c value and add it to the CloseDate__c on the QuoteLine.
I guess let's start with that first.NOTE: This code has not been tested and may contain typographical or logical errors