You need to sign in to do that
Don't have an account?
Michele Toscano
Invalid initial value type List for List
I've tried to put my query directly in a list and then loop through the list but I'm getting an error invalid value type list for list.
Map<String,string> maprecTypewithId = new Map<String,String>();
List<Price_Authorization_Request__c> listPARToUpdate = new List<Price_Authorization_Request__c>([select id,Name from recordType where SObjectType = 'Price_Authorization_Request__c']);
for(RecordType rec : listPARToUpdate)
{
maprecTypewithId.put(rec.Name,rec.id);
}
However, If I try it this way - I get the aggregrate query FOR loop error (due to large recrod set)
Map<String,string> maprecTypewithId = new Map<String,String>();
List<Price_Authorization_Request__c> listPARToUpdate = new List<Price_Authorization_Request__c>();
for(RecordType rec : [select id,Name from recordType where SObjectType = 'Price_Authorization_Request__c'])
{
maprecTypewithId.put(rec.Name,rec.id);
}
What is the best way to achieve this - without exceeding governor limits?
Map<String,string> maprecTypewithId = new Map<String,String>();
List<Price_Authorization_Request__c> listPARToUpdate = new List<Price_Authorization_Request__c>([select id,Name from recordType where SObjectType = 'Price_Authorization_Request__c']);
for(RecordType rec : listPARToUpdate)
{
maprecTypewithId.put(rec.Name,rec.id);
}
However, If I try it this way - I get the aggregrate query FOR loop error (due to large recrod set)
Map<String,string> maprecTypewithId = new Map<String,String>();
List<Price_Authorization_Request__c> listPARToUpdate = new List<Price_Authorization_Request__c>();
for(RecordType rec : [select id,Name from recordType where SObjectType = 'Price_Authorization_Request__c'])
{
maprecTypewithId.put(rec.Name,rec.id);
}
What is the best way to achieve this - without exceeding governor limits?
as you can see we I have added childRecCount.get(parObj.Id) == 0 at the end of the if condition in the OR section. I thought we had already added it in there. I probably missed that. The idea being
If number of child records is equal to the number of child records that are expired, expire the PAR
Or
If number of child records for PAR is equal to zero and PAR expiration is less than today then expire PAR
Hope this helps
All Answers
try this,
1. List and maps needs to be specified with type like List<Price_Authorization_Request__c> and Map<String, Id>
2. SOQL query is used within the loop
3. since you are querying the child records you can use subquery, inner query to query child records,
4. maprecTypewithId does not seems to be used anywhere
I have not tested the code, so there might be some errors. try this and let me know.
Hope this helps
I replied to your other question, I realised that using inner query we will run into too many rows assigned error so here is the mofied query, should work though I did not test.
let me know
with
should resolve that issue. Now we are also making sure that we are not updating PAR when there are no child records.
I am sorry you had to redo this number of times, but this should fix the problem.
So, here is the corrected version, just replace this section and try again
for(Pricing_Input__c pi :pInput){
childRecCount.put(pi.Price_Authorization_Request__c, childRecCount.get(pi.Price_Authorization_Request__c)+1);
if(pi.Expiration_Date_Change_To__c != null && pi.Expiration_Date_Change_To__c < system.today()) {
updatedCount.put(pi.Price_Authorization_Request__c,
updatedCount.get(pi.Price_Authorization_Request__c)+1);
}
}
for(Price_Authorization_Request__c parObj : Parlist){
if( (childRecCount.get(parObj.Id) == updatedCount.get(parObj.Id) && childRecCount.get(parObj.Id) > 0) || (parObj.Expiration_Date__c < System.today())){ //problem
parObj.Par_Status__c = 'Expired';
Since the expiration date resides on both the header and on the pricing input level- the pricing input level always wins. Meaning, if there is ANY product pricing inputs with a changed expiration date to the future- even if the PAR's header expiration is in the past- it should NOT be expired. Only when there are no product pricing inputs should the main PAR's expiration be considered when it's in the past- then, in that case- it should mark it fully expired.
as you can see we I have added childRecCount.get(parObj.Id) == 0 at the end of the if condition in the OR section. I thought we had already added it in there. I probably missed that. The idea being
If number of child records is equal to the number of child records that are expired, expire the PAR
Or
If number of child records for PAR is equal to zero and PAR expiration is less than today then expire PAR
Hope this helps