• Prerna Agrawal
  • NEWBIE
  • 30 Points
  • Member since 2016

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hello,

How can i do the SOQL query and save the result in utility class and further call the vaules populated in utility class
 
Trigger:

    trigger AccountTrigger on Account(before insert, before update)  
    {
        AccountTriggerHandler handler = new  AccountTriggerHandler();
        
        handler.updateUser(Trigger.new);  // Call method for update account field.

    }

Trigger Handler Class:


    public class AccountTriggerHandler
    {

//TO DO: Do the SOQL Call and store in utility class

           public void updateUser(List<Account> accList)
           {
                  Set<Id> masterIds = new Set<Id>();
                  
                  for(Account accObj : accList)
                  {
                    if(accObj.Master__c != null)
                       masterIds.add(accObj.Master__c);
                  }
            
                    Map<Id,Master__c> masterMap = new Map<Id,Master__c>([Select Id, test_user1__c from Master__c where Id IN : masterIds]);
                     
                     
                  for(Account acct : accList)
                  {
            
                    if(masterMap.containsKey(acct.Master__c))
                    {
                       Master__c masterObj = masterMap.get(acct.Master__c);
                  
                        if(acct.test_user1__c == null)
                
                           acct.test_user1__c = masterObj.test_user1__c;
                    }
                  }
           }
    }

Thank you for suggestion
  • January 06, 2022
  • Like
  • 0
Hello,

How can i do the SOQL query and save the result in utility class and further call the vaules populated in utility class
 
Trigger:

    trigger AccountTrigger on Account(before insert, before update)  
    {
        AccountTriggerHandler handler = new  AccountTriggerHandler();
        
        handler.updateUser(Trigger.new);  // Call method for update account field.

    }

Trigger Handler Class:


    public class AccountTriggerHandler
    {

//TO DO: Do the SOQL Call and store in utility class

           public void updateUser(List<Account> accList)
           {
                  Set<Id> masterIds = new Set<Id>();
                  
                  for(Account accObj : accList)
                  {
                    if(accObj.Master__c != null)
                       masterIds.add(accObj.Master__c);
                  }
            
                    Map<Id,Master__c> masterMap = new Map<Id,Master__c>([Select Id, test_user1__c from Master__c where Id IN : masterIds]);
                     
                     
                  for(Account acct : accList)
                  {
            
                    if(masterMap.containsKey(acct.Master__c))
                    {
                       Master__c masterObj = masterMap.get(acct.Master__c);
                  
                        if(acct.test_user1__c == null)
                
                           acct.test_user1__c = masterObj.test_user1__c;
                    }
                  }
           }
    }

Thank you for suggestion
  • January 06, 2022
  • Like
  • 0
Hi ,

I have a requirement, if user clicks a button order object field should update and display a message on UI. Please let me know how it can be acheived using New button or Link and VisualForce.. Once i click the button on detail page layout I should update the field and display message on UI.
  • January 06, 2022
  • Like
  • 0
how pass encrypted login credentials in the url in salesforce ?