+ Start a Discussion
Manoprabha PalpandianManoprabha Palpandian 

ustom Object - AirTravel, Fields - Arrival and Departure Datatype- Picklist. Custom Object - Hotel, Fields - Check In Date and Check Out Date Datatype- Picklist. These two custom objects lookup with Registraton1__c.

Best Answer chosen by Manoprabha Palpandian
Suraj Tripathi 47Suraj Tripathi 47
Hi Manoprabha,

Check this code:-
trigger updateParent on hotel__c(after insert,after update){
   map<id, hotel__c> hotelMap= new map< id, hotel__c>([select checkindate__c,checkoutdate__c,registration1__c from hotel__c where id IN: trigger.new]);
   set<id> sid= new set<id>();
    for(hotel__c hotel: trigger.new){
       if(hotel.registration1__c!=null){
          sid.add(hotel.registration1__c);//lookup field with AirTravel object
       }
    }
List<AirTravel__c> updateairtravel= new List<AirTravel__c>();
  List<AirTravel__c> airtravel= new List<AirTravel__c>();
  airtravel=[select arrival__c,departure__c from AirTravel__c where id IN: sid];
  for(AirTravel__c air: airtravel){
      for(hotel__c ho:hotelMap.values()){
        if(air.id==ho.registration1__c){
          air.arrival__c=ho.checkindate__c;
          air.departure__c= ho.checkoutdate__c;
          updateairtravel.add(air);
       }
    }
  }
 if(updateairtravel.size()>0){
   update updateairtravel;
  }
}

In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 

All Answers

Suraj Tripathi 47Suraj Tripathi 47
Hi Manoprabha,

Check this code:-
trigger updateParent on hotel__c(after insert,after update){
   map<id, hotel__c> hotelMap= new map< id, hotel__c>([select checkindate__c,checkoutdate__c,registration1__c from hotel__c where id IN: trigger.new]);
   set<id> sid= new set<id>();
    for(hotel__c hotel: trigger.new){
       if(hotel.registration1__c!=null){
          sid.add(hotel.registration1__c);//lookup field with AirTravel object
       }
    }
List<AirTravel__c> updateairtravel= new List<AirTravel__c>();
  List<AirTravel__c> airtravel= new List<AirTravel__c>();
  airtravel=[select arrival__c,departure__c from AirTravel__c where id IN: sid];
  for(AirTravel__c air: airtravel){
      for(hotel__c ho:hotelMap.values()){
        if(air.id==ho.registration1__c){
          air.arrival__c=ho.checkindate__c;
          air.departure__c= ho.checkoutdate__c;
          updateairtravel.add(air);
       }
    }
  }
 if(updateairtravel.size()>0){
   update updateairtravel;
  }
}

In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 
This was selected as the best answer
Manoprabha PalpandianManoprabha Palpandian
public class Registrationcontroller {
    public Registration1__c reg1 {get;set;}
    public String editid {get;set;}
    public Registrationcontroller()
    {
        reg1 = new Registration1__c();
     }
      public List<Registration1__c> getregisterlist(){
        List<Registration1__c> listreg= new List<Registration1__c>();
        listreg=[SELECT Id, Name, FirstName__c, LastName__c, Email__c, (SELECT id,name FROM Hotels__r),
                 (SELECT id,name FROM AirTravels__r) FROM Registration1__c];
        return listreg;
     }
    public void editfunction() {
        system.debug('editfunction inside===>'+editid);
        reg1=[SELECT Id, Name, FirstName__c, LastName__c, Email__c FROM Registration1__c where id=:editid];
    }
    public void deletefunction() {
        system.debug('editfunction inside===>'+editid);
        List<Registration1__c>  reg2=[SELECT Id, Name, FirstName__c, LastName__c, Email__c FROM Registration1__c where id=:editid];
        
        delete reg2;
        ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.INFO,'Record deleted successfully'));
    }
    public void saveaction()
    {
        system.debug('saveaction inside===>'+reg1);
        try{
            upsert reg1;
            Hotel__r.Registration__c=reg1.01I5g000001paEN;
            AirTravel__r.Registration__c=reg1.01I5g000001paGd;
            if(reg1.Id !=null){
                ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.INFO,'Record saved successfully'));
                reg1 = new Registration1__c();
           } else
            {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.SEVERITY.ERROR,'Record not saved')); 
            }
        }
        Catch(Exception e)  
        {
            System.debug(e.getMessage());
        }
    }
}





<apex:page controller="Registrationcontroller" id="theRepeat" sidebar="false" showHeader="true">
    <apex:form >
        <apex:pageBlock >
            <apex:messages />
            <apex:pageBlockSection columns="1" >
                <apex:inputField label="FirstName" value="{!reg1.FirstName__c}"/>
                <apex:inputField label="LastName" value="{!reg1.LastName__c}"/>
                <apex:inputField label="Email" value="{!reg1.Email__c}"/>
            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="save" action="{!saveaction}" rerender="pg1,theTable" />
            </apex:pageBlockButtons> 
        </apex:pageBlock>
        <apex:pageBlock >
            <apex:dataTable value="{!registerlist}" var="regvalue" id="theTable" width="100%">
                <apex:facet name="caption">Registration List</apex:facet>
                <apex:column headerValue="Reg ID"><apex:outputText value="{!regvalue.Name}" /> </apex:column>
                <apex:column headerValue="FirstName"><apex:outputText value="{!regvalue.FirstName__c}" /> </apex:column>
                <apex:column headerValue="LastName"><apex:outputText value="{!regvalue.LastName__c}" /> </apex:column>
                <apex:column headerValue="Email"><apex:outputText value="{!regvalue.Email__c}" /> </apex:column>
                
                    <apex:repeat value="{!regvalue.Hotels__r}" var="c">
                        <apex:column value="{!c.Name}"/>
                    </apex:repeat>
                    <apex:repeat value="{!regvalue.AirTravels__r}" var="d">
                        <apex:column value="{!d.Name}"/>
                    </apex:repeat>
               
                <apex:column >
                    <apex:commandLink value="Edit" action="{!editfunction}" rerender="pg1">
                        <apex:param name="cid" value="{!regvalue.id}" assignto="{!editid}"/>
                    </apex:commandLink> || 
                    <apex:commandLink value="Delete" action="{!deletefunction}" rerender="pg1,theTable">
                        <apex:param name="cid" value="{!regvalue.id}" assignto="{!editid}"/>
                    </apex:commandLink> 
                </apex:column>    
            </apex:dataTable>
        </apex:pageBlock>
    </apex:form>         
</apex:page>





how to update my lookup fields in this code after the registration record saved and display the lookup customobject

AirTravel and Hotel custom objects lookup with Registration__c.
custom Object - AirTravel, Fields - Arrival and Departure Datatype- Picklist, AirCommands datatype= Textarea(long). Custom Object - Hotel, Fields - Check In Date and Check Out Date Datatype- Picklist, HotelCommands datatype= Textarea(long).
how to update the record


 
Manoprabha PalpandianManoprabha Palpandian
please can anyone helpme
Manoprabha PalpandianManoprabha Palpandian
suraj  helpme
 
Manoprabha PalpandianManoprabha Palpandian
please anyone help me to solve the above code