You need to sign in to do that
Don't have an account?
Problem in getting parent child records with its associated field
can anyone tell me how to get this hierarchy
Parent Id
ChildID CountOfPickupDays(formula field)...decimal
CHildID CountOfPickupDays
ChildID CountOfPickupDays
Example: By name rather than ID
Caffe Nero Group Ltd Count Of PickUp days Field(Formmula Field)
Caffe Nero = 2
CaffeNero = 1
Starbucks = 0
Caffe Nero Group Ltd = 5
Caffe Nero = 1
i want to get parent Id----->Child IDs-----> All Pickup Days
i have used map for getting parent ID assoiated to its child
Map<Id,List<Id>> servMap = new Map<Id,List<Id>>();
for(Service__c serObj: serviceList){
Id parentAccId = serObj.Customer__r.Grand_Parent_Account__c;
Id AccountId = serObj.Customer__r.id;
if(serObj.Status__c == 'Active'){
if(servMap.get(parentAccId)==null)
{
servMap.put(parentAccId,new list<Id>{AccountId});
}
else
{
servMap.get(parentAccId).add(AccountId);
}
}
got all the child IDs according to parent
now i want to get count of pickup days according to its child ids
Give me some idea
Hi,
From what I understand, you're trying to get the count for a particular child record while you're having the parentid in hand.
If my understanding is right, you can try the below code.
With this, you can get the count as follows if you've the parentAccId.
servMap.get(parentAccId).get(0) -> first child record detail for your parentAccId
childDetails.get(0) -> child record id
childDetails.get(1) -> count
Note: Please validate the code against your api names, as I might be using some random names for unknown attributes.
Thanks,
Anoop
All Answers
What about updating your map to Map<Id, List<List<String>>>?
A sample entry in this collection will look something like this: ParentId (Key) -> ((ChildId, count for child), (ChildId, count for child), (ChildId, count for child)... )
Thanks,
Anoop
actually m not familiar with map<id,list<list<>>>
can u give me some example
and is it proviiding the desired result?
Hi,
From what I understand, you're trying to get the count for a particular child record while you're having the parentid in hand.
If my understanding is right, you can try the below code.
With this, you can get the count as follows if you've the parentAccId.
servMap.get(parentAccId).get(0) -> first child record detail for your parentAccId
childDetails.get(0) -> child record id
childDetails.get(1) -> count
Note: Please validate the code against your api names, as I might be using some random names for unknown attributes.
Thanks,
Anoop
i have implmented ur idea but the problem is
Account ID is ID type and count of pickup days is decimal type field
so how to do that because it is giving error because type of list is ID
Error: Initial expression is of incorrect type, expected: Id
Id AccountId = serObj.Customer__r.id;
Decimal count = serObj.Count_of_Pickup_Days__c; //Added
List<Id> childDetailsList = new List<Id>{AccountId, count};
thanks for ur reply.....
i have implemented it and it works:
:)
but now the next step is
i wanted to Sum that Count value
system debug of servMap:-
i have parent id and corresponding to that i have child ids and their count.......now i want to Sum that value of all count
ANY idea ?
Hi,
I assume that you're trying to calculate the sum of all count for a particular parent id.
If that is the case, you can add a new Map<Id, Integer> to your code as below.
Whenever you want to get the total count for a particular parentId, you can use servCountMap.get(parentId).
Thanks,
Anoop
Oops, forgot that your count is decimal. Please note that I'd used Integer in the above code. If you're using this code, make sure proper type casting is done.
Thanks,
Anoop
Just an afterthought, with all the type casting and complicated collections, doesn't the code look a bit unclean?
For the two requirements you stated above, I think the following code will be a much more cleaner version. :)
Here, note that there will be no calculations involved even if you've multiple Service records with the same Customer record as parent. Another assumption I'd made. :D
Please feel free to share your thoughts on this.
Thanks,
Anoop
thanks anoop for ur reply
i want to show google charts according to date from and date to
so i have created two new fields Date_From__c and Date_To__c
now i want to show them on my visualforce page and in controller coding
can u help me in that
My Vf Page
<apex:page controller="WasteSplit" sidebar="false">
<!-- Google API inclusion -->
<apex:includeScript id="a" value="https://www.google.com/jsapi" />
<apex:sectionHeader title="Google Charts" subtitle="Chart 2"/>
<!-- Google Charts will be drawn in this DIV -->
<div id="chartBlock" style="width: 600px; height: 500px;"/>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.load('visualization', '1', {'packages':['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(initCharts);
function initCharts() {
WasteSplit.WasteSource(
function(result, event){
// load Column chart
var visualization = new google.visualization.PieChart(document.getElementById('chartBlock'));
// Prepare table model for chart with columns
var data = new google.visualization.DataTable();
data.addColumn('string', 'Waste Name');
data.addColumn('number', 'Waste Type');
// add rows from the remoting results
for(var i=0; i<result.length;i++){
var finalBean= result[i];
data.addRow([finalBean.WasteName,finalBean.wastetype]);
}
// all done, lets draw the chart with some options to make it look nice.
visualization.draw(data,{title:'Waste Service Split at Source',legend : {position: 'bottom', textStyle: {color: 'blue', fontSize: 10}}, width:window.innerWidth,vAxis:{textStyle:{color:'red', fontSize: 15}},hAxis:{title: 'Record Count',textStyle:{fontSize: 10},showTextEvery:1,slantedText:true}} );
}, {escape:true});
}
</script>
</apex:page>
cud u tell me where i can locate these two fields so that chart is showing between those dates
Sorry Nisha, doesn't look like something I can help you with. Way beyond my ability it is.
Why don't you put this as a new Board topic, that way you'll make this issue visible to a larger set of people. Someone might be able to help you out.
Thanks,
Anoop