I have built following apex trigger code and isAfter
code is not executing because I have used recursive method in this trigger.
Is it possible to run isAfter
while trigger call first time ?
Please see below code apex trigger code and please tell me what I have did wrong in this code :
trigger CreateOrderForOpportunity on Opportunity (before insert, after insert) {
Map<ID,Schema.RecordTypeInfo> rt_Map = Opportunity.sObjectType.getDescribe().getRecordTypeInfosById();
if(checkRecursive.checkOneTime()){
//Map<ID,Schema.RecordTypeInfo> rt_Map = Opportunity.sObjectType.getDescribe().getRecordTypeInfosById();
for(Opportunity opp : trigger.New){
if(rt_map.get(opp.recordTypeID).getName().contains('CONECTIVIDAD') && opp.Coming_from_Portal__c == True){
if(trigger.isBefore){
if(opp.Owner_Email_Address_coming_from_portal__c != Null){
List<user> uList = [select Id, Email from user where Email =: opp.Owner_Email_Address_coming_from_portal__c Limit 1];
if(uList.size() > 0)
opp.OwnerId = uList.get(0).Id;
}
if(opp.Portal_Account_Name__c != Null){
List<Account> AccList = [select Id, Name from Account where Name =: opp.Portal_Account_Name__c Limit 10000];
if(AccList.size() > 0){
opp.AccountId = AccList.get(0).Id;
}
}
}
}
}
}
for(Opportunity oppAfter : trigger.New){
if(rt_map.get(oppAfter.recordTypeID).getName().contains('CONECTIVIDAD') && oppAfter.Coming_from_Portal__c == True){
if(trigger.isAfter){
SBQQ__Quote__c quote = new SBQQ__Quote__c();
quote.Quote_Type__c = 'Final';
quote.SBQQ__Opportunity2__c = oppAfter.Id;
quote.Requerimientos_del_cliente__c = 'PORTAL';
quote.Primary_Contact__c = [Select Id from Contact where AccountId =: oppAfter.AccountId Order By createdDate Limit 1].Id;
insert quote;
if(oppAfter.Quote_line_Product_Name__c != Null){
for(Product2 p : [select Id, Name from Product2 where Name =: oppAfter.Quote_line_Product_Name__c]){
SBQQ__QuoteLine__c qli = new SBQQ__QuoteLine__c();
qli.SBQQ__Product__c = p.Id;
qli.SBQQ__SpecialPrice__c = oppAfter.Product_Special_Price_coming_from_portal__c;
qli.SBQQ__Quote__c = quote.Id;
insert qli;
}
}
SBQQ__QuoteLine__c qliNew = new SBQQ__QuoteLine__c();
qliNew.SBQQ__Product__c = '01t7000000Wt7xj';
qliNew.SBQQ__Quote__c = quote.Id;
insert qliNew;
}
}
}
}
Recursive Class :
public Class checkRecursive{
private static boolean check = true;
public static boolean checkOneTime(){
if(check){
check = false;
return true;
}
else{
return check;
}
}
}
checkRecursive.checkOneTime()
method