You need to sign in to do that
Don't have an account?
Vimal Makwana
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY error in production
I got following error in production.
Apex script unhandled exception by user/organization: 00580000005FYRy/00D80000000PQ16
Failed to invoke future method 'public static void updateSubs(List)' on class 'MDLiveIntegration' for job id '7078000001iFGgq'
caused by: System.DmlException: Update failed. First exception on row 0 with id a0q8000000QlTHsAAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SubscriberUpdateTrigger: execution of AfterUpdate
caused by: System.AsyncException: Future method cannot be called from a future or batch method: MDLiveIntegration.deleteSubs(String, Id)
Trigger.SubscriberUpdateTrigger: line 55, column 1: []
Class.MDLiveIntegration.updateSubs: line 247, column 1
But in sandbox i don't get any error. Please give your suggestions.
Apex script unhandled exception by user/organization: 00580000005FYRy/00D80000000PQ16
Failed to invoke future method 'public static void updateSubs(List)' on class 'MDLiveIntegration' for job id '7078000001iFGgq'
caused by: System.DmlException: Update failed. First exception on row 0 with id a0q8000000QlTHsAAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SubscriberUpdateTrigger: execution of AfterUpdate
caused by: System.AsyncException: Future method cannot be called from a future or batch method: MDLiveIntegration.deleteSubs(String, Id)
Trigger.SubscriberUpdateTrigger: line 55, column 1: []
Class.MDLiveIntegration.updateSubs: line 247, column 1
But in sandbox i don't get any error. Please give your suggestions.
My first suggestion os to check that "MDLiveIntegration" class is enabled in production. Or, if it is enabled make sure that the method "updateSubs(List)" on line 247 is not commented out.
It would be really helpful if you can provide codes for both :)
Thanks for reply. Here is my code.
Apex trigger
------------------
List<ID> subRecords = new List<ID>();
List<ID> subUpdateRecords = new List<ID>();
Boolean deleteflag = false;
if(!trigger.IsDelete) {
for(Subscriber__c subs : Trigger.new){
if(subs.Active_Subscriber__c == true && subs.Auto_Telemedicine__c == true){
Boolean needsUpdate = false ;
if(Trigger.isInsert){
needsUpdate = true;
}
else if (Trigger.isUpdate){
needsUpdate = false;
}
if(needsUpdate)
subRecords.add(subs.id);
else
subUpdateRecords.add(subs.id);
}
else
{
deleteflag = true;
}
}
if(subRecords.size() >0){
if(system.isFuture())
return;
MDLiveIntegration.insertSubs(subRecords);
}
if(subUpdateRecords.size() >0){
if(system.isFuture())
return;
MDLiveIntegration.updateSubs(subUpdateRecords);
MDLiveIntegration.reactiveSubs(subUpdateRecords);
}
}
else
{
for(Subscriber__c subs : Trigger.old) {
if(subs.Active_Subscriber__c == true && subs.Auto_Telemedicine__c == true){
MDLiveIntegration.deleteSubs(subs.MDLIVE_ID__c,subs.id);
}
}
}
if(deleteflag){
if(Trigger.isUpdate){
for(Subscriber__c subs : Trigger.old) {
MDLiveIntegration.deleteSubs(subs.MDLIVE_ID__c,subs.id); // error line 55
}
}
}
Apex class
----------------
@future(callout=true)
public static void updateSubs(List<id> ids){
String responseBody;
String Data;
List<Subscriber__c> lists = new List<Subscriber__c>();
List<Subscriber__c> subs = [Select id,MDLIVE_ID__c,Subscriber_Contact__r.MDLive_Birthdate__c,Name,
Product_Bundle__c,Subscriber_Account__c,Related_Opportunity__c,Subscriber_Contact__r.Gender__c,
Subscriber_Contact__r.name, Subscriber_Contact__r.Phone,Subscriber_Contact__r.FirstName, Subscriber_Contact__r.LastName,
Subscriber_Contact__r.MailingCity, Subscriber_Contact__r.MailingState, Subscriber_Contact__r.MailingCountry,
Subscriber_Contact__r.MailingPostalCode, Subscriber_Contact__r.MailingStreet,Subscriber_Contact__r.Email,
Subscriber_Contact__r.Birthdate from Subscriber__c where id =: ids];
for(Subscriber__c subitems : subs ){
// get value code
gen = subitems.Subscriber_Contact__r.Gender__c;
fname = subitems.Subscriber_Contact__r.FirstName;
lname = subitems.Subscriber_Contact__r.LastName;
Product_Bunndle = subitems.Product_Bundle__c;
Account_name = subitems.Subscriber_Account__c;
Opps_name = subitems.Related_Opportunity__c;
email = subitems.Subscriber_Contact__r.email;
street = subitems.Subscriber_Contact__r.MailingStreet;
city = subitems.Subscriber_Contact__r.MailingCity;
state = subitems.Subscriber_Contact__r.MailingState;
code = subitems.Subscriber_Contact__r.MailingPostalCode;
country = subitems.Subscriber_Contact__r.MailingCountry;
phone = subitems.Subscriber_Contact__r.phone;
bdate = subitems.Subscriber_Contact__r.MDLive_Birthdate__c;
ext_id = subitems.Name;
if(subitems.MDLIVE_ID__c != null){
// Http callout code
req.setEndpoint('https://members.mdlive.com/services/members/'+subitems.MDLIVE_ID__c);
req.setMethod('PUT');
req.setHeader('Content-Type', 'application/json');
Blob headerValue = Blob.valueOf(username +':' +password);
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
req.setHeader('RemoteUserId', 'f58b2369a9b9df5438ea');
jsonData = '{"member":{"first_name":' + '\"'+ fname +'\"'+',"last_name":'+'\"'+ lname +'\"'+',"address1":'+'\"' + street + '\"'+',"gender":'+'\"'+gen+'\"'+',"state":'+'\"'+state+'\"'+',"zip":'+'\"'+code+'\"'+',"City":'+'\"'+city+'\"'+',"Country":'+'\"'+country+'\"'+',"Email":'+'\"'+email+'\"'+',"Phone":'+'\"'+phone+'\"'+',"birthdate":'+'\"'+bdate+'\"'+'}}';
req.setBodyAsBlob(Blob.valueof(jsondata));
Http http = new Http();
HttpResponse res;
if(!Test.isRunningTest()){
res = http.send(req);
responseBody = res.getBody();
System.debug('Body Data:'+res.getBody());
} else {
responseBody = '{"member":{"external_id":"28","Id":"713","first_name":"Jimmy","last_name":"Games","address1":"india","gender":"male","state":"NY","zip":"36560","birthdate":"27-08-1988"}}';
}
JSONParser parser = JSON.createParser(responseBody);
while (parser.nextToken() != null) {
if(parser.getCurrentToken() == JSONToken.FIELD_NAME){
data = parser.getText();
if(data == 'errors'){
sendMail(responseBody);
break;
}
}
}
}
else {
req.setEndpoint('https://members.mdlive.com/services/members');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
Blob headerValue = Blob.valueOf(username +':' +password);
String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
req.setHeader('RemoteUserId', 'f58b2369a9b9df5438ea');
jsonData = '{"member":{"external_id":' + '\"'+ ext_id +'\"'+',"first_name":' + '\"'+ fname +'\"'+',"last_name":'+'\"'+ lname +'\"'+',"address1":'+'\"' + street + '\"'+',"gender":'+'\"'+gen+'\"'+',"state":'+'\"'+state+'\"'+',"zip":'+'\"'+code+'\"'+',"City":'+'\"'+city+'\"'+',"Country":'+'\"'+country+'\"'+',"Email":'+'\"'+email+'\"'+',"Phone":'+'\"'+phone+'\"'+',"birthdate":'+'\"'+bdate+'\"'+'}}';
req.setBodyAsBlob(Blob.valueof(jsondata));
Http http = new Http();
req.setTimeout(60000);
HttpResponse res;
if(!Test.isRunningTest()){
res = http.send(req);
responseBody = res.getBody();
System.debug('Response Body::'+res.getBody());
}else{
responseBody = '{"member":{"external_id":"28","first_name":"Jimmy","last_name":"Games","id":"713","address1":"india","gender":"male","state":"NY","zip":"36560","birthdate":"27-08-1988"}}';
}
// JSon parse for Id
JSONParser parser = JSON.createParser(responseBody);
while (parser.nextToken() != null) {
if(parser.getCurrentToken() == JSONToken.FIELD_NAME){
String fieldName = parser.getText();
System.debug('My Field Name:'+fieldName);
data = parser.getText();
if(data == 'errors'){
sendMail(responseBody);
break;
}
parser.nextToken();
System.debug('Last Token'+parser.getText());
if(fieldName == 'Id'){
String vals = parser.getText();
System.debug('Value val'+vals);
//MyID.add(vals);
Subscriber__c s = new Subscriber__c();
s.MDLIVE_ID__c = vals;
s.id = subitems.Id;
lists.add(s);
}
}
}
}
}
if(lists != null && !Test.isRunningTest())
update lists; // error line 247
}
I do not know mate, this is a bit out of my comfort zone. After doing some quick research it maybe @future methods that causes this error. Check out this post, the guy had similar problem and was able to fix it.
https://developer.salesforce.com/forums/ForumsMain?id=906F000000091dMIAQ