You need to sign in to do that
Don't have an account?
Lisa Horne
Trigger Error Help!
I am getting this error on a legacy trigger. Could someone please help with this one?
Contract_Update_Before_After_Update: execution of AfterUpdate
caused by: System.AsyncException: Future method cannot be called from a future or batch method: Account_Contract_Update_Class.UpdateAccounts(SET<Id>, String)
Trigger.Contract_Update_Before_After_Update: line 147, column 1 : CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY ()
trigger Contract_Update_Before_After_Update on Contract (after update, before update)
{
system.debug('Update TRIGGER FIRSTRUN VARIABLE: ' + Account_Contract_Update_Class.FirstRun);
list<Contract> TheseContracts = new list<Contract>();
if(Global_Apex_Calls_Class.FireTriggers == true && Global_Apex_Calls_Class.FireGeoCode == true)
{
//Query all possible Product Families from Products and put into list
//Important Product Families should match the API name of Product in Amount fields
//Get describe of all possible picklist values
list<Schema.PicklistEntry> ProductFamily_Values = Product2.Family.getDescribe().getPickListValues();
list<String> ProductFamilies = new list<string>();
//Loop through all Product Family values from picklist. Get Label of picklist from each value and add to list of ProductFamilies
string FamilyName = null;
for(integer i = 0; i<ProductFamily_Values.size(); i++)
{
FamilyName =string.valueof(ProductFamily_Values[i].getLabel());
FamilyName = FamilyName.Replace(' ','_');
ProductFamilies.add(FamilyName);
}
if(Account_Contract_Update_Class.FirstRun == true)
{
//Account_Contract_Update_Class.FirstRun = false;
system.debug('Trigger Is Update: ' + Trigger.isUpdate);
system.debug('Trigger is Insert: ' + Trigger.isInsert);
if(Trigger.isInsert == false)
{
system.debug('CONTRACT TRIGGER ACTIVATED!');
String ObjectDMLType ='ContractBefore';
//Create Set of IDs for Account and Contract Objects on the updated and inserted Contract Products
set<ID> TheseContractIDs = new set <ID>(); //set of Contract IDs for all Contract Products.
//These Contracts will need to be updated by checking all their Contract Products
set<ID> TheseAccountIDs = new set<id>(); //Set of Account IDs that have Contract Products.
//These Accounts Need to be updated by checking All their active Contract Products
for(Contract c : Trigger.New)
{
//Add This Contract ID to set TheseContractIDs
TheseContractIDs.add(c.id);
//Add This Account ID to set TheseAccountIDs
TheseAccountIDs.add(c.AccountID);
TheseContracts.add(c);
}
//THIS IS A TEST TO UPDATE THE CONTRACTS ONLY
system.debug('CONTRACTS SENT TO CLASS: ' + TheseContractIds);
if(Trigger.isBefore)
{
system.debug('Contract Update Trigger IS BEFORE!!');
list<Contract> FromClass = new list<Contract>();
//FromClass = Account_Contract_Update_Class.UpdateContracts(TheseContractIDs, ObjectDMLType);
Account_Contract_Update_Class.UpdateContracts_Trigger(TheseContracts, ObjectDMLType);
//system.debug('RETURN FROM CLASS: ' + FromClass);
system.debug('RETURN FROM CLASS: ' + FromClass);
//system.assert(false,'After class!: '+ FromClass.size());
}
/*
if(FromClass != null && FromClass.size() > 0)
{
map<id, Contract> mFromClass = new map<id,Contract>();
for(Contract c : FromClass)
{
mFromClass.put(c.id,c);
}
Contract cFromClass = null;
//Variables for Contract Loop
String RecurringField = '_Total_Recuring_Amount__c';
string NonRecurringField = '_Total_Non_Recurring_Amount__c';
Object O = null; //Variable of field object that we can get the value of field name
//Build map of all fields on Contract
Map<String, Schema.SObjectField> mFields = new Contract().getSobjectType().getDescribe().fields.getMap();
//Dynamic Apex variables.
sObject delegate; //Contract active in loop
sObject FromDelegate;
Schema.SobjectField f; //Field in contract being updated
string FieldName = null; //Field API name. Used to get Field from mFields (Field Map)
for(integer i=0;i<Trigger.new.size();i++)
{
RecurringField = '_Total_Recurring_Amount__c'; //Standard Ending. FieldName format is *Product*_Total_Recurring_Amount__c
NonRecurringField = '_Total_Non_Recurring_Amount__c';//Standard Ending. FieldName format is *Product*_Total_Non_Recurring_Amount__c
cFromClass = null;
cFromClass = mFromClass.get(Trigger.new[i].id);
//for(integer v=0; i<FromClass.size();v++)
//{
//if(Trigger.new[i].id == FromClass[v].id)
if(cFromClass != null)
{
system.debug('Contract From Class - S797 Total Recurring Amount: ' + cFromClass.Simplifi_797_Total_Recurring_Amount__c);
system.debug('Contract From Class - S797 Total Recurring Amount: ' +Trigger.new[i].Simplifi_797_Total_Recurring_Amount__c);
FromDelegate = cFromClass;
delegate = Trigger.new[i]; //Set the current contract in loop to the delegate sObject
//Loop through Products
for(integer p=0; p<ProductFamilies.size(); p++)
{
//Default Recurring Field
FieldName = ProductFamilies[p] + RecurringField; //Build API name for field
f = mFields.get(FieldName); //Get the field from map of fields based on API Name
system.debug('Default field: ' + FieldName);
//Check to see if F is null. Null means field does not exist
if(f != null)
{
O = FromDelegate.get(f);
delegate.put(f, O); //Set the value of the field to 0
}
//Default Non Recurring Field
FieldName = ProductFamilies[p] + NonRecurringField; //Build API name for field
f = mFields.get(FieldName); //Get the field from map of fields based on API Name
//Check to see if F is null. Null means field does not exist
if(f != null)
{
O = FromDelegate.get(f);
delegate.put(f, O); //Set the value of the field to 0
}
//End Prodct Family Loop
}
//End Trigger and Class Match
}
//End FromClass Loop
//}
system.debug('Yearly Revenue: ' + Trigger.new[i].yearly_revenue__c);
system.debug('Products on Contract: ' + Trigger.new[i].Products_included_in_Contract__c);
//system.assert(Trigger.new[i].Products_included_in_Contract__c != '', 'PRODUCT LIST NOT UPDATED!');
//system.assert(Trigger.new[i].simplifi_797_Amount__c > 0, 'Product Amount Not Updated!');
//end Trigger Loop
}
//end If Existing FromClass
}
}
*/
if(Trigger.isAfter)
{
system.debug('Contract Update Trigger IS AFTER!!');
/*Information to update Accounts */
list<Contract_Product__c> TheseProducts = [Select c.Total_Price__c, c.Sale_Type__c, c.Quantity__c, c.Product_Family__c,
c.New_Client__c, c.Name, c.Id, c.Exception__c, c.Discount__c, c.Contract__c, c.Contract_Product__c,
c.Annual_Price__c, c.Annual_List_Price__c, c.Account__c From Contract_Product__c c where c.Contract__c in :TheseContractIds];
if(TheseProducts != Null && TheseProducts.size() >0)
{
for(Contract_Product__c cp : TheseProducts)
{
TheseAccountIds.add(cp.Account__c);
}
Account_Contract_Update_Class.UpdateAccounts(TheseAccountIDs, ObjectDMLType);
}
}
}
//FirstRun IF statement
}
//Trigger global test
}
//last brackett
}
Contract_Update_Before_After_Update: execution of AfterUpdate
caused by: System.AsyncException: Future method cannot be called from a future or batch method: Account_Contract_Update_Class.UpdateAccounts(SET<Id>, String)
Trigger.Contract_Update_Before_After_Update: line 147, column 1 : CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY ()
trigger Contract_Update_Before_After_Update on Contract (after update, before update)
{
system.debug('Update TRIGGER FIRSTRUN VARIABLE: ' + Account_Contract_Update_Class.FirstRun);
list<Contract> TheseContracts = new list<Contract>();
if(Global_Apex_Calls_Class.FireTriggers == true && Global_Apex_Calls_Class.FireGeoCode == true)
{
//Query all possible Product Families from Products and put into list
//Important Product Families should match the API name of Product in Amount fields
//Get describe of all possible picklist values
list<Schema.PicklistEntry> ProductFamily_Values = Product2.Family.getDescribe().getPickListValues();
list<String> ProductFamilies = new list<string>();
//Loop through all Product Family values from picklist. Get Label of picklist from each value and add to list of ProductFamilies
string FamilyName = null;
for(integer i = 0; i<ProductFamily_Values.size(); i++)
{
FamilyName =string.valueof(ProductFamily_Values[i].getLabel());
FamilyName = FamilyName.Replace(' ','_');
ProductFamilies.add(FamilyName);
}
if(Account_Contract_Update_Class.FirstRun == true)
{
//Account_Contract_Update_Class.FirstRun = false;
system.debug('Trigger Is Update: ' + Trigger.isUpdate);
system.debug('Trigger is Insert: ' + Trigger.isInsert);
if(Trigger.isInsert == false)
{
system.debug('CONTRACT TRIGGER ACTIVATED!');
String ObjectDMLType ='ContractBefore';
//Create Set of IDs for Account and Contract Objects on the updated and inserted Contract Products
set<ID> TheseContractIDs = new set <ID>(); //set of Contract IDs for all Contract Products.
//These Contracts will need to be updated by checking all their Contract Products
set<ID> TheseAccountIDs = new set<id>(); //Set of Account IDs that have Contract Products.
//These Accounts Need to be updated by checking All their active Contract Products
for(Contract c : Trigger.New)
{
//Add This Contract ID to set TheseContractIDs
TheseContractIDs.add(c.id);
//Add This Account ID to set TheseAccountIDs
TheseAccountIDs.add(c.AccountID);
TheseContracts.add(c);
}
//THIS IS A TEST TO UPDATE THE CONTRACTS ONLY
system.debug('CONTRACTS SENT TO CLASS: ' + TheseContractIds);
if(Trigger.isBefore)
{
system.debug('Contract Update Trigger IS BEFORE!!');
list<Contract> FromClass = new list<Contract>();
//FromClass = Account_Contract_Update_Class.UpdateContracts(TheseContractIDs, ObjectDMLType);
Account_Contract_Update_Class.UpdateContracts_Trigger(TheseContracts, ObjectDMLType);
//system.debug('RETURN FROM CLASS: ' + FromClass);
system.debug('RETURN FROM CLASS: ' + FromClass);
//system.assert(false,'After class!: '+ FromClass.size());
}
/*
if(FromClass != null && FromClass.size() > 0)
{
map<id, Contract> mFromClass = new map<id,Contract>();
for(Contract c : FromClass)
{
mFromClass.put(c.id,c);
}
Contract cFromClass = null;
//Variables for Contract Loop
String RecurringField = '_Total_Recuring_Amount__c';
string NonRecurringField = '_Total_Non_Recurring_Amount__c';
Object O = null; //Variable of field object that we can get the value of field name
//Build map of all fields on Contract
Map<String, Schema.SObjectField> mFields = new Contract().getSobjectType().getDescribe().fields.getMap();
//Dynamic Apex variables.
sObject delegate; //Contract active in loop
sObject FromDelegate;
Schema.SobjectField f; //Field in contract being updated
string FieldName = null; //Field API name. Used to get Field from mFields (Field Map)
for(integer i=0;i<Trigger.new.size();i++)
{
RecurringField = '_Total_Recurring_Amount__c'; //Standard Ending. FieldName format is *Product*_Total_Recurring_Amount__c
NonRecurringField = '_Total_Non_Recurring_Amount__c';//Standard Ending. FieldName format is *Product*_Total_Non_Recurring_Amount__c
cFromClass = null;
cFromClass = mFromClass.get(Trigger.new[i].id);
//for(integer v=0; i<FromClass.size();v++)
//{
//if(Trigger.new[i].id == FromClass[v].id)
if(cFromClass != null)
{
system.debug('Contract From Class - S797 Total Recurring Amount: ' + cFromClass.Simplifi_797_Total_Recurring_Amount__c);
system.debug('Contract From Class - S797 Total Recurring Amount: ' +Trigger.new[i].Simplifi_797_Total_Recurring_Amount__c);
FromDelegate = cFromClass;
delegate = Trigger.new[i]; //Set the current contract in loop to the delegate sObject
//Loop through Products
for(integer p=0; p<ProductFamilies.size(); p++)
{
//Default Recurring Field
FieldName = ProductFamilies[p] + RecurringField; //Build API name for field
f = mFields.get(FieldName); //Get the field from map of fields based on API Name
system.debug('Default field: ' + FieldName);
//Check to see if F is null. Null means field does not exist
if(f != null)
{
O = FromDelegate.get(f);
delegate.put(f, O); //Set the value of the field to 0
}
//Default Non Recurring Field
FieldName = ProductFamilies[p] + NonRecurringField; //Build API name for field
f = mFields.get(FieldName); //Get the field from map of fields based on API Name
//Check to see if F is null. Null means field does not exist
if(f != null)
{
O = FromDelegate.get(f);
delegate.put(f, O); //Set the value of the field to 0
}
//End Prodct Family Loop
}
//End Trigger and Class Match
}
//End FromClass Loop
//}
system.debug('Yearly Revenue: ' + Trigger.new[i].yearly_revenue__c);
system.debug('Products on Contract: ' + Trigger.new[i].Products_included_in_Contract__c);
//system.assert(Trigger.new[i].Products_included_in_Contract__c != '', 'PRODUCT LIST NOT UPDATED!');
//system.assert(Trigger.new[i].simplifi_797_Amount__c > 0, 'Product Amount Not Updated!');
//end Trigger Loop
}
//end If Existing FromClass
}
}
*/
if(Trigger.isAfter)
{
system.debug('Contract Update Trigger IS AFTER!!');
/*Information to update Accounts */
list<Contract_Product__c> TheseProducts = [Select c.Total_Price__c, c.Sale_Type__c, c.Quantity__c, c.Product_Family__c,
c.New_Client__c, c.Name, c.Id, c.Exception__c, c.Discount__c, c.Contract__c, c.Contract_Product__c,
c.Annual_Price__c, c.Annual_List_Price__c, c.Account__c From Contract_Product__c c where c.Contract__c in :TheseContractIds];
if(TheseProducts != Null && TheseProducts.size() >0)
{
for(Contract_Product__c cp : TheseProducts)
{
TheseAccountIds.add(cp.Account__c);
}
Account_Contract_Update_Class.UpdateAccounts(TheseAccountIDs, ObjectDMLType);
}
}
}
//FirstRun IF statement
}
//Trigger global test
}
//last brackett
}
Sumitkumar_Shingavi
Are you calling batch from any trigger or updating any records from batch which causing trigger to fire which is making WS callout? Kindly check logs.