• Jason in China
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies

Hi,

 

When I tested some batch apex, I continual getting the "salesforce response to EXEC to /_ui/common/apex/debug/apexcsiapi was:0, communication failure" error message.

 

is there anyone had facing the same issue?

 

thanks,

Hi,

 

I am facing a strange issue now. Dose anyone have idea about this?

 

By requrirement, I created a batch apex to send email to some user, according some special condition.

But when i tested it in console, it seems the Start-Excute-Finish block donot run.

 

Below detail apex for reference:

 

global class D_Not_AA implements Database.Batchable<sObject>,Database.Stateful {
List <String> L_Ps = new String[] {'D_P','SSO_D_P'};
List <String> L_CP_Status = new String[] {'Approved','Submitted'};
Set<Id> S_CP_Owner = new set<Id>();
List<Id> L_toMail_Ps = new List<Id>();
// List<Id> L_toMail_P_Mgrs = new List<Id>();
Map <Id,List<Id>> M_Manager_P = new Map <Id,List<Id>>();

global D_Not_AA ()
{

// Get the detail Cycle Plan Owners on current period
system.debug(LoggingLevel.INFO,' Get Cycle Plan info.');

for (Cycle_Plan_vod__c J_CP_Owner :[SELECT OwnerId FROM Cycle_Plan_vod__c where Status_D__c in :L_CP_Status and Start_Date_vod__c < today and End_Date_vod__c > today]) {
S_CP_Owner.add(J_CP_Owner.OwnerId);
system.debug('[J] Cycle Plan OwnerId: '+J_CP_Owner.OwnerId);
}

system.debug(LoggingLevel.INFO,' Get Cycle Plan info_End.');

// L_toMail_P_Mgrs.addAll(M_Manager_P.keySet());
}


global Database.QueryLocator start(Database.BatchableContext BC)
{
system.debug(LoggingLevel.INFO,' Batch Start');

For (User U: [SELECT Id,ManagerId from User where isActive = true and ProfileId in (
SELECT Id FROM Profile 
where Name in :L_Ps)]) {
if (S_CP_Owner.contains (U.Id)) {
// the P have already create Cycle Plan
}
else
{
// the P did not create Cycle Plan yet
L_toMail_Ps.add(U.Id);
if (M_Manager_P.keySet().Contains(U.ManagerId))
{
M_Manager_P.get(U.ManagerId).add(U.Id);
}
else
{
M_Manager_P.put(U.ManagerId,new List <Id> {U.Id});
}
system.debug('[J] P Manager Users : '+U.ManagerId);
system.debug('[J] P Users : '+U.Id);
}
}

// Get all users to be send email
String query = 'Select id, name, email FROM User where id in' + M_Manager_P.keySet();
return Database.getQueryLocator(query);
}
global void Execute(Database.BatchableContext BC, List<sObject> Scope) 
{
system.debug(LoggingLevel.INFO,' Batch Execute');
for (Sobject s : Scope)
{
User ur = (User)s;

if (M_Manager_P.containsKey(ur.Id))
{
List<User> L_P_User = [SELECT ID,NAME,EMAIL FROM USER WHERE ID IN :M_Manager_P.get(ur.Id)];
String body = '';
body = BodyFormat(L_P_User);

// Mail Setting
Messaging.Singleemailmessage mail = new messaging.Singleemailmessage();
String[] toAddresses = new String[] {ur.Email};
mail.setToAddresses (toAddresses);
mail.setSubject('System Message:');
mail.setHtmlBody('Hi ' + ur.Name + ', Details of Cases logged today is as follows : 
' + User + ' 
Thanks');
}
}
}

public String BodyFormat(List<User> P) 
{ 
system.debug(LoggingLevel.INFO,' Batch Body');
String str = '' ; 
for(User U_P : P) 
{ 
str += '<tr><td>'+ U_P.Name +'</td>'+'<td>'+ U_P.Username +'</td>'+'</tr>' ; 
} 
str = str.replace('null' , '') ; 
String finalStr = '' ; 
finalStr = '<table border="1"> <td> P </td> <td> User Name </td> '+ str +'</table>' ; 
return finalStr ; 
} 

global void Finish (Database.BatchableContext BC) 
{
system.debug(LoggingLevel.INFO,' Batch Finish'); 
}
}

 I run it with 

D_Not_AA controller = new D_Not_AA () ; Integer batchSize = 1; database.executebatch(controller , batchSize);

 Dose anybody have idea about this?

 

I realy apprical for any response on this.

Thanks in advance.

 

Hello,

 

I am attemping to create a warning email via apex class.

And I got a sample from internet for that.

 

But when I try that in my environment, I keep getting the error info "Save error: unexpected token: ')' ".

 

Is there any idea for this?

 

 

Detail script as below, and I marked the error line in red color.

 

public with sharing class Email_Reminding {

 

User USR = [Select id from User limit 1];
EmailTemplate et = [Select id from EmailTemplate where name= 'EmailTemplatename'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(USR.Id);
mail.setSenderDisplayName('Jason Fang');
mail.setTemplateId(et.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}

 

Thanks a lot.

 

Hi,

 

I am facing a strange issue now. Dose anyone have idea about this?

 

By requrirement, I created a batch apex to send email to some user, according some special condition.

But when i tested it in console, it seems the Start-Excute-Finish block donot run.

 

Below detail apex for reference:

 

global class D_Not_AA implements Database.Batchable<sObject>,Database.Stateful {
List <String> L_Ps = new String[] {'D_P','SSO_D_P'};
List <String> L_CP_Status = new String[] {'Approved','Submitted'};
Set<Id> S_CP_Owner = new set<Id>();
List<Id> L_toMail_Ps = new List<Id>();
// List<Id> L_toMail_P_Mgrs = new List<Id>();
Map <Id,List<Id>> M_Manager_P = new Map <Id,List<Id>>();

global D_Not_AA ()
{

// Get the detail Cycle Plan Owners on current period
system.debug(LoggingLevel.INFO,' Get Cycle Plan info.');

for (Cycle_Plan_vod__c J_CP_Owner :[SELECT OwnerId FROM Cycle_Plan_vod__c where Status_D__c in :L_CP_Status and Start_Date_vod__c < today and End_Date_vod__c > today]) {
S_CP_Owner.add(J_CP_Owner.OwnerId);
system.debug('[J] Cycle Plan OwnerId: '+J_CP_Owner.OwnerId);
}

system.debug(LoggingLevel.INFO,' Get Cycle Plan info_End.');

// L_toMail_P_Mgrs.addAll(M_Manager_P.keySet());
}


global Database.QueryLocator start(Database.BatchableContext BC)
{
system.debug(LoggingLevel.INFO,' Batch Start');

For (User U: [SELECT Id,ManagerId from User where isActive = true and ProfileId in (
SELECT Id FROM Profile 
where Name in :L_Ps)]) {
if (S_CP_Owner.contains (U.Id)) {
// the P have already create Cycle Plan
}
else
{
// the P did not create Cycle Plan yet
L_toMail_Ps.add(U.Id);
if (M_Manager_P.keySet().Contains(U.ManagerId))
{
M_Manager_P.get(U.ManagerId).add(U.Id);
}
else
{
M_Manager_P.put(U.ManagerId,new List <Id> {U.Id});
}
system.debug('[J] P Manager Users : '+U.ManagerId);
system.debug('[J] P Users : '+U.Id);
}
}

// Get all users to be send email
String query = 'Select id, name, email FROM User where id in' + M_Manager_P.keySet();
return Database.getQueryLocator(query);
}
global void Execute(Database.BatchableContext BC, List<sObject> Scope) 
{
system.debug(LoggingLevel.INFO,' Batch Execute');
for (Sobject s : Scope)
{
User ur = (User)s;

if (M_Manager_P.containsKey(ur.Id))
{
List<User> L_P_User = [SELECT ID,NAME,EMAIL FROM USER WHERE ID IN :M_Manager_P.get(ur.Id)];
String body = '';
body = BodyFormat(L_P_User);

// Mail Setting
Messaging.Singleemailmessage mail = new messaging.Singleemailmessage();
String[] toAddresses = new String[] {ur.Email};
mail.setToAddresses (toAddresses);
mail.setSubject('System Message:');
mail.setHtmlBody('Hi ' + ur.Name + ', Details of Cases logged today is as follows : 
' + User + ' 
Thanks');
}
}
}

public String BodyFormat(List<User> P) 
{ 
system.debug(LoggingLevel.INFO,' Batch Body');
String str = '' ; 
for(User U_P : P) 
{ 
str += '<tr><td>'+ U_P.Name +'</td>'+'<td>'+ U_P.Username +'</td>'+'</tr>' ; 
} 
str = str.replace('null' , '') ; 
String finalStr = '' ; 
finalStr = '<table border="1"> <td> P </td> <td> User Name </td> '+ str +'</table>' ; 
return finalStr ; 
} 

global void Finish (Database.BatchableContext BC) 
{
system.debug(LoggingLevel.INFO,' Batch Finish'); 
}
}

 I run it with 

D_Not_AA controller = new D_Not_AA () ; Integer batchSize = 1; database.executebatch(controller , batchSize);

 Dose anybody have idea about this?

 

I realy apprical for any response on this.

Thanks in advance.

 

Hello,

 

I am attemping to create a warning email via apex class.

And I got a sample from internet for that.

 

But when I try that in my environment, I keep getting the error info "Save error: unexpected token: ')' ".

 

Is there any idea for this?

 

 

Detail script as below, and I marked the error line in red color.

 

public with sharing class Email_Reminding {

 

User USR = [Select id from User limit 1];
EmailTemplate et = [Select id from EmailTemplate where name= 'EmailTemplatename'];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(USR.Id);
mail.setSenderDisplayName('Jason Fang');
mail.setTemplateId(et.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}

 

Thanks a lot.

 

 

I have apex  batch class

  

global class apexBatch implements Database.Batchable<sObject>{
 global final string query;
List<user>  lstUser= new List<user>();
Set<id>     setUserID= new Set<id>();



//constructor
global apexBatch () {
    if (system.Test.isRunningTest())
    {
        this.query='SELECT id FROM user limit 100';
    }
    else
    {
        this.query='SELECT id FROM user ;
    }
}


global Database.QueryLocator start(Database.BatchableContext BC) {

    return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, List<sObject> scope) {

// do some processing


}

global void finish(Database.BatchableContext BC) {

}

 I am calling this class from test class using this code

 

 Test.startTest(); 
    apexBatch ba = new apexBatch();

    Database.executeBatch(ba);
      Test.stopTest();

 

When i check the code coverage i can only see that the constructor is covered, the start and execute methods are not covered at all.

Any idea what could cause this

Thanks