Hii Kristiana ,you have to write the trigger both Account and location becouse when you create Recode anywhere(Account/Location) Junction Object Recode shuold be Craeted.
Thanks Bablupublic class accountClassTriggerHandler{
public static void insertAccount(List<Account> lstacc){
List<Junction1__c> lstjunc = New List<Junction1__c>();
for(Account objacc :lstacc){
Junction1__c objjun = New Junction1__c();
objjun.name = 'Test Junction Recode'; // you can map junction object name with account name like objun.name = objacc.name
objjun.Account__c = objacc.Id;
lstjunc.add(objjun);
}
if(lstjunc.size() > 0){
insert lstjunc;
}
}
}
public class LOcationClassTriggerHandler{
public static void insertlocation(List<Location__c> lstloc){
List<Junction1__c> lstjunc = New List<Junction1__c>();
for(Location__c objloc :lstloc){
Junction1__c objjun = New Junction1__c();
objjun.name = 'Test Junction Recode'; // you can map junction object name with account name like objun.name = objloc.name
objjun.location__c = objloc.Id;
lstjunc.add(objloc);
}
if(lstjunc.size() > 0){
insert lstjunc;
}
}
}
trigger AccountTrigger on Account(After insert){
if(Trigger.isInsert && Trigger.isAfter){
accountClassTriggerHandler.insertAccount(Trigger.New);
}
}
trigger LocationTrigger on location__c(After insert){
if(Trigger.isInsert && Trigger.isAfter){
LOcationClassTriggerHandler.insertlocation(Trigger.New);
}
}
1 answer