+ Start a Discussion
uzma khanuzma 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
 
suresh sanneboina 4suresh sanneboina 4
Are the records already there in the objects or should it be for future records.

Like should it be trigger or batch class
Tammer SalemTammer Salem
Hello Uzma,
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:
uzma khanuzma khan
HI suresh ,

yes records are in rate detail and lookup with rate master . i want to fetch the records in BMS through query
 
Tammer SalemTammer Salem
Hi Uzma,
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?
uzma khanuzma khan
User-added image this book my show  if i select date it should take data from rate master according to rate master though i have rate detail lookup to but dont want data from thr User-added image this rate master and parent of BMS and Rate detailUser-added imagein this i have RD1 ,RD2 and RD3 records with different dates . so when i select date in book my show it should take all the data according to date in rate detail.
Tammer SalemTammer Salem
So if I understnad correctly - in the "book my show" edit screen, you want the date from the "Rate Detail". And they are both Children of "Rate Master". So that means you want to be able to display all the "Rate Detail" dates that are related to that "Rate Master" and select one?

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.
uzma khanuzma khan
yes i m doing it in this way but still not getting ... 





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');
                    }
            }
                
            }
            
        } } }
suresh sanneboina 4suresh sanneboina 4
the code looks good. When the trigger is fired? It should be before insert/update.
uzma khanuzma khan
Trigger code :

trigger BMS2RateMasterTrigger on Book_My_Show__c (before insert,after insert) {

    if(trigger.isinsert && trigger.isbefore){
    BMSRateMaster.BMSratemaster (trigger.new);

    }
    
    
    
}


but still not working....
 
suresh sanneboina 4suresh sanneboina 4
Hi,

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);
 



 
Vishnu Datla 13Vishnu Datla 13
Hi Uzma, 

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.
 
ravi teja 118ravi teja 118
uzma Khan can u tell me how to get city name and store from ip adresss based on the user who visited the site 

Thanks and regards 
ravi