You need to sign in to do that
Don't have an account?

Making use of Maps
I have an issue of GLimit when using the list and set.
I have written a trigger on a custom object which is in relation with contacts.
The trigger performs action based on updation or insertion of records.
Here is my code:
Set<String> cntctIds = new Set<String>();
List<obj__c> obj =[select id, SSN__c, Name, Status__c, Contact__c,ownerid, Account_Name__c, from obj__c where id In:trigger.newMap.keyset()];
for(Integer j=0;j< obj.size();j++)
{
cntctIds.add(obj[j].Contact__c);
}
List<obj__c> obj_Total =[select id, SSN__c, Name, Status__c, Contact__c,ownerid, Account_Name__c, from obj__c where id IN: cntctIds];
//List used to retrieve contacts based on cntctIds
List<Contact> objCntct = [Select id,Account.Name,lookupOwnerID__c, SSN__c, PCN__c, Status__c, FirstName, LastName,AccountId, OwnerId, from Contact where id IN: cntctIds];
//List used to retrieve Obj__c based on cntctIds and Terminated Status.
List<obj__c> obj_Terminated =[select id, SSN__c, Name, Status__c, Contact__c,ownerid, Account_Name__c, from obj__c where obj__c.Status__c = 'Terminated' and id IN: cnctctIds];
//List used to retrieve Obj__c based on cntctIds and Current Status.
List<obj__c> obj_Current =[select id, SSN__c, Name, Status__c, Contact__c,ownerid, Account_Name__c, from obj__c where obj__c.Status__c = 'Current' and id IN: cnctctIds];
now i need to check the conditions if all the records are terminated or current.
For that i am using the condition:
for(j=0; j<objCntct ; j++)
{
if(obj_Total.size() == obj_Terminated.size())
{
//functionality
}
else if(obj_Total.size() == obj_Current.size())
{
}
}
This is working perfectly fine if the batch size is 1.
Becuase in that scenario there will be only one contact but if the batch size is 200 then there will be many contacts for 200 obj__c records.And then the condition fails bacause the the obj_Total count and the terminated or current count never matches.
Can anyone provide a soln for this.
Or any one has the idea how to make use of Maps here to check the conditions.
Thanks
shaan
We use only two queries, and build mapped data to easily keep track of this complex data structure. A well-organized structure will almost certainly reduce coding requirements and probably heap memory usage as well. If you need help understanding what's going on, please let me know.
Hey many thanks for your response.
I tried using your Logic its perfect.
But i have an issue , Within the object i have a status field in obj__c and the status field can have values as Terminated or Current.
There is no Status with Total value.
So it is throwing an error at:
While Total here is the combination of Current and Terminated records.
If i can get the Total Records in a map (i.e Combination of Current and Terminated records).
Then i can complete my task.
Please help me out if any solution.
Regards
shaan
What error are you getting? The words 'Total', 'Current', and 'Terminated' are merely keys for an associative array, and so should not present a problem, even though 'Total' is not a field or a status on the Obj__c entity.
Sorry for the earlier post there was no error actually ... there was a mistake from my side. I used the value of key in the map as 'total' instead of 'Total' ( case sensistive) :smileyhappy:.
Any ways thanks for the reply. this is working perfectly now. I am trying to bulid my code as there are many conditions involved here.
Will let you know when its perfectly done.
Thanks a lot.
Regards,
Shaan
Yes, my example code did the same thing, so that was at least partially my fault. But it's useful to know that Maps are always case sensitive, likely because they use a hash-key internally, such as many other languages use to create efficient string key indexing.