You need to sign in to do that
Don't have an account?
Subrat kumar Ray
Automatically create opportunitycontactrole with insertion of opportunity in apex
I have a trigger that is checking whether an opportuniycontactrole is created when opportunity is inserted.
trigger OpptyCheck on Opportunity (after insert) {
List<OpportunityContactRole> oppContRoleList = [Select id, ContactId, OpportunityId from OpportunityContactRole Where OpportunityId IN :trigger.New];
for(Opportunity opp : trigger.New){
flag = false;
for(OpportunityContactRole oppRole : oppContRoleList){
if((oppRole.OpportunityId == opp.Id){
flag=true;
}
}
if(!Flag){
opp.addError('No Active Contact Present. Add an active Contact.');
}
}
}
Problem I am facing now is, whenever trying to insert opp this trigger prevents from insertion.
[except creating opp from contact where opportunitycontactrole will simulatneously created because in url 'ConId' property will hold value of contact ]
Please suggest how to insert an oppty from apex class.
Thanks.
trigger OpptyCheck on Opportunity (after insert) {
List<OpportunityContactRole> oppContRoleList = [Select id, ContactId, OpportunityId from OpportunityContactRole Where OpportunityId IN :trigger.New];
for(Opportunity opp : trigger.New){
flag = false;
for(OpportunityContactRole oppRole : oppContRoleList){
if((oppRole.OpportunityId == opp.Id){
flag=true;
}
}
if(!Flag){
opp.addError('No Active Contact Present. Add an active Contact.');
}
}
}
Problem I am facing now is, whenever trying to insert opp this trigger prevents from insertion.
[except creating opp from contact where opportunitycontactrole will simulatneously created because in url 'ConId' property will hold value of contact ]
Please suggest how to insert an oppty from apex class.
Thanks.
Can you explain a bit more what you are tryting to acomplish?