You need to sign in to do that
Don't have an account?
ankush
"Future method cannot be called from a future" error in trigger
Getting the error when validating
Future method cannot be called from a future or batch method: contactactivecheckboxclass.updatecnt(Set<String>) Trigger.Checkuseractive: line 18, column 1
ankush
Hi Tejpal,
Tried the below code using your code given above the contactactivecheckboxclass1 error vanished but now the contactactivecheckboxclass causing the issue. Same issue. Can you please help me in the contactactive checkbox class if I had made any error.
Trigger.
//This is a trigger that is used to check whether the user is active and updates the related Contact
trigger Checkuseractive on User (after insert, after update) {
set<string> set1 = new set<string>();
set<string> set2 = new set<string>();
if (!ProcessorControl.inFutureContext) {
//Below soql query gets the IsActive and ContactId of the user
list<user> u=[select id,Isactive,contactid from user where id=:trigger.new];
for(user usr:u){
if(usr.IsActive==false)
{
set1.add(usr.ContactId);
}
else if(usr.IsActive==true)
{
set2.add(usr.ContactId);
}
}
contactactivecheckboxclass.Updatecnt(set1);
contactactivecheckboxclass1.Updatecnt1(set2);
}
}
Contactactive checkbox class
//Future class for updating Contact Active Checkbox field
public class contactactivecheckboxclass {
@future
//Method that takes the contact id as parameter from Trigger and checks if user is active on user Object and updates the related contact accordingly.
public static void updatecnt(set<string> x){
try{
list<contact> cntlist= new list<contact>();
list<contact> c=[select Is_user_Active__c from Contact where id IN : x limit 1];
for(contact cnt:c){
cnt.Is_User_Active__c=false;
if(!test.isrunningtest()){
cntlist.add(cnt);
}
}
ProcessorControl.inFutureContext = true;
database.update(cntlist);
}
catch(exception e){
}
}
}
Contact Active checjboxclass1
//Future class for updating Contact Active Checkbox field
public class contactactivecheckboxclass1 {
@future
//Method that takes the contact id as parameter from Trigger and checks if user is active on user Object and updates the related contact accordingly.
public static void updatecnt1(set<string> x){
try{
list<contact> cntlist= new list<contact>();
list<contact> c=[select Is_user_Active__c from Contact where id IN : x limit 1];
for(contact cnt:c){
cnt.Is_User_Active__c=true;
if(!test.isrunningtest()){
cntlist.add(cnt);
}
}
ProcessorControl.inFutureContext = true;
database.update(cntlist);
}
catch(exception e){
}
}
}
Processor Control Class
public class ProcessorControl {
public static boolean inFutureContext = false;
}
Future method cannot be called from a future or batch method: contactactivecheckboxclass.updatecnt(Set<String>) Trigger.Checkuseractive: line 18, column 1
ankush
Hi Tejpal,
Tried the below code using your code given above the contactactivecheckboxclass1 error vanished but now the contactactivecheckboxclass causing the issue. Same issue. Can you please help me in the contactactive checkbox class if I had made any error.
Trigger.
//This is a trigger that is used to check whether the user is active and updates the related Contact
trigger Checkuseractive on User (after insert, after update) {
set<string> set1 = new set<string>();
set<string> set2 = new set<string>();
if (!ProcessorControl.inFutureContext) {
//Below soql query gets the IsActive and ContactId of the user
list<user> u=[select id,Isactive,contactid from user where id=:trigger.new];
for(user usr:u){
if(usr.IsActive==false)
{
set1.add(usr.ContactId);
}
else if(usr.IsActive==true)
{
set2.add(usr.ContactId);
}
}
contactactivecheckboxclass.Updatecnt(set1);
contactactivecheckboxclass1.Updatecnt1(set2);
}
}
Contactactive checkbox class
//Future class for updating Contact Active Checkbox field
public class contactactivecheckboxclass {
@future
//Method that takes the contact id as parameter from Trigger and checks if user is active on user Object and updates the related contact accordingly.
public static void updatecnt(set<string> x){
try{
list<contact> cntlist= new list<contact>();
list<contact> c=[select Is_user_Active__c from Contact where id IN : x limit 1];
for(contact cnt:c){
cnt.Is_User_Active__c=false;
if(!test.isrunningtest()){
cntlist.add(cnt);
}
}
ProcessorControl.inFutureContext = true;
database.update(cntlist);
}
catch(exception e){
}
}
}
Contact Active checjboxclass1
//Future class for updating Contact Active Checkbox field
public class contactactivecheckboxclass1 {
@future
//Method that takes the contact id as parameter from Trigger and checks if user is active on user Object and updates the related contact accordingly.
public static void updatecnt1(set<string> x){
try{
list<contact> cntlist= new list<contact>();
list<contact> c=[select Is_user_Active__c from Contact where id IN : x limit 1];
for(contact cnt:c){
cnt.Is_User_Active__c=true;
if(!test.isrunningtest()){
cntlist.add(cnt);
}
}
ProcessorControl.inFutureContext = true;
database.update(cntlist);
}
catch(exception e){
}
}
}
Processor Control Class
public class ProcessorControl {
public static boolean inFutureContext = false;
}
NOTE: This code has not been tested and may contain typographical or logical errors
NOTE: Please use the "Add a code sample" button (Icon <>) to insert your code. This will increase readability and make it easier to reference in solutions.
on line 23
Variable does not exist: contactactivecheckboxclass.ProcessorControl.inFutureContext
Trigger
ModifyContactCheckbox
ModifyContactCheckbox is now throwing me the nelow error
Only top-level class variables can be declared static
Can you please help me on this
Trigger
ModifyContactCheckbox