You need to sign in to do that
Don't have an account?
![sandy hello sandy hello](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
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
eg: Year 2020, servicetype - gold which are common on both 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>();
if(trigger.isBefore){
system.debug('trigger before event');
conList = trigger.new;
}else if(trigger.isAfter){
conList=trigger.new;
for(Contact con:conList){
setid.add(con.AccountId);
}
system.debug('setid ' + setid);
List<Account> accList = [Select Id, Name, email__c From Account Where Id=:setid];
if(trigger.isInsert){
for(Contact c1:trigger.new){
for(Account a1:accList){
a1.email__c= c1.email;
update a1;
}
}
}else if(trigger.isupdate){
for(Contact c2:trigger.new){
for(Account a2:accList){
a2.email__c= c2.email;
update a2;
}
}
}
}
}
Thanks
A.Anshi.