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
sandy hellosandy hello 

Using before update apex trigger how to retrieve values from other object "B" based on year and service type fields on object "A" and update revenue value on Object "A"

I want to retreive value revenue from Object "B" based on input values year and servicetype fields which or common on both objects "A"  & "B" and there is no relationship between both objects, and update revenue value on Object "A"

eg: Year 2020, servicetype - gold which are common on both objects   
Hi sandy ,based on your requirement  you can try below code by modifying ur objects.

trigger updaterecords on Contact (before insert, before update, after insert, after update) {

List<Contact> conList =new List<Contact>();
    Set<Id> setid = new  Set<Id>();
        system.debug('trigger before event');
        conList =;
    }else if(trigger.isAfter){;
        for(Contact con:conList){
        system.debug('setid ' + setid);
        List<Account> accList = [Select Id, Name, email__c From Account  Where Id=:setid];     
                 for(Account a1:accList){
                     update a1;
        }else if(trigger.isupdate){
                for(Account a2:accList){
                    update a2;

AbhinavAbhinav (Salesforce Developers) 
Iterate Object A Trigger.old or Trigger.New Value-------> Store common field value in a list-----> Query on object B with common field in where clause with value stored in list.