+ Start a Discussion
Deepak G 9Deepak G 9 

On User object whenever status is TRUE I need to display user information while updating lookup fields on opportunity objects using Trigger

Hi All,  
On User object whenever status is TRUE I need to display user information while updating lookup fields on opportunity objects using Trigger
 Eg: product1 ....lookup
     product@ ....lookup
 
trigger psr_update_createdby on Opportunity (before insert, before update) 
{
    List<Id> USR_id = new List<Id>(); 
    Map<Id, String> Usr_Role = new Map<Id, String>();
 
    for(Opportunity Opp: Trigger.new)
    {
    if(Opp.Qualified_By__c!=NULL)
      {
      
      }
      
    }        
  }

please help

Regards.
Deepak
rajat Maheshwari 6rajat Maheshwari 6
Hi Deepak,

Below is code as per your use case : - 
trigger psr_update_createdby on Opportunity (before insert, before update) 
{
   Set<Id> USR_id = new Set<Id>(); 
 
  Map<Id,User> mp_User= new Map<Id,User>();

  for(Opportunity Opp: Trigger.new)
    {
    if(Opp.Qualified_By__c!=NULL)
      {
         USR_id.add(Qualified_By__c);
      }
      
    }      

for(User u : [Select Id,Name,Fields from User where Id IN : USR_id])
    {
      mp_User.put(u.id,u);
     }

for(Opportunity opp : Trigger.new)
  {
     if(mp_User!=null && mp_User.containsKey(opp.Qualified_By__c))
       {

          // here you can populate fields of user to opportunity
            
              opp.UserInfo = mp_User.get(opp.Qualified_By__c).Info;
       }
  }





  
  }

Please let me know, in cas eof any help :)

Thanks
Rajat maheshwari
rajatzmaheshwari@gmail.com
rajat Maheshwari 6rajat Maheshwari 6

Hi Deepak,

Does your issue get solved ?

Please let me know about the same, You can contact with me at my email Id also : - rajatzmaheshwari@gmail.com

Thanks
Rajat maheshwari