function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nitin Sharma 401nitin Sharma 401 

Updating custom object with the contact records from the contact object after email field matches with the email field on the contact object but some issue with it

I have couple of objects and the relationship is as follows

1)Acount
2)Opp
3)contact
4)Planning 
5)Management
 

Account has a ralationmship with the Opp object and planning has a lookup relatiomship with Opp and management has a lookup wiht thr planining

I have created email field on the Management object 

I have trigger on the planning object and from planning I am extracting management reord which are basically copied contacts from the contact object known as special contacts.If more record are added in the contact object I need to match email on the management with email on the contact object and if they match it means management has that record so no need to insert just update that record..If the email does not match then copy that contact object to the management object......Management has no direct relationship  realtionhip withe contact object

Relationship goes like this:- 

Starting backwards from management------Plannnig -----Opp-----Account-----Contact
 
My code is  not complete and I have focussed on after udpate trigger assuning that certain records with thei email address already esists in the Management object and new we gonna update them if the email matches with the email on the contact object


Problem is at the line where I am checking if the email from the contact record exists in the map of Management object.I know email exists in both the objects but it's always giving me null value so please help me out.


trigger UpdateStartegicPlanning on Strategic_planning__c (after update)
{
    set<string>EmailtoLastname=new set<string>();
    set<id>IdofStrategicplan=new set<id>();
    set<id>storeoppIds=new set<id>();
    for(Strategic_planning__c Str:trigger.new)
    {
       
      IdofStrategicplan.add(str.id);  
           
    }
     list<Realtionship_Management__c>ManageRec=([select Key_Contacts_Email_Address__c from Realtionship_Management__c where Strategic_planning__c=:IdofStrategicplan]);
    //might need maoo for the above line
    //
    //        
    
    Map<string,Realtionship_Management__c>must=new Map<string,Realtionship_Management__c>();
    
    for(Realtionship_Management__c Mrecords:ManageRec)
    {
        
        
      must.put(Mrecords.Key_Contacts_Email_Address__c,mrecords);
        
        
    }

for(Strategic_planning__c Check:Trigger.new)
   {
 
       
       
       storeoppIds.add(check.opportunity__c);
            
       
   }
  

    
list<opportunity>newOppIds=[Select id,accountid from opportunity where id in:storeoppIds];
set<id>accountids=new set<id>();
for(opportunity ids:newoppids)
{
accountids.add(ids.accountid);    
system.debug('the account id is'+accountids);   
   
}    
List<account>str=[select id,(select id,Key_Contact_Account_Planning__c,lastname,email from contacts where Key_Contact_Account_Planning__c=true)from account where id in:accountids];
   
list<Realtionship_Management__c>management=new list<Realtionship_Management__c>();

for(Strategic_planning__c plan1:trigger.new)
{
System.debug('The strategic planning id is'+plan1);
for(account s:str)
{
  System.debug('The account info is is'+s);  
    
for(contact contra:s.contacts)
{
    
    if(must.containskey(contra.email))
    {
       system.debug('the email address is');
        //+EmailRelation.containskey(contra.email)); 
    }
    else
    {
        system.debug('the email address is not good');
        
        
    }
     
    
    
}    
}    
}
}    



 





 
Sam KarnSam Karn