• Suman Bonthala
  • NEWBIE
  • 30 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 3
    Replies

public class controllerActionSupport{

    public string accid {get; set;}
    public List<Contact> SelectedAcc{get;set;}
    
    public list<selectoption> getaccountnames() {
        
        list<selectoption> accoptions = new list<selectoption>();
        accoptions.add(new selectoption('None', '--Select Account--'));
        for (account acc : [select id, name from account]){
            accoptions.add(new selectoption(acc.id, acc.name));
        }  
        return accoptions;
    } 
    
    public void  getDetails() {
        
        SelectedAcc = new List<Contact>();
        SelectedAcc = [SELECT id, FirstName, Email FROM Contact WHERE AccountId=:accid ];
        
    }
}
Trigger NoRelation on Candidate__c(After Insert,After Update)
{

    List<Candidate__c> updcanlist= new List<Candidate__c>();
    if(Utility.flag!=true)
    {
        map<Id,Id> canmap= new map<Id,Id>();
        for(Candidate__c c:trigger.new)
        {
            canmap.put(c.Id,c.Opportunity_Relation__c);
        }
        map<Id,string> oppmap= new map<Id,string>();
        List<opportunity> opplist= [Select id,name,Emp_Number__c from opportunity where Id IN:canmap.values()];
        for(opportunity opp:opplist)
        {
            oppmap.put(opp.Id,opp.Emp_Number__c);
        }
        map<string,Id> empmap= new map<string,Id>();
        List<Employee__c> emplist= [Select id,name,Emp_Number__c from Employee__c where Emp_Number__c IN:oppmap.values()];
        for(Employee__c emp:emplist)
        {
            empmap.put(emp.Emp_Number__c,emp.Id);
        }
        List<Candidate__c> canlist=[select id,name,Opportunity_Relation__c,Emp_RecordID__c from Candidate__c where Id IN:canmap.keyset()];
        for(Candidate__c can:canlist)
        {
            Candidate__c  c= new Candidate__c();
            c.Id=can.Id;
            c.Emp_RecordID__c=empmap.get(oppmap.get(can.Opportunity_Relation__c));
            
            updcanlist.add(c);
        }
    }
    Utility.flag=true;
    if(updcanlist.size()>0)
    {
        update updcanlist;
    }


}
//1.its not changing address in contact automatically
trigger trgbillingupdate on Account(after update)
{
  List<Contact> colistupdate = new list<Contact>();
  
   for(Account a :[select id,name,billingstreet,(select id,name,accountid,otherstreet from Contacts)from Account where id IN:trigger.new])
   {
      if(trigger.oldmap.get(a.id).billingstreet!=a.billingstreet)
      {
       Contact c = new Contact();
       c.accountid = a.id;
       c.otherstreet = a.billingstreet;
       colistupdate.add(c);
      }

   }
  update colistupdate;
 }


//2
trigger trgotherstreetdate on Contact(before update)
 {
 
 
   for(Contact c :[select id,name,otherstreet,Account.id,Account.name,Account.billingstreet from Contact where id IN:trigger.new])
   {
     if(trigger.oldmap.get(c.id).otherstreet!= c.otherstreet)
      {
       Account a = new Account();
       a.id=c.id;
       a.billingstreet=c.otherstreet;
       update a;
     }
   
   }
 }
//Opportunity is parent and Customer Project is chlid 
trigger trgcpundelete on Opportunity(after undelete)
 {
     set<id>oppid= new set<id>();
     if(trigger.isafter&&trigger.isundelete)
      {
         for(Opportunity o : trigger.new)
         {
          oppid.add(o.id);
         }
      }  
     list <Customer_Project__c> cplist = [select id,name,Opp_relation__c from Customer_Project__c where isdeleted=true and Opp_relation__c IN:oppid];
     undelete cplist;
}

//if i undelete opportunity the child records doesnot undelete
trigger trgcpundelete on Opportunity(after undelete)
 {
     set<id>oppid= new set<id>();
     if(trigger.isafter&&trigger.isundelete)
      {
         FOR(Opportunity o : trigger.new)
         {
          oppid.add(o.id);
         }
      }  
     list <Customer_Project__c> cplist = [select id,name,Opp_relation__c from Customer_Project__c where isdeleted=true and Opp_relation__c IN:oppid];
     undelete cplist;
}
//1.its not changing address in contact automatically
trigger trgbillingupdate on Account(after update)
{
  List<Contact> colistupdate = new list<Contact>();
  
   for(Account a :[select id,name,billingstreet,(select id,name,accountid,otherstreet from Contacts)from Account where id IN:trigger.new])
   {
      if(trigger.oldmap.get(a.id).billingstreet!=a.billingstreet)
      {
       Contact c = new Contact();
       c.accountid = a.id;
       c.otherstreet = a.billingstreet;
       colistupdate.add(c);
      }

   }
  update colistupdate;
 }


//2
trigger trgotherstreetdate on Contact(before update)
 {
 
 
   for(Contact c :[select id,name,otherstreet,Account.id,Account.name,Account.billingstreet from Contact where id IN:trigger.new])
   {
     if(trigger.oldmap.get(c.id).otherstreet!= c.otherstreet)
      {
       Account a = new Account();
       a.id=c.id;
       a.billingstreet=c.otherstreet;
       update a;
     }
   
   }
 }
//Opportunity is parent and Customer Project is chlid 
trigger trgcpundelete on Opportunity(after undelete)
 {
     set<id>oppid= new set<id>();
     if(trigger.isafter&&trigger.isundelete)
      {
         for(Opportunity o : trigger.new)
         {
          oppid.add(o.id);
         }
      }  
     list <Customer_Project__c> cplist = [select id,name,Opp_relation__c from Customer_Project__c where isdeleted=true and Opp_relation__c IN:oppid];
     undelete cplist;
}

//if i undelete opportunity the child records doesnot undelete
trigger trgcpundelete on Opportunity(after undelete)
 {
     set<id>oppid= new set<id>();
     if(trigger.isafter&&trigger.isundelete)
      {
         FOR(Opportunity o : trigger.new)
         {
          oppid.add(o.id);
         }
      }  
     list <Customer_Project__c> cplist = [select id,name,Opp_relation__c from Customer_Project__c where isdeleted=true and Opp_relation__c IN:oppid];
     undelete cplist;
}