You need to sign in to do that
Don't have an account?
uzma khan
How to get all the records from one child object to another child object through the parent object.
i have 3 objects named Book my show,rate detail ,and Rate master where Rate master is parent of Rate detail and book my show with the look up relationship in rate master there is no fields all the feilds are in rate details i need to fetch all the records of rate detail in book my show through rate master ...PLZ help
Like should it be trigger or batch class
It depends on how you've set up the child relatinships, but the simplest way to show child records on a parent is through related lists. You can do this through your Layout on Rate master, and if you have a lookup from rate detail, you can add it as a relatd list.
I'd look at these documents:
yes records are in rate detail and lookup with rate master . i want to fetch the records in BMS through query
do you want to retrieve the records in code? Is this for display on the Rate Master? If so what happens if you have more than one child record, what are you going to display?
I'm assuming your "New Book My Show" is a VF page? If so in your controller on initialise, you can get a list of all the "Rate Detail" children of the "Rate Master" record that is also the parent of this new "Book My Show". So I assume you have the "Rate Master" ID already, you can use a SOQL query to get the "Rate Detail" children in a list. I would use the dates returned and maybe populate a pull down menu in the VF page. That way you only can select a date from the "Rate Details" associated to the "Rate Master" record.
public class BMSRateMaster {
public static void BMSratemaster(list <Book_My_Show__c> newlist){
list <Book_My_Show__c> BMSlist = new list <Book_My_Show__c>();
set <id> BMSid =new set<id>();
list <RateDetail__c> RDlist =new list <RateDetail__c>();
set<id> RDid =new set<id>();
list <Rate_Master__c> RMlist =new list <Rate_Master__c>();
set<id> RMid = new set<id>();
for(Book_My_Show__c B : newlist){
RMid.add(B.Rate_Master__c);
}
RMlist =[select id ,(select From_Date__c,Gold_category__c,Platinum_Category__c,Silver_Category__c,To_Date__c from RateDetails__r) from Rate_Master__c where id IN:RMid];
Map <id ,Rate_Master__c> RateMasterMap = new Map <id ,Rate_Master__c> (Rmlist);
Map<id,list<RateDetail__c>> MApRateDetailtoRateMaster =new Map<id,list<RateDetail__c>> ();
for(Rate_Master__c RM1:RMlist){
MApRateDetailtoRateMaster.put(RM1.id,RM1.RateDetails__r);
}
for (Book_My_Show__c B : newlist) {
Rate_Master__c RMobj=RateMasterMap.get(B.Rate_Master__c);
RDlist = MApRateDetailtoRateMaster.get(B.Rate_Master__c);
for(RateDetail__c r :RDlist){
system.debug(r);
if(B.Select_Date__c == r.From_Date__c && B.Select_Date__c == r.To_Date__c){
system.debug('no..!!! working');
if (B.Category__c == 'gold' ) {
system.debug('gold');
B.Movie_Fare__c=r.Gold_category__c* B.No__c;
}
else if(B.Category__c == 'silver') {
B.Movie_Fare__c =r.Silver_Category__c * B.No__c;
system.debug('silver');
}
else if (B.Category__c== 'Platinum') {
B.Movie_Fare__c =r.Platinum_Category__c * B.No__c;
system.debug('platinum');
}
}
}
} } }
trigger BMS2RateMasterTrigger on Book_My_Show__c (before insert,after insert) {
if(trigger.isinsert && trigger.isbefore){
BMSRateMaster.BMSratemaster (trigger.new);
}
}
but still not working....
The Trigger looks fine
can you check the If condition comparision.
if(B.Select_Date__c == r.From_Date__c &&
B.Select_Date__c== r.To_Date__c)Use System.debug('Book My Show Date'+B.Select_Date__c);
Both The From_Date__c,To_Date__c and B.Select_Date__c should be same.
System.debug(r.From_Date__c );
System.debug(r.To_Date__c);
The ideal way to do it is to use a data loader tool. There are several in the market and some in AppExchange are free.
You would run in the following problems
- Do you have any Circular references?
- How deep (data set, size) is the data
- Triggers and validation rules (do you need to disable them?)
See what fits you need.
Thanks and regards
ravi