You need to sign in to do that
Don't have an account?
Vikram Singh 157
Hi Prevent to create Opportunity on the base on account filed value . But this allow to save record
Here Account custom filed id Probhited__c and code is :
trigger ProhibitedOpp1 on Opportunity (before insert) {
List<Opportunity> opps = [Select Id,Account.Prohibited__c From Opportunity Where Id in : Trigger.new];
for (Opportunity opp: opps)
{ if (opp.account.Prohibited__c=='Pakistan') {
opp.adderror('You cannot create an Opportunity from an Account located in a restricted or Pakistan country');
}
}
trigger ProhibitedOpp1 on Opportunity (before insert) {
List<Opportunity> opps = [Select Id,Account.Prohibited__c From Opportunity Where Id in : Trigger.new];
for (Opportunity opp: opps)
{ if (opp.account.Prohibited__c=='Pakistan') {
opp.adderror('You cannot create an Opportunity from an Account located in a restricted or Pakistan country');
}
}
In trigger, if we want to refer parent fields values, we can't do it directly. We have to perform query.
All Answers
In trigger, if we want to refer parent fields values, we can't do it directly. We have to perform query.