You need to sign in to do that
Don't have an account?
Having trouble writing Cross Object Trigger
Hello All,
I am new to writing Apex and am having trouble writing a trigger. I have two Objects 1) Standard Account Object and 2) Sales Reps custom Object. I am attempting to have the trigger update all accounts in which a certain field (SalesRep#) matches the custom object field (rep Id). On the custom object the Owner can change of the rep id. On the standard Object field there is a trigger in place that will update an account correctly once it is edited but not if the Sales rep object changes. I pretty much just need the trigger to fire to update those accounts so the second trigger can fire. But another issue i will have is updating all records which already exist and have this issue currently.
this is what i wrote but does nothing
trigger SalesRepID on SRID__C (before insert, before update){
List<String> SRIDS = New List<String>();
for(SRID__c S : Trigger.new){
if(S.Name != null){
SRIDS.add(S.Name);
}
}
List<Account> AcctList = [SELECT Id FROM Account WHERE SLS_1__C in :SRIDS];
for(integer i = 0 ; i < AcctList.size(); i++){
AcctList[i].SLS_1__c = '0???';
}
update AcctList;
}