I have a custom object called 'BidManager_Bid__c'. On this object, I created an External Lookup field called 'Global_Opportunity__c' that reference to the external object called 'Opportunity__x'.
I want to write a trigger on the 'BidManager_Bid__c' object and fetch the field 'Amount__c' from the parent 'Opportunity__x' record. Following is my code:
Trigger:
trigger BidManager_Trigger on BidManager_Bid__c (after update, after insert) {
if(Trigger.isInsert || Trigger.isUpdate) {
BidManagerTriggerHandler.getGlobalOpportunityInfo(Trigger.New);
}
}
Apex:
public class BidManagerTriggerHandler {
public static void getGlobalOpportunityInfo(List<BidManager_Bid__c> getInfo) {
Id globalOpp;
for (BidManager_Bid__c bm : getInfo) {
globalOpp = bm.Global_Opportunity__c;
}
Opportunity__x globalOppAmount = [Select Id, Amount__c From Opportunity__x WHERE ExternalId =: globalOpp];
system.debug(globalOppAmount.Amount__c);
}
}
I could save the trigger and the class but when I try to update a record, it gives me the following error:
BidManager_Trigger: execution of AfterUpdate caused by: System.UnexpectedException: Apex triggers can't reference external objects or call out to external data sources. Contact your administrator for help. Class.BidManagerTriggerHandler.getGlobalOpportunityInfo: line 11, column 1 Trigger.BidManager_Trigger: line 4, column 1