• abinaya
  • NEWBIE
  • 35 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 24
    Questions
  • 29
    Replies

Hi,

I created some distrubution lists using custom settings, in each distribution list i have email field,created 10 records for each distribution list,.

 

I need to send automatic emails based on email templates on scheduled base.

 

 

please help how to write code for this

 

Need sample for using node.js in Salesforce -- Creating records, updating records in salesforce 
Hi Team,

I have mapped a distributionlist email address to a user and tried to generate password for that user but i am not receiving any emails so far. Whether we can map the distributionlist for a user? 

Kindly advise.

Regards,
Abinaya S
Hi all,

I am unable to download xlsx files which is available in my vf page in chrome and IE. Kindly help me. 

In my controller i am using this stmt : attachBody = EncodingUtil.base64Encode(itrAttach.Body);

In VF Page : <a download="{!attachItem.attachName}" href="data:{!attachItem.attachContentType};base64,{!attachItem.attachBody}" > {!attachItem.attachName} </a>

Thanks in advance.

Regards,
Abinaya.
Hi team,

We have integrated SF with JIRA. In which from salesforce we have linked a JIRA issue. 

Now we would like to create a case based on JIRA issue. Can you please help me on this.

Thanks in advance,
Abinaya S
Hi all,

How to get the selected day dates in the a given date range. For eg: i am selecting the date range from nov 1st to nov 30th. In this date range i want to get the monday date's i.e nov 2nd, nov 9th, etc.

Also i want to check a condition in soql like createddate day is equal to monday .

Kindly help me in this.

Regards,
Abinaya.

 
Hi all,

I would like to know how the business hours diff calculation is working?  I am facing a issue on it.

Start Time is : 7/30/2014 3:11 PM
End Time is  : 7/30/2014 3:00 PM

Business Hours is 9 AM to 6 PM (IST).

In code we have used  the below formula.

BusinessHours.diff(businessHoursId, StartTime, EndTime).

Please let me know how the calculation works?

Thanks in advance!!!

Regards,
Abinaya S
hi team,

i have a global class and it has inner class and that is also a global class.

For ex:

global with sharing  class x

{
  
global class y
{
  // here i have  a method
}
}

How to call the inner class and its method in test class

Regards,
Abi
hi team,

Kindly help me how to clone the record with the selected field values. This should redirect to the edit page of the new cloned record

Regards,
Abi

Hi,

I need to write test class for inner class coverage. 

Class:

public class PerformanceReport
{
public String strFromDate {get; set;}
public String strToDate {get; set;}
public List<PerformanceReportClass> LstPerformanceReportClass {get;set;}
public Class PerformanceReportClass
{
public String strMRName{get;set;}
public String strMonth1{get;set;}
public String strMonth2{get;set;}
public String strMonth3{get;set;}
public String strMonth4{get;set;}
public String strMonth5{get;set;}
public String strMonth6{get;set;}
public String strMonth7{get;set;}
public String strMonth8{get;set;}
public String strMonth9{get;set;}
public String strMonth10{get;set;}
public String strMonth11{get;set;}
public String strMonth12{get;set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass1{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass2{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass3{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass4{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass5{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass6{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass7{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass8{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass9{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass10{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass11{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass12{get; set;}
}
public class ReqmtDetailsClass
{
public string ReqmtName {get; set;}
public string ReqmtStatus {get; set;}
public string ReqmtPostdDate {get; set;}
public string ResumeReqstd {get; set;}
public string ResumeSubmtd {get; set;}
public string ResumeFirstPosted {get; set;}
public string ElapsedTimeFirstResumePosted {get; set;}
public string ReqmtClosedDate {get; set;}
public string ReqmtClosedHrs {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass2 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass3 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass4 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass5 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass6 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass7 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass8 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass9 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass10 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass11 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass12 {get; set;}
}

public class CandtDetailsClass
{
public string CandtName{get; set;}
public string CandtEmail{get; set;}
}
public PageReference GetReportDetails()
{
List<User> lstAllUser = new List<User>([SELECT id, name, LastModifiedDate, isActive from user where userroleid in (select id from userrole where name='Management Representative')]);
List<User> lstUser = new List<User>();
List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();
List<RequirementAssignment__c> FilterReqmtAssign ;
List<RequirementAssignment__c> FilterReqmtAssignMonthly ;
List<Requirement__c> lstReqmts = new List<Requirement__c>();
if(strFromDate != null && strToDate != null)
{
DateTime startDT = DateTime.parse(strFromDate);
system.debug('Date:' + startDT);
DateTime endDT = DateTime.parse(strToDate);
system.debug('Date:' + endDT);
Date NewStartDate;
Integer startMonth = startDT.monthgmt();
Integer endMonth = endDT.monthgmt();
Integer startYear = startDT.yeargmt();
Integer endYear = endDT.yeargmt();
for(User allUser : lstAllUser)
{
if(allUser.IsActive == true)
{
lstUser.add(allUser);
}
else
{
if(allUser.LastModifiedDate > startDT)
{
lstUser.add(allUser);
}
}
}
lstReqmtAssign = [select Status__c, Requirement__c, Lead_Recruiter__c, Recruiter__c, createddate, createdbyid from RequirementAssignment__c where createddate >: startDT and createddate <: endDT ];

LstPerformanceReportClass = new List<PerformanceReportClass>();
for(User MRUSer : lstUser)
{
FilterReqmtAssign = new List<RequirementAssignment__c>();
for(RequirementAssignment__c ReqmAssign : lstReqmtAssign)
{
if(MRUSer.id == ReqmAssign.createdbyid)
{
FilterReqmtAssign.Add(ReqmAssign);
}
}
PerformanceReportClass objPerformanceReportClass = new PerformanceReportClass();
objPerformanceReportClass.strMonth1 = objPerformanceReportClass.strMonth2 = objPerformanceReportClass.strMonth3 = objPerformanceReportClass.strMonth4 = objPerformanceReportClass.strMonth5 = objPerformanceReportClass.strMonth6 = objPerformanceReportClass.strMonth7 = objPerformanceReportClass.strMonth8 = objPerformanceReportClass.strMonth9 = objPerformanceReportClass.strMonth10 = objPerformanceReportClass.strMonth11 = objPerformanceReportClass.strMonth12 = string.valueOf(0);
Integer count = 0;
NewStartDate = startDT.date();
Integer incrMonth = NewStartDate.month();
objPerformanceReportClass.strMRName = MRUSer.name;
if(FilterReqmtAssign != null)
{
for(integer i=startMonth; i<=endMonth; i++)
{
FilterReqmtAssignMonthly = new List<RequirementAssignment__c>();
for(RequirementAssignment__c ReqmAssignUser : FilterReqmtAssign)
{
DateTime ReqmtAssignDt = ReqmAssignUser.createddate;
Date ReqmAssignDate = Date.NewInstance(ReqmtAssignDt.yeargmt(), ReqmtAssignDt.monthgmt(), ReqmtAssignDt.daygmt());
System.Debug('Reqmt Assign Date:' +ReqmAssignDate);
System.Debug('Original Date:' + NewStartDate.month());
if((ReqmAssignDate.month() == incrMonth) && (ReqmAssignDate.year() == NewStartDate.year()))
{
FilterReqmtAssignMonthly.Add(ReqmAssignUser);
}
}
incrMonth++;
System.Debug('List Size:' +FilterReqmtAssignMonthly.size());
if(i==1)
{
objPerformanceReportClass.strMonth1 = string.valueOf(FilterReqmtAssignMonthly.size());
System.Debug('objReqmtAssignClass.strDate1:' +objPerformanceReportClass.strMonth1);
objPerformanceReportClass.lstReqmtDetailsClass1 = new List<ReqmtDetailsClass>();
Set<ID> setReqId = new Set<ID>();
for(RequirementAssignment__c Reqmt : FilterReqmtAssignMonthly)
{
System.Debug('Filter List Monthly'+FilterReqmtAssignMonthly);
System.Debug('Monthly Reqmt' +Reqmt);
setReqId.add(Reqmt.Requirement__c);
}
System.Debug('Id Set:' +setReqId);
if(setReqId.size()>0)
{
for(ID ReqID : setReqId)
{
System.Debug('Reqmt Id:' + ReqID);
List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c where id =:ReqID];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);
List<Candidate_Mapping__c> lstCandtMapping = [select Candidate__r.Candidate_Full_Name__c , Candidate__r.Email__c from Candidate_Mapping__c where Requirement__c =:ReqID];
System.Debug('Candidates List:' +lstCandtMapping);
if(lstReqmtsResume.size()>0)
{
for(Requirement__c req:lstReqmtsResume)
{
ReqmtDetailsClass objReqmtDetailsClass1 = new ReqmtDetailsClass();
objReqmtDetailsClass1.lstCandtdetailClass = new List<CandtDetailsClass>();
System.Debug('Reqmt Resume:' +req);
objReqmtDetailsClass1.ReqmtName = string.valueOf(req.Name);
objReqmtDetailsClass1.ReqmtStatus = string.valueOf(req.Status__c);
objReqmtDetailsClass1.ReqmtPostdDate = string.valueOf(req.createddate);
objReqmtDetailsClass1.ResumeReqstd = string.valueOf(req.No_Of_Resumes__c);
objReqmtDetailsClass1.ResumeSubmtd = string.valueOf(req.Resumes_Submitted__c);
objReqmtDetailsClass1.ResumeFirstPosted = string.valueOf(req.Assign_Candidate_date__c);
objReqmtDetailsClass1.ElapsedTimeFirstResumePosted = string.valueOf(req.First_Response__c);
objReqmtDetailsClass1.ReqmtClosedDate = string.valueOf(req.Req_Closed_Date__c);
objReqmtDetailsClass1.ReqmtClosedHrs = string.valueOf(req.Req_Closed_hrs__c);
System.Debug('objReqmtDetailsClass1:'+objReqmtDetailsClass1);
objPerformanceReportClass.lstReqmtDetailsClass1.add(objReqmtDetailsClass1);
for(Candidate_Mapping__c candt :lstCandtMapping)
{
CandtDetailsClass objCandtDetailsClass1 = new CandtDetailsClass();
objCandtDetailsClass1.CandtName = string.valueOf(candt.Candidate__r.Candidate_Full_Name__c);
objCandtDetailsClass1.CandtEmail = string.valueOf(candt.Candidate__r.Email__c);
objReqmtDetailsClass1.lstCandtdetailClass.add(objCandtDetailsClass1);
}
}
}
}
}

}
else if(i==2)
{
objPerformanceReportClass.strMonth2 = string.valueOf(FilterReqmtAssignMonthly.size());
System.Debug('objReqmtAssignClass.strDate2:' +objPerformanceReportClass.strMonth2);
objPerformanceReportClass.lstReqmtDetailsClass2 = new List<ReqmtDetailsClass>();
Set<ID> setReqId = new Set<ID>();
for(RequirementAssignment__c Reqmt : FilterReqmtAssignMonthly)
{
System.Debug('Filter List Monthly'+FilterReqmtAssignMonthly);
System.Debug('Monthly Reqmt' +Reqmt);
setReqId.add(Reqmt.Requirement__c);
}
System.Debug('Id Set:' +setReqId);
if(setReqId.size()>0)
{
for(ID ReqID : setReqId)
{
System.Debug('Reqmt Id:' + ReqID);
List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c where id =:ReqID];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);
if(lstReqmtsResume.size()>0)
{
for(Requirement__c req:lstReqmtsResume)
{
ReqmtDetailsClass objReqmtDetailsClass2 = new ReqmtDetailsClass();
System.Debug('Reqmt Resume:' +req);
objReqmtDetailsClass2.ReqmtName = string.valueOf(req.Name);
objReqmtDetailsClass2.ReqmtStatus = string.valueOf(req.Status__c);
objReqmtDetailsClass2.ReqmtPostdDate = string.valueOf(req.createddate);
objReqmtDetailsClass2.ResumeReqstd = string.valueOf(req.No_Of_Resumes__c);
objReqmtDetailsClass2.ResumeSubmtd = string.valueOf(req.Resumes_Submitted__c);
objReqmtDetailsClass2.ResumeFirstPosted = string.valueOf(req.Assign_Candidate_date__c);
objReqmtDetailsClass2.ElapsedTimeFirstResumePosted = string.valueOf(req.First_Response__c);
objReqmtDetailsClass2.ReqmtClosedDate = string.valueOf(req.Req_Closed_Date__c);
objReqmtDetailsClass2.ReqmtClosedHrs = string.valueOf(req.Req_Closed_hrs__c);
System.Debug('objReqmtDetailsClass2:'+objReqmtDetailsClass2);
objPerformanceReportClass.lstReqmtDetailsClass2.add(objReqmtDetailsClass2);
}}}}}}
LstPerformanceReportClass.add(objPerformanceReportClass);
}}}
return null;
}}

Test Class:

@isTest
private class testclassperformancereport
{
static testmethod void myTestclass()
{
Candidate_Mapping__c cm = new Candidate_Mapping__c();

Candidate__c cc1=new Candidate__c();
cc1.Name='test';
cc1.Last_name__c='testonek';
cc1.Current_city__c='chennai';
cc1.Current_state__c='Maine';
cc1.Gender__c='Male';
cc1.Employer_Name__c='ttt';
cc1.Email__c='test@gmail.com';
cc1.interview_contact_phone__c='Mobile Phone';
cc1.Contract_type__c='Corp to Corp';
cc1.visa_type__c='H1 B';
cc1.cost__c =100;
cc1.mobile_phone_no__c='9890043500';
cc1.employer_contact_email__c='test@gmail.com';
cc1.Employer_Contact_Name_Name__c='tt';
cc1.Employer_Mobile_No__c='9988009876';
cc1.Employer_Name__c = 'jos';
cc1.Employer_Work_Phone_No__c = '(425) 264-6771';
cc1.Followup_Date__c =date.today();

System.test.startTest();
insert cc1;

cm.Candidate__c=cc1.id;
system.debug('candid:'+cc1.id);

Requirement__c rc1=new Requirement__c();

rc1.Name='SampathReq';
rc1.Job_Title__c='.net';
rc1.Duration__c='6';
rc1.No_Of_Resumes__c=2;
rc1.Min_Cost__c=100;
rc1.Max_Cost__c=200;
rc1.Rate__c=200;
rc1.Rate_Basis__c='Hourly';
rc1.Status__c='open';
rc1.Position_Type__c='Contract';
rc1.State__c='CA';
rc1.City__c='CA';
rc1.Est_Start_Date__c=date.today();
insert rc1;
User lruser = [select u.id from user u where (u.Profile.Name ='Lead Recruiter' or u.Profile.Name ='LR Chatter Only User') and u.ManagerId!=null and u.IsActive= True limit 1] ;
User ruser = [select u.id from user u where (u.Profile.Name ='Recruiter' or u.Profile.Name ='R Chatter Only User') and u.ManagerId!=null and u.IsActive= True limit 1] ;

RequirementAssignment__c reqas = new RequirementAssignment__c();

reqas.Requirement__c = rc1.id;
reqas.AssignStatus__c= 'true';
reqas.Won__c= 'no';
reqas.Lead_Recruiter__c = lruser.id;
//reqas.Recruiter__c = ruser.id;
insert reqas;

cm.Requirement__c=rc1.id;
system.debug('candid:'+cc1.id);

cm.Employer_s_Authorization__c = 'test';
cm.status1__c = 'Applied';
cm.LR_Comments__c = 'test by lr';
cm.MR_Comments__c = 'test by MR';
cm.Requirement_Owner_Email__c = 'testOwner@preludesys.com';
cm.Manager_Email_ID__c = 'testOwner1@preludesys.com';
cm.LR_Status__c = 'Approved';
cm.MR_Status__c = 'Approved';
cm.LR_Status_Date__c = string.valueOf(date.today());
cm.Submitted_to_Client__c = 'Yes';
cm.Interview_Scheduled__c = 'Yes';
cm.Interview_Accepted__c = 'Yes';
cm.Client_Interviewed__c = 'Yes';
cm.Client_Offered__c = 'Yes';
cm.Comments__c = '';
cm.MR_Status1__c = 'Approved' ;

User user = [Select Id from User limit 1] ;

EmailTemplate et = [Select Id, Subject, HtmlValue, Body from EmailTemplate where Name = 'Candidate Approval Email with link EZRE'];
List<ContentVersion> contentList = new List<ContentVersion>();

ContentWorkspace library = [SELECT id FROM ContentWorkspace LIMIT 1];
System.Debug('library.id:'+ library.id);

ContentVersion contentVersionObj = new ContentVersion();

contentVersionObj.title = 'Google';//contentVersionObj.Enablement_Area__c = 'Acct Mgmt';
contentVersionObj.FirstPublishLocationId = library.id;
contentVersionObj.Candidate_Id__c = cc1.Id;
contentVersionObj.VersionData = Blob.valueOf('Ayangar') ;
contentVersionObj.PathOnclient = 'http://www.google.com';
contentVersionObj.Title ='Management Approach';

insert contentVersionObj;
System.Debug('ContentVersionObj:'+ contentVersionObj);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('Sasikumar.Word');
efa.setBody(Blob.ValueOf(et.Body));
System.Debug('efa:' +efa);
String[] toAddresses = new string[]{'dummy@yahoo.com'};
mail.setTargetObjectId(user.Id);
mail.setToAddresses(toAddresses);

mail.setTemplateId(et.Id);

mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
mail.saveAsActivity = false;
// Sends the email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

insert cm;

datetime nowdate = datetime.now();

string strfromdate = nowdate.format('MM/dd/yyyy hh:mm a');

datetime newdate= nowdate.addMonths(2);

string strtodate = newdate.format('MM/dd/yyyy hh:mm a');

List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();

PerformanceReport pr = new PerformanceReport();

list<PerformanceReportClass> c = new List<PerformanceReportClass>();

datetime startdate = datetime.parse(strfromdate);
system.debug('startdate :' + startdate);

datetime enddate = datetime.parse(strtodate);
system.debug('enddate :' + enddate);

lstReqmtAssign = [select Status__c, Requirement__c, Lead_Recruiter__c, Recruiter__c, createddate, createdbyid from RequirementAssignment__c where createddate >= 2013-09-01T00:00:00.000+0000 and createddate <=2013-09-25T00:00:00.000+0000 ];

System.debug('lstReqmtAssign: ' + lstReqmtAssign);


List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c where id =:rc1.id];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);

List<Candidate_Mapping__c> lstCandtMapping = [select Candidate__r.Candidate_Full_Name__c , Candidate__r.Email__c from Candidate_Mapping__c where Requirement__c =:rc1.id];
System.Debug('Candidates List:' +lstCandtMapping);

pr.GetReportDetails();

}
}

 

What ever i modify in the test class, the code coverage is 3% only, Kindly help meto fix this.

 

Regards,

Abinaya.

Hi all,

 

I am using two user licenses, chatter only and salesforce for same role with different profiles (both A and B has same access permission for objects, fields and etc).

 

the user with salesforce can able to see all the records irrespective of the assigned to him/her.

 

the user with chatter only license can able to the records assigned to him/her.

 

how to restrict the records the records?

 

In sandbox, it is working fine but in production i am facing issues. 

 

Kindly advice

 

Hi,

 

I have a requirement object and in that i have a status picklist which contains 4 status.

If the status is reopen, then the no.of resumes in the requirement object should be 0. And if the no.of resumes is 0, then an error message should be thrown like "enter the no. of resumes".

I am updating few other fields based on the reopen status in a trigger. So I am updating no.of resumes to 0 in that trigger and created a validation rule in requirement object like

if (no.of resumes == 0, true, false)
error message : enter the no.of resumes.


But the error message is throwing whenever i have mentioned no.of resumes greater than 0 (i.e 1).

 

 

Kindly advice.

 Hi,

 

Please find the below trigger and test class. As of now the code coverage is only 46% and i have passed all the parameters(mandatory) field values. Plz advice.

 

trigger statusupdate on Candidate_Mapping__c (before insert, before update)
{

public string strConvertedDate {get; set;}

if(Trigger.isUpdate)
{
// Candidate_Mapping__c ac = Trigger.new[0];
for(Candidate_Mapping__c ac : Trigger.new)
{
system.debug('ac:'+ ac);

candidate_mapping__c ac1 = Trigger.oldMap.get(ac.ID);

Map<Id,Candidate_Mapping__c> newContactMap = Trigger.newMap;
Map<Id,Candidate_Mapping__c> oldContactMap = Trigger.oldMap;

system.debug('newContactMap:' + newContactMap );
system.debug('oldContactMap:' + newContactMap );

if (ac.LR_Status__c == 'Approved' && ac.LR_Status__c != ac1.LR_Status__c )
{
// ac.LR_Email__c = ac.LR_Email_ID__c;

ac.status1__c = 'LR Approved';
ac.Manager_Email_ID__c = ac.Req_Owner_Email__c;
ac.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.LR_Status__c == 'Rejected'&& ac.LR_Status__c != ac1.LR_Status__c)
{
// ac.LR_Email__c = ac.LR_Email_ID__c;
ac.status1__c = 'LR Rejected';
ac.Manager_Email_ID__c = ac.Req_Owner_Email__c;
ac.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}



if (ac.MR_Status__c == 'Approved' && ac.MR_Status__c != ac1.MR_Status__c)
{
//
for(Id contactId:newContactMap.keySet())
{
//Loop through the map
Candidate_Mapping__c myNewContact = newContactMap.get(contactId);
Candidate_Mapping__c myOldContact = oldContactMap.get(contactId);
if (myNewContact.MR_Status__c <> myOldContact.MR_Status__c)
{
ac.MR_Status1__c = 'Approved';
ac.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');

}
else
{
ac.MR_Status1__c = 'None';
}
}
//
//ac.MR_Status1__c = 'Approved';
ac.status1__c = 'Approved';
ac.Manager_Email_ID__c = ac.Req_Owner_Email__c;
ac.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.MR_Status__c == 'Rejected' && ac.MR_Status__c != ac1.MR_Status__c)
{
ac.Manager_Email_ID__c = ac.Req_Owner_Email__c;
ac.status1__c = 'Rejected';
ac.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Submitted_to_Client__c == 'Yes' && ac.Submitted_to_Client__c != ac1.Submitted_to_Client__c)
{
ac.status1__c = 'Submitted to Client';
ac.Priority__c = 'a';
ac.Submitted_to_Client_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Submitted_to_Client__c == 'No'&& ac.Submitted_to_Client__c != ac1.Submitted_to_Client__c)
{
ac.status1__c = 'Not Submitted to Client';
ac.Priority__c = 'a';
ac.Submitted_to_Client_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Interview_Scheduled__c == 'Yes'&& ac.Interview_Scheduled__c != ac1.Interview_Scheduled__c )
{
ac.status1__c = 'Interview Requested';
ac.Priority__c = 'b';
ac.Interview_Scheduled_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Interview_Scheduled__c == 'No' && ac.Interview_Scheduled__c != ac1.Interview_Scheduled__c )
{
ac.status1__c = 'Not Shortlisted For Interview';
ac.Priority__c = 'b';
ac.Interview_Scheduled_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Interview_Accepted__c == 'Yes' && ac.Interview_Accepted__c != ac1.Interview_Accepted__c)
{
ac.status1__c = 'Interview Accepted';
ac.Priority__c = 'c';
ac.Interview_Accepted_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Interview_Accepted__c == 'No' && ac.Interview_Accepted__c != ac1.Interview_Accepted__c)
{
ac.status1__c = 'Candidate Not Available';
ac.Priority__c = 'c';
ac.Interview_Accepted_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Client_Interviewed__c == 'Yes'&& ac.Client_Interviewed__c != ac1.Client_Interviewed__c)
{
ac.status1__c = 'Client Interviewed';
ac.Priority__c = 'd';
ac.Client_Interview_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Client_Interviewed__c == 'No' && ac.Client_Interviewed__c != ac1.Client_Interviewed__c)
{
ac.status1__c = 'Client Did Not Interview';
ac.Priority__c = 'd';
ac.Client_Interview_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Client_Offered__c == 'Yes' && ac.Client_Offered__c != ac1.Client_Offered__c)
{
ac.status1__c = 'Client Offered';
ac.Priority__c = 'e';
ac.Client_Offer_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Client_Offered__c == 'No' && ac.Client_Offered__c != ac1.Client_Offered__c)
{
ac.status1__c = 'Interviewed and rejected';
ac.Priority__c = 'e';
ac.Client_Offer_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Candidate_started__c == 'Yes' && ac.Candidate_started__c != ac1.Candidate_started__c)
{
ac.status1__c = 'Candidate started';
ac.Priority__c = 'f';
ac.started_date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.Candidate_started__c == 'No' && ac.Candidate_started__c != ac1.Candidate_started__c )
{
ac.status1__c = 'Candidate did not start';
ac.Priority__c = 'f';
ac.started_date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

system.debug('ac:'+ ac);
system.debug('Status:' + ac.status1__c);
system.debug('Priority:' + ac.Priority__c);
system.debug('Manager Email:' + ac.Manager_Email_ID__c);
system.debug('LR_Email__c :' + ac.LR_Email__c);
system.debug('R_Email__c :' + ac.R_Email__c );
system.debug('MR_Status1__c:' + ac.MR_Status1__c );

}
}

if(Trigger.isInsert)
{
//Candidate_Mapping__c ac = Trigger.new[0];
for(Candidate_Mapping__c ac : Trigger.new)
{
system.debug('ac:'+ ac);

//Map<Id,Candidate_Mapping__c> newContactMap = Trigger.newMap;
//Map<Id,Candidate_Mapping__c> oldContactMap = Trigger.oldMap;


system.debug('LRStatus:' + ac.LR_Status__c);
system.debug('MRStatus:' + ac.MR_Status__c);

if(ac.Status1__c == 'Applied')
{
// ac.R_Email__c = ac.R_email_id__c;
ac.Requirement_Owner_Email__c = ac.Req_Owner_Email__c;
// ac.Manager_Email_ID__c = ac.LR_Email_ID__c;
}

if (ac.LR_Status__c == 'Approved')
{
// ac.LR_Email__c = ac.LR_Email_ID__c;
ac.status1__c = 'LR Approved';
ac.Manager_Email_ID__c = ac.Req_Owner_Email__c;
ac.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.LR_Status__c == 'Rejected')
{

// ac.LR_Email__c = ac.LR_Email_ID__c;
ac.status1__c = 'LR Rejected';
ac.Manager_Email_ID__c = ac.Req_Owner_Email__c;
ac.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}


if (ac.MR_Status__c == 'Approved')
{
ac.MR_Status1__c = 'Approved';
ac.status1__c = 'Approved';
ac.Manager_Email_ID__c = ac.Req_Owner_Email__c;
ac.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

if (ac.MR_Status__c == 'Rejected')
{
ac.Manager_Email_ID__c = ac.Req_Owner_Email__c;
ac.status1__c = 'Rejected';
ac.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
}

system.debug('ac:'+ ac);
system.debug('Status:' + ac.status1__c);
system.debug('Priority:' + ac.Priority__c);
system.debug('Manager Email:' + ac.Manager_Email_ID__c);
system.debug('LR_Email__c :' + ac.LR_Email__c);
system.debug('R_Email__c :' + ac.R_Email__c );
system.debug('MR_Status1__c:' + ac.MR_Status1__c );

}

 


}


}

 

 

Test class: 

 

@isTest(seealldata=true)
private class TestTriggerStatusUpdate
{
static testMethod void myUnitTest()
{
Candidate_Mapping__c coa =new Candidate_Mapping__c();
coa.status1__c = 'Applied';
coa.Employer_s_Authorization__c = 'test';
coa.LR_Comments__c = 'test by lr';
coa.MR_Comments__c = 'test by MR';
coa.Requirement_Owner_Email__c = 'testOwner@preludesys.com';
coa.Manager_Email_ID__c = 'testOwner1@preludesys.com';
coa.R_Comments__c = '';
coa.LR_Status__c = 'Rejected';
coa.MR_Status__c = 'Rejected';
coa.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Submitted_to_Client__c = 'No';
coa.Submitted_to_Client_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Interview_Scheduled__c = 'No';
coa.Interview_Scheduled_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Interview_Accepted__c = 'No';
coa.Interview_Accepted_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Client_Interviewed__c = 'No';
coa.Client_Interview_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Client_Offered__c = 'No';
coa.Client_Offer_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Candidate_started__c = 'No';
coa.Comments__c = '';
coa.started_date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.MR_Status1__c = 'None' ;
coa.LR_Email__c = 'test@prel.com';
// coa.status1__c = 'Rejected';
//coa.Manager_Email_ID__c = ac.Req_Owner_Email__c;

Candidate__c cc1=new Candidate__c();
cc1.Name='test';
cc1.Last_name__c='testone';
cc1.Current_city__c='chennai';
cc1.Current_state__c='Maine';
cc1.Gender__c='Male';
cc1.Employer_Name__c='ttt';
cc1.Email__c='test@gmail.com';
cc1.interview_contact_phone__c='Mobile Phone';
cc1.Contract_type__c='Corp to Corp';
cc1.visa_type__c='H1 B';
cc1.cost__c =100;
cc1.mobile_phone_no__c='9890043500';
cc1.employer_contact_email__c='test@gmail.com';
cc1.Employer_Contact_Name_Name__c='tt';
cc1.Employer_Mobile_No__c='9988009876';
cc1.Employer_Name__c = 'jos';
cc1.Employer_Work_Phone_No__c = '(425) 264-6771';
cc1.Followup_Date__c =date.today();
insert cc1;
coa.Candidate__c=cc1.id;
system.debug('candid:'+cc1.id);

Requirement__c rc1=new Requirement__c();
rc1.Name='SampathReq';
rc1.Job_Title__c='.net';
//rc1.Client__c ='abc company';
rc1.Duration__c='6';
rc1.No_Of_Resumes__c=2;
rc1.Min_Cost__c=100;
rc1.Max_Cost__c=200;
rc1.Rate__c=200;
rc1.Rate_Basis__c='Hourly';
rc1.Status__c='open';
rc1.Position_Type__c='Contract';
rc1.State__c='CA';
rc1.City__c='CA';
rc1.Est_Start_Date__c=date.today();
rc1.won__c = true;
//rc1.won_text__c ='yes';
insert rc1;
coa.Requirement__c=rc1.id;


insert coa;

}
static testMethod void myUnitTest1()
{

Candidate_Mapping__c coa =new Candidate_Mapping__c();
coa.status1__c = 'Applied';
coa.Employer_s_Authorization__c = 'test';
coa.LR_Comments__c = 'test by lr';
coa.MR_Comments__c = 'test by MR';
coa.Requirement_Owner_Email__c = 'testOwner@preludesys.com';
coa.Manager_Email_ID__c = 'testOwner1@preludesys.com';
coa.R_Comments__c = '';
coa.LR_Status__c = 'Approved';
coa.MR_Status__c = 'Approved';
coa.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Submitted_to_Client__c = 'Yes';
coa.Submitted_to_Client_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Interview_Scheduled__c = 'Yes';
coa.Interview_Scheduled_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Interview_Accepted__c = 'Yes';
coa.Interview_Accepted_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Client_Interviewed__c = 'Yes';
coa.Client_Interview_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
// coa.status1__c = 'Client Interviewed';
coa.Client_Offered__c = 'Yes';
coa.Client_Offer_Date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
// coa.status1__c = 'Client Offered';
coa.Candidate_started__c = 'Yes';
coa.Comments__c = '';
coa.MR_Status1__c = 'Approved' ;
coa.started_date__c= DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');

Candidate__c cc1=new Candidate__c();
cc1.Name='test';
cc1.Last_name__c='testone';
cc1.Current_city__c='chennai';
cc1.Current_state__c='Maine';
cc1.Gender__c='Male';
cc1.Employer_Name__c='ttt';
cc1.Email__c='test@gmail.com';
cc1.interview_contact_phone__c='Mobile Phone';
cc1.Contract_type__c='Corp to Corp';
cc1.visa_type__c='H1 B';
cc1.cost__c =100;
cc1.mobile_phone_no__c='9890043500';
cc1.employer_contact_email__c='test@gmail.com';
cc1.Employer_Contact_Name_Name__c='tt';
cc1.Employer_Mobile_No__c='9988009876';
cc1.Employer_Name__c = 'jos';
cc1.Employer_Work_Phone_No__c = '(425) 264-6771';
cc1.Followup_Date__c =date.today();
insert cc1;
coa.Candidate__c=cc1.id;
system.debug('candid:'+cc1.id);

Requirement__c rc1=new Requirement__c();
rc1.Name='SampathReq';
rc1.Job_Title__c='.net';
//rc1.Client__c ='abc company';
rc1.Duration__c='6';
rc1.No_Of_Resumes__c=2;
rc1.Min_Cost__c=100;
rc1.Max_Cost__c=200;
rc1.Rate__c=200;
rc1.Rate_Basis__c='Hourly';
rc1.Status__c='open';
rc1.Position_Type__c='Contract';
rc1.State__c='CA';
rc1.City__c='CA';
rc1.Est_Start_Date__c=date.today();
rc1.won__c = true;
//rc1.won_text__c ='yes';
insert rc1;
coa.Requirement__c=rc1.id;

User user = [Select Id from User limit 1] ; //where Email= 'gopalmr140313@gmail.com'];

EmailTemplate et = [Select Id, Subject, HtmlValue, Body from EmailTemplate where Name = 'Candidate Approval Email with link EZRE'];
List<ContentVersion> contentList = new List<ContentVersion>();

ContentWorkspace library = [SELECT id FROM ContentWorkspace LIMIT 1];
System.Debug('library.id:'+ library.id);
/* contentList = [Select Id, ContentDocumentId,VersionData from ContentVersion where FirstPublishLocationId = :library.id];
Blob strVersionData;
for(ContentVersion cversion :contentList)
{
strVersionData = cversion.VersionData;
System.Debug('strVersionData&colon;'+ strVersionData);
} */
ContentVersion contentVersionObj = new ContentVersion();
//contentVersionObj.ContentURL = 'http://www.google.com';
contentVersionObj.title = 'Google';//contentVersionObj.Enablement_Area__c = 'Acct Mgmt';
contentVersionObj.FirstPublishLocationId = library.id;
contentVersionObj.Candidate_Id__c = cc1.Id;
contentVersionObj.VersionData = Blob.valueOf('Ayangar') ;
contentVersionObj.PathOnclient = 'http://www.google.com';
contentVersionObj.Title ='Management Approach';
// contentVersionObj.ContentDocumentId = cv1.ContentDocumentId;

insert contentVersionObj;
System.Debug('ContentVersionObj:'+ contentVersionObj);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('Sasikumar.Word');
efa.setBody(Blob.ValueOf(et.Body));
//efa.setBody(Blob.valueOf('Ayangar'));
//efa.setContentType('.word'); //
System.Debug('efa:' +efa);
String[] toAddresses = new string[]{'dummy@yahoo.com'};
mail.setTargetObjectId(user.Id);
mail.setToAddresses(toAddresses);
//mail.setplaintextBody('plainbody');

mail.setSenderDisplayName('Charan Tej');

mail.setTemplateId(et.Id);
// mail.setWhatId(c.Id);
mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
mail.saveAsActivity = false;
// Sends the email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});
//


insert coa;

Candidate_Mapping__c coa1 = [Select Id,Status1__c, LR_Status__c, MR_Status__c, MR_Status1__c from Candidate_Mapping__c where Candidate__c =: cc1.Id and Requirement__c =: rc1.id limit 1];
coa1.Status1__c = 'Candidate started';
// coa.LR_Status__c = 'Approved';
// coa.MR_Status__c = 'Rejected';
//coa1.Status1__c = 'LR Rejected';
update coa1;



}
}

 

 

 

 

 

 

 

  • September 24, 2013
  • Like
  • 0

hi all,

 

how to avoid the soql stmts inside the for loop in this class. plz help me.

 

public class assigncandidatestatusemailalert
{

public void SendEmail()
{

List<UserRole> UsersRoleList = new List<UserRole>([Select Id, Name from UserRole where Name = 'Vice President' or Name = 'Business Development Manager' or Name ='Management Representative' or Name ='Business Development Executive']);

System.debug('UserList123:' + UsersRoleList );

for(UserRole UsersRoleList123 :UsersRoleList)
{
List<User> UsersList = new List<User>([ SELECT Id, Name, Email FROM User where IsActive = true and UserRoleId = : UsersRoleList123.Id]);

System.debug('userlist1234' + UsersList);

for ( User userlist1 : UsersList )
{
List<Candidate_Mapping__c> candidatemappinglist = new List<Candidate_Mapping__c>( [SELECT Candidate__r.Candidate_Full_Name__c,Requirement__r.Name,Requirement__r.Job_Title__c, Requirement__r.Opportunity_Code__c, Requirement__r.CreatedDate,status1__c,Req_Owner_Email__c,Requirement_Owner__c FROM Candidate_Mapping__c where Submitted_to_Client__c ='' and status1__c = 'approved' and LastModifiedBy.Id = : userlist1.Id and LastModifiedDate = Last_n_days : 14]);

system.debug('candidatemappinglist :' + candidatemappinglist );

String htmlBody ;

Messaging.SingleEmailMessage mail;

htmlBody ='Dear '+userlist1 .Name+',</br></br>';

htmlBody =htmlBody +'<table style="border: 1px solid black;border-collapse:collapse;"><tr><td style="border: 1px solid black;"><b>Candidate</b> </td><td style="border: 1px solid black;"><b>Requirement</b> </td><td style="border: 1px solid black;"><b>Requirement Code</b></td><td style="border: 1px solid black;"><b>Client Name</b></td><td style="border: 1px solid black;"><b>Requirement Created Date</b></td></tr>';


for (Candidate_Mapping__c cm :candidatemappinglist )
{
htmlBody = htmlBody + '<tr><td style="border: 1px solid black;">'+cm .Candidate__r.Candidate_Full_Name__c+'</td><td style="border: 1px solid black;">'+cm.Requirement__r.Name+'</td><td style="border: 1px solid black;">'+cm.Requirement__r.Opportunity_Code__c+'</td><td style="border: 1px solid black;">'+cm.Requirement__r.Job_Title__c+'</td><td style="border: 1px solid black;">'+cm.Requirement__r.CreatedDate+'</td></tr>';

}

htmlBody = htmlBody +'</table></br>Either it is yet to be submitted to the client or the details are not updated in the EZRE system.</br> Please close this action item asap. </br></br>Regards</br>EZRE Team';

mail = new Messaging.SingleEmailMessage();

String[] address = new String[]{userlist1.Email};
mail.setToAddresses(address);
mail.setHtmlBody(htmlBody );
mail.setSubject('Submitted to client alert');
String[] bccaddress = new String[]{'abinaya_s@preludesys.com'};
mail.setBccAddresses(bccaddress);
mail.saveAsActivity = false;
if( candidatemappinglist.size() > 0 )
{

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}

}
}
}

  • September 18, 2013
  • Like
  • 0

Hi all,

 

I am facing too many soql queries in 2 of my triggers. 

 

In the first trigger i am facing issue in List<Candidate__c> candidatelist = [Select Id, Placed__c, Star_Candidate__c from candidate__c where id =: candidateids limit 1];

 

In the second trigger i am facing issue in listCM = [Select Candidate__c, Requirement__c from Candidate_Mapping__c where id =:contentId];

 

Please find the triggers below. 

 

trigger candidatestartedupdate on Candidate_Mapping__c (after update)
{

if(Trigger.isUpdate)
{

string testId = Trigger.new[0].Id;

set<ID> candidateids = New set<ID>();

set<ID> requirementids = New set<ID>();

// List<Candidate_Mapping__c> cm1 = [select candidate__c, requirement__c, status1__c,Candidate_started__c from Candidate_Mapping__c where id =:testId limit 1];

for(Candidate_Mapping__c cm : Trigger.new)
{

if (cm.Candidate_started__c == 'yes')
{
requirementids.add(cm.requirement__c);

candidateids.add(cm.candidate__c);

}

}

List<Requirement__c> reqlist = [Select Id, won__c from requirement__c where id in : requirementids limit 1];

system.debug('reqlist size:' + reqlist.size());

List<Candidate__c> candidatelist = [Select Id, Placed__c, Star_Candidate__c from candidate__c where id =: candidateids limit 1];

system.debug('candidatelist size:' + candidatelist.size());


for(integer i = 0 ; i< reqlist.size(); i++)
{
reqlist[i].won__c = true;
}

for(integer j = 0 ; j< candidatelist.size(); j++)
{
candidatelist[j].Star_Candidate__c = true;
candidatelist[j].Placed__c = true;
}

update reqlist;

update candidatelist;

}


}

 

 

 

trigger updateresumessubmitted on Candidate_Mapping__c (after insert, after update)
{

integer ressubmitted;
integer ressubmitted1;
string UserId = UserInfo.getUserId();
System.Debug('UserId =' + UserId);

Candidate_Mapping__c cm = Trigger.new[0];

List<Aggregateresult> ar= new List<Aggregateresult>();
//Map<Integer,Aggregateresult> getRequirement = new Map<Integer,Aggregateresult>();
set<Id> RequirementIds = new Set<Id>();
List<Requirement__c> reqlist = new List<Requirement__c>();
List<Candidate_Mapping__c> listCM = new List<Candidate_Mapping__c>();

if(Trigger.isUpdate || Trigger.isInsert)
{

string contentId = Trigger.new[0].Id;

listCM = [Select Candidate__c, Requirement__c from Candidate_Mapping__c where id =:contentId];

for(Candidate_Mapping__c cm1 : listCM)
{
system.debug('cm1:' + cm1);

RequirementIds.add(cm1.Requirement__c);
}

reqlist = [Select Id, Submitted_Resumes__c, status__c,cumulative_resumes_submitted__c from requirement__c where id =:RequirementIds limit 1];
system.debug('reqlist :' +reqlist);

ar = [SELECT count(Id) cnt FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c in:RequirementIds];
system.debug('ar:' +ar);

for(AggregateResult ar1 : ar)
{
ressubmitted = Integer.valueOf(ar1.get('cnt'));
system.debug('ressubmitted :' +ressubmitted);

for(requirement__c req : reqlist)
{
req.cumulative_resumes_submitted__c = ressubmitted;
system.debug('cumulative_resumes_submitted__c :' + req.cumulative_resumes_submitted__c);
system.debug('status__c12 :'+ req.status__c);
if(req.status__c == 'Open')
{
system.debug('status__c123 :'+ req.status__c);
for(integer i = 0 ; i< reqlist.size(); i++)
{
reqlist[i].Submitted_Resumes__c = ressubmitted;
}
}

if(req.status__c == 'Re-open' )
{
system.debug('status__c1 :'+ req.status__c);
system.debug('cm.Status1__c11 :'+ cm.Status1__c);
system.debug('submitted_resumes :' + req.Submitted_Resumes__c);
system.debug('cm.LRdate__c :' + cm.LRdate__c);
if(cm.status1__c == 'applied' && cm.createdbyid == UserId || cm.status1__c == 'LR Approved' && cm.createdbyid == UserId || cm.status1__c == 'Approved' && cm.createdbyid == UserId )
{
system.debug('status__c00:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c + 1;
system.debug('submitted_resumes0 :' + req.Submitted_Resumes__c);
}
else if (cm.status1__c == 'LR Rejected' && cm.createdbyid == UserId && req.Submitted_Resumes__c == 0 || cm.status1__c == 'Rejected' && cm.createdbyid == UserId && req.Submitted_Resumes__c == 0)
{
system.debug('status__c 1123:'+ req.status__c);
req.Submitted_Resumes__c = 0;
system.debug('submitted_resumes3 :' + req.Submitted_Resumes__c);
}

else if (cm.status1__c == 'rejected' || cm.status1__c == 'LR Rejected')
{
// system.debug('cm.LRdate__c :' + cm.LRdate__c);
system.debug('status__c 1122:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c - 1;
system.debug('submitted_resumes2 :' + req.Submitted_Resumes__c);
}
else
{
system.debug('status__c 1121:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c;
system.debug('submitted_resumes1 :' + req.Submitted_Resumes__c);
}
}

system.debug('cm.Status1__c :'+ cm.Status1__c);
system.debug('status__c :'+ req.status__c);
system.debug('submitted_resumes3 :' + req.Submitted_Resumes__c);

upsert reqlist;
system.debug('reqlist1:' +reqlist);

//}

}
}
}

}

  • September 18, 2013
  • Like
  • 0

Hi,

 

I am facing an issue like "too many sqol queries : 101" when i run a test class.

 

I will post my code here:

 

 

trigger updateassreqwon on Requirement__c (after update) 


if(Trigger.isUpdate) 

string reqId = Trigger.old[0].Id;

Requirement__c listR = [Select Id, Name, job_title__c, won__c from Requirement__c where Id =:reqId limit 1]; 

// List<RequirementAssignment__c> listreq = [Select Id, Name, won__c, Lead_Recruiter__c, Recruiter__c,Requirement__c from RequirementAssignment__c where requirement__c=:reqId limit 1];

// System.Debug('listreq :' +listreq); 

for(Requirement__c req:Trigger.old) 


Requirement__c R = new Requirement__c(won__c = listR.won__c);

List<RequirementAssignment__c> RAA = new List<RequirementAssignment__c>(); 

{
for(RequirementAssignment__c pc: [Select Id, Name, won__c, Lead_Recruiter__c, Recruiter__c,Requirement__c from RequirementAssignment__c where requirement__c=:reqId limit 1])

System.Debug('pc.Lead_Recruiter__c :' + pc.Lead_Recruiter__c); 
if(pc.Lead_Recruiter__c == null) 
{

System.Debug('pc.Lead_Recruiter__c :' + pc.Lead_Recruiter__c); 

user up = [Select u.Id from User u where (u.Profile.Name ='Lead Recruiter' or u.Profile.Name ='LR Chatter Only User') and Isactive = true limit 1]; 
pc.Lead_Recruiter__c = up.id; 

if(R.won__c == true) 
pc.won__c = 'Yes'; 
else 
pc.won__c = 'No'; 
System.Debug('pc.won__c :' + pc.won__c); 
RAA.add(pc); 



if(RAA.size() >0 )

Database.DMLOptions dml = new Database.DMLOptions(); 
// dml.optAllOrNone = false;
database.update(RAA,dml); 


} // if listreq.size Ends 
}

}
}

 

 

In this trigger, i am facing soql limit error in for(RequirementAssignment__c pc: [Select Id, Name, won__c, Lead_Recruiter__c, Recruiter__c,Requirement__c from RequirementAssignment__c where requirement__c=:reqId limit 1]) line.

 

trigger updateresumessubmitted on Candidate_Mapping__c (after insert, after update)
{

integer ressubmitted;
integer ressubmitted1;
string UserId = UserInfo.getUserId();
System.Debug('UserId =' + UserId);

if(Trigger.isUpdate || Trigger.isInsert)
{

for(Candidate_Mapping__c cm : Trigger.new)
{
system.debug('cm:' + cm);

List<Requirement__c> reqlist = [Select Id, Submitted_Resumes__c, status__c,cumulative_resumes_submitted__c from requirement__c where id =:cm.requirement__c limit 1];

system.debug('reqlist :' +reqlist);

//List <AggregateResult> ar = [SELECT count(Id) cnt FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c =:cm.requirement__c];

//List <Candidate_Mapping__c> ar = [SELECT Id FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c =:cm.requirement__c limit 1];
// system.debug('ar:' +ar);

for(AggregateResult ar1 : [SELECT count(Id) cnt FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c =:cm.requirement__c])
{
ressubmitted = Integer.valueOf(ar1.get('cnt'));
system.debug('ressubmitted :' +ressubmitted);

for(requirement__c req : reqlist)
{
req.cumulative_resumes_submitted__c = ressubmitted;
system.debug('cumulative_resumes_submitted__c :' + req.cumulative_resumes_submitted__c);
system.debug('status__c12 :'+ req.status__c);
if(req.status__c == 'Open')
{
system.debug('status__c123 :'+ req.status__c);
for(integer i = 0 ; i< reqlist.size(); i++)
{
reqlist[i].Submitted_Resumes__c = ressubmitted;
}
}

if(req.status__c == 'Re-open' )
{
system.debug('status__c1 :'+ req.status__c);
system.debug('cm.Status1__c11 :'+ cm.Status1__c);
system.debug('submitted_resumes :' + req.Submitted_Resumes__c);
system.debug('cm.LRdate__c :' + cm.LRdate__c);
if(cm.status1__c == 'applied' && cm.createdbyid == UserId || cm.status1__c == 'LR Approved' && cm.createdbyid == UserId || cm.status1__c == 'Approved' && cm.createdbyid == UserId )
{
system.debug('status__c00:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c + 1;
system.debug('submitted_resumes0 :' + req.Submitted_Resumes__c);
}
else if (cm.status1__c == 'LR Rejected' && cm.createdbyid == UserId && req.Submitted_Resumes__c == 0 || cm.status1__c == 'Rejected' && cm.createdbyid == UserId && req.Submitted_Resumes__c == 0)
{
system.debug('status__c 1123:'+ req.status__c);
req.Submitted_Resumes__c = 0;
system.debug('submitted_resumes3 :' + req.Submitted_Resumes__c);
}

else if (cm.status1__c == 'rejected' || cm.status1__c == 'LR Rejected')
{
// system.debug('cm.LRdate__c :' + cm.LRdate__c);
system.debug('status__c 1122:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c - 1;
system.debug('submitted_resumes2 :' + req.Submitted_Resumes__c);
}
else
{
system.debug('status__c 1121:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c;
system.debug('submitted_resumes1 :' + req.Submitted_Resumes__c);
}
}

system.debug('cm.Status1__c :'+ cm.Status1__c);
system.debug('status__c :'+ req.status__c);
system.debug('submitted_resumes3 :' + req.Submitted_Resumes__c);

upsert reqlist;
system.debug('reqlist1:' +reqlist);

}

}
}
}

}

 

In this trigger, i am facing soql limit error in for(AggregateResult ar1 : [SELECT count(Id) cnt FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c =:cm.requirement__c].

 

 

When i run the below test class i am facing error in any one of the above 2 stmts. 

 

 

@isTest
private class testclassCandidateMapfromCandidatesEdit
{
static testMethod void myUnitTest()
{

String oppid;
String cid;
String Userid;
Integer i,j,k;

Id id1 = UserInfo.getUserRoleId();
UserRole test1 = [Select Name from UserRole where id = :id1 limit 1];
system.test.starttest();

Profile p = [SELECT Id FROM Profile where Name = 'R Chatter Only User' ];
userRole r=[select id from userrole where Name = 'Recruiter' ];
User u = new User(Alias = 'testa', Email='standarduser1@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testaa', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='standarduser1@testorg.com.ezredev',userRoleid=r.id);

System.runAs(u)
{
Candidate_Mapping__c coa =new Candidate_Mapping__c();

coa.status1__c = 'Applied';
coa.Employer_s_Authorization__c = 'test';
coa.LR_Comments__c = 'test by lr';
coa.MR_Comments__c = 'test by MR';
coa.Requirement_Owner_Email__c = 'testOwner@preludesys.com';
coa.Manager_Email_ID__c = 'testOwner1@preludesys.com';
coa.R_Comments__c = '';
coa.LR_Status__c = 'Rejected';
coa.MR_Status__c = 'Applied';
coa.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Submitted_to_Client__c = 'Yes';
coa.Interview_Scheduled__c = 'Yes';
coa.Interview_Accepted__c = 'Yes';
coa.Client_Interviewed__c = 'Yes';
coa.Client_Offered__c = 'Yes';
coa.Candidate_started__c = 'Yes';
coa.Comments__c = '';

candidate__c cc1=new candidate__c();

cc1.Name='test';
cc1.Last_name__c='testoneo';
cc1.Current_city__c='chennai';
cc1.Current_state__c='Maine';
cc1.Gender__c='Male';
cc1.Employer_Name__c='ttt';
cc1.Email__c='test@gmail.com';
cc1.interview_contact_phone__c='Mobile Phone';
cc1.Contract_type__c='Corp to Corp';
cc1.visa_type__c='H1 B';
cc1.cost__c =100;
cc1.mobile_phone_no__c='9890043500';
cc1.employer_contact_email__c='test@gmail.com';
cc1.Employer_Contact_Name_Name__c='tt';
cc1.Employer_Mobile_No__c='9988009876';
cc1.Employer_Name__c = 'jos';
cc1.Employer_Work_Phone_No__c = '(425) 264-6771';

cc1.Followup_Date__c =date.today();
insert cc1;
coa.Candidate__c=cc1.id;
system.debug('candid:'+cc1.id);

requirement__c rc1=new requirement__c();

rc1.Name='SampathReq';
rc1.Job_Title__c='.net';
rc1.Duration__c='6';
rc1.No_Of_Resumes__c=2;
rc1.Min_Cost__c=100;
rc1.Max_Cost__c=200;
rc1.Rate__c=200;
rc1.Rate_Basis__c='Hourly';
rc1.Status__c='open';
rc1.Position_Type__c='Contract';
rc1.State__c='CA';
rc1.City__c='CA';
rc1.Est_Start_Date__c=date.today();
rc1.won__c = true;
insert rc1;
coa.Requirement__c=rc1.id;

RequirementAssignment__c oppa=new RequirementAssignment__c();
oppa=new RequirementAssignment__c();
oppa.Requirement__c=rc1.Id;
oppa.Recruiter__c =u.Id;
oppa.won__c = 'yes';
System.Debug('U:'+ oppa.Recruiter__c);
insert oppa;

insert coa;

List<ContentVersion> cv = new List<ContentVersion>();
cv = [Select Id, Candidate_ID__c From ContentVersion where Candidate_ID__c =:coa.Candidate__c limit 1] ;
System.Debug('CV : '+ cv);
if(cv.Size()>0)
{
for(ContentVersion cv1 : cv)
{
Candidate__c can = new Candidate__c(Id = cc1.Id);
can.Resume_Attach__c = '0584000000003RrAAI';
update can;
}
}

CandidateMapfromCandidatesEdit cc = new CandidateMapfromCandidatesEdit();

cc.save();
apexpages.currentpage().getparameters().put('cid' , coa.id);
cc.save();
system.assert(coa!= null);
cc.cancel();
cc.save();
}

Profile p1 =[SELECT Id From Profile where Name= 'LR Chatter Only User'];
userRole r1 =[SELECT Id FROM UserRole where Name = 'Lead Recruiter'];
User u1 = new User(Alias = 'testuser', Email='testUser@testorg.com',
EmailEncodingKey='UTF-8', LastName='TestUseraa', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p1.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='testUser@testorg.com.ezredev',userRoleid=r1.id);
System.runAs(u1){
Candidate_Mapping__c coa1 =new Candidate_Mapping__c();

coa1.status1__c = 'Applied';
coa1.Employer_s_Authorization__c = 'test';
coa1.LR_Comments__c = 'test by lr';
coa1.MR_Comments__c = 'test by MR';
coa1.Requirement_Owner_Email__c = 'testOwn1@preludesys.com';
coa1.Manager_Email_ID__c = 'testOwn1@preludesys.com';

coa1.R_Comments__c = '';
coa1.LR_Status__c = 'Rejected';
coa1.MR_Status__c = 'Applied';
coa1.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa1.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa1.Submitted_to_Client__c = 'Yes';
coa1.Interview_Scheduled__c = 'Yes';
coa1.Interview_Accepted__c = 'Yes';
coa1.Client_Interviewed__c = 'Yes';
coa1.Client_Offered__c = 'Yes';
coa1.Candidate_started__c = 'Yes';
coa1.Comments__c = '';

candidate__c cc1=new candidate__c();
cc1.Name='testtwo';
cc1.last_name__c='testtwo';
cc1.current_city__c='chennai';
cc1.current_state__c='Maine';
cc1.gender__c='Male';
cc1.Employer_Name__c='ttt';
cc1.email__c='test@gmail.com';
cc1.interview_contact_phone__c='Mobile Phone';
cc1.contract_type__c='w2';
cc1.visa_type__c='H1 B';
cc1.cost__c =100;
cc1.mobile_phone_no__c='9890043500';
cc1.employer_contact_email__c='test@gmail.com';
cc1.Employer_Contact_Name_Name__c='tyt';
cc1.Employer_Mobile_No__c='9988009876';

insert cc1;
coa1.Candidate__c=cc1.id;
system.debug('candid:'+cc1.id);

requirement__c rc1=new requirement__c();
rc1.Name='SampathReq0';
rc1.Job_Title__c='.net0';
rc1.Duration__c='6';
rc1.No_Of_Resumes__c=2;
rc1.Min_Cost__c=100;
rc1.Max_Cost__c=200;
rc1.Rate__c=200;
rc1.Rate_Basis__c='Hourly';
rc1.Status__c='open';
rc1.Position_Type__c='Contract';
rc1.State__c='CA';
rc1.City__c='CA';
rc1.Est_Start_Date__c=date.today();
rc1.won__c = true;
insert rc1;
coa1.Requirement__c=rc1.id;

RequirementAssignment__c oppa=new RequirementAssignment__c();
oppa=new RequirementAssignment__c();
oppa.Requirement__c=rc1.Id;
oppa.lead_recruiter__c =u1.Id;
oppa.won__c = 'yes';
System.Debug('U:'+ oppa.lead_recruiter__c);
insert oppa;
insert coa1;

List<ContentVersion> cv = new List<ContentVersion>();
cv = [Select Id, Candidate_ID__c From ContentVersion limit 1] ;
if(cv.Size()>0)
{
for(ContentVersion cv1 : cv)
{
Candidate__c can = new Candidate__c(Id = cv1.Id);

//can.Cost__c = 0;
can.Resume_Attach__c = cv1.Id;
update can;
}
}

CandidateMapfromCandidatesEdit cc = new CandidateMapfromCandidatesEdit();
cc.save();
apexpages.currentpage().getparameters().put('cid' , coa1.id);

cc.save();

system.assert(coa1!= null);

cc.cancel();

cc.save();
}
system.test.stoptest();
}
}

 

Some times i am facing issue in the first trigger and some times i am facing this issue in 2nd trigger.

 

Kindly advice.

 

 

 

 

 

  • September 11, 2013
  • Like
  • 0

When i run the test class i am getting this error message. Any idea abt this? plz help me out.

  • September 06, 2013
  • Like
  • 0

Hi,

 

I have a custom object named candidate (Salesforce Std Page layout) and in that we are capturing candidate email address.

 

I would like to send email to the candidate by clicking send email custom button. By clicking the send email button, outlook should  open with to as candidate email address and user can enter the body and subject. 

 

Note: I am not integrated outlook with salesforce

 

How to achieve this? Kindly advise.

 

 

Hi,

 

Whenever a candidate is approved and not submitted to client by the requirement owner on same date, an e-mail has to be sent to the requirement owner by end of day. I have selected the candidates which are appoved and not submitted to client using SOQL. 

 

My query is "SELECT Candidate__c,Requirement__c, Requirement_Code__c, Requirement_Owner__c,Req_Owner_Email__c,status1__c FROM Candidate_Mapping__c where  Submitted_to_Client__c =''and status1__c = 'Approved' ". 

 

No.of rows retrieved is 55 in my sandbox environment. 

 

I have used text template to send this email to the owners. I am facing a issue like "No of Email Invocation is more than 10" Governor limits.

 

 

Code using text template:

 

public class assigncandidatestatusemailalert
{

public void SendEmail()
{

List<Candidate_Mapping__c> candidatemappinglist = new List<Candidate_Mapping__c>( [SELECT Candidate__c, Id, Req_Owner_Email__c, Requirement__c, Requirement_Owner__c, Requirement_Owner_Email__c, Status1__c,LastModifiedDate FROM Candidate_Mapping__c where Submitted_to_Client__c = '' limit 30]);

system.debug('candidatemappinglist :' + candidatemappinglist );

String CandID, ReqmtID;

if(candidatemappinglist != null)
{
Messaging.SingleEmailMessage mail;

for (Candidate_Mapping__c cm :candidatemappinglist )
{
CandID = cm .Candidate__c;
system.debug('candID:' + CandID);

ReqmtID = cm.Requirement__c;
system.debug('ReqmtID:' + ReqmtID);

Candidate__c Candt = [Select Id, Candidate_Full_Name__c from Candidate__c where Id = :CandID];
Requirement__c Reqmt = [Select Id,Name,Opportunity_Code__c,OwnerId from Requirement__c where id = :ReqmtID];
System.debug('Reqmt:' + Reqmt);
User u = [select Id, Email, Name from User where Id = :Reqmt.OwnerId];
System.debug('user:' + u);

EmailTemplate et = [Select Id, Subject, HtmlValue, Body from EmailTemplate where Name = 'Submitted to Client Alert'];
System.Debug('EmailTemplate Id: ' + et.id);
System.Debug('et : ' + et);
// mail.setSenderDisplayName('Abinaya');

// String htmlBody = et.HtmlValue;
String plainBody = et.Body;


if(u.Name != null)
{
plainBody = plainBody.replace('{!Requirement__c.OwnerFullName}', u.Name);
}

else
{
plainBody = plainBody.replace('{!Requirement__c.OwnerFullName}', ' ');
}

if(Candt.Candidate_Full_Name__c != null)
{
// htmlBody = htmlBody.replace('{!Candidate__c.Candidate_Full_Name__c}', Candt.Candidate_Full_Name__c);
plainBody = plainBody.replace('{!Candidate__c.Candidate_Full_Name__c}', Candt.Candidate_Full_Name__c);
System.Debug('Candt Name:' + Candt.Candidate_Full_Name__c);
}
else
{
//htmlBody = htmlBody.replace('{!Candidate__c.Candidate_Full_Name__c}', ' ');
plainBody = plainBody.replace('{!Candidate__c.Candidate_Full_Name__c}', ' ');
}

if(Candt.Id != null)
{
// htmlBody = htmlBody.replace('{!Candidate__c.Id}', Candt.Id);
plainBody = plainBody.replace('{!Candidate__c.Id}', Candt.Id);
System.Debug('Candt Id:' + Candt.Id);
}
else
{
// htmlBody = htmlBody.replace('{!Candidate__c.Id}', ' ');
plainBody = plainBody.replace('{!Candidate__c.Id}', ' ');
}

if(Reqmt.Name != null )
{
// htmlBody = htmlBody.replace(' {!Requirement__c.Name}', Reqmt.Name);
plainBody = plainBody.replace('{!Requirement__c.Name}', Reqmt.Name);
System.Debug('Reqmt Name:' + Reqmt.Name);
}
else
{
// htmlBody = htmlBody.replace('{!Requirement__c.Name}', ' ');
plainBody = plainBody.replace('{!Requirement__c.Name}', ' ');
}

if(Reqmt.Opportunity_Code__c != null)
{
// htmlBody = htmlBody.replace('{!Requirement__c.Opportunity_Code__c}', Reqmt.Opportunity_Code__c );
plainBody = plainBody.replace('{!Requirement__c.Opportunity_Code__c}', Reqmt.Opportunity_Code__c );
System.Debug('Candt Name:' + Reqmt.Opportunity_Code__c );
}
else
{
// htmlBody = htmlBody.replace('{!Requirement__c.Opportunity_Code__c}', ' ');
plainBody = plainBody.replace('{!Requirement__c.Opportunity_Code__c}', ' ');
}

mail = new Messaging.SingleEmailMessage();

String[] address = new String[]{u.email};
mail.setToAddresses(address);


//System.Debug('HtmlBody:' + htmlBody);

System.Debug('Plain Body:' + plainBody);

// List<User>user = new List<User>([Select Id from User where IsActive = true and ProfileId = '00e40000000wnXc' ]);
// System.Debug('UserID: ' + user.id);

//String subject = et.Subject;
//mail.setTemplateId(et.id);
mail.setPlainTextBody(plainBody);
// mail.setHtmlBody(htmlBody );


String[] bccaddress = new String[]{'abinaya_s@preludesys.com'};

mail.setBccAddresses(bccaddress);

mail.saveAsActivity = false;
// mail.setTargetObjectId(user.Id);


Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}
}

}

}

 

 

So I am trying to send email through visualforce email template. 

 

For this i have created a class, component and visualforce email template.

 

Class:

 

public class SubmittedtoClientalert
{
public final List<Candidate_Mapping__c> candidatemappinglist ;
public final test[ ] candiateassign= new List<test>();
public final List<Candidate_Mapping__c> one = new List<Candidate_Mapping__c>();

public SubmittedtoClientalert()
{
candidatemappinglist = [SELECT Candidate__c,Requirement__c, Requirement_Code__c, Requirement_Owner__c,Req_Owner_Email__c,status1__c FROM Candidate_Mapping__c where Submitted_to_Client__c =''and status1__c = 'Approved' limit 30];

system.debug('candidatemappinglist :' + candidatemappinglist );

String CandID, ReqmtID;

if(candidatemappinglist != null)
{
Messaging.SingleEmailMessage mail;

for (Candidate_Mapping__c cm :candidatemappinglist )
{
test t= new test();
CandID = cm .Candidate__c;
system.debug('candID:' + CandID);
ReqmtID = cm.Requirement__c;
system.debug('ReqmtID:' + ReqmtID);

Candidate__c Candt = [Select Id, Candidate_Full_Name__c from Candidate__c where Id = :CandID];
Requirement__c Reqmt = [Select Id,Name,Opportunity_Code__c,OwnerId from Requirement__c where id = :ReqmtID];
System.debug('Reqmt:' + Reqmt);
User u = [select Id, Email, Name from User where Id = :Reqmt.OwnerId];
System.debug('user:' + u);
one.add(new Candidate_Mapping__c( LR_Comments__c= Candt.Candidate_Full_Name__c ,R_Comments__c= Reqmt.Name,MR_Comments__c= Reqmt.Opportunity_Code__c,status1__c= cm.status1__c));

}
}

}

public List<Candidate_Mapping__c> getcandidatemappinglist()
{
return candidatemappinglist ;
}

public List<Candidate_Mapping__c> getone()
{
return one;
}

public class test
{
public String candidatename { get; set; }
public String requirementname{ get; set; }
public String reqcode { get; set; }
public String status { get; set; }
}
}

 

Component:

 

<apex:component controller="SubmittedtoClientalert" access="global">
<apex:dataTable value="{!one}" var="proj" border="2">
<apex:column width="30%" style="align:left">
<apex:facet name="header">Candidate Name</apex:facet>
{!proj.LR_Comments__c}
</apex:column>
<apex:column width="30%" style="align:left">
<apex:facet name="header">Requirement Name</apex:facet>
{!proj.R_Comments__c}
</apex:column>
<apex:column width="40%" style="halign:left">
<apex:facet name="header">Requirement Code</apex:facet>
{!proj.MR_Comments__c}
</apex:column>
</apex:dataTable>
</apex:component>

 

 

I am retrieving the output in visualforce template if the query limit is 30. Otherwise too many queries 101 error is throwing.

 

How to resolve this error?. And also i need to seperate the candidate list based on the requirement owner and send email to the requirement owner with their candidate list.

 

Kindly advice.

In my custom object i have 7 status fields. All these are pick-list fields.
 
If the user update first status field, status message will be updated in the x field. I am doing this using trigger before insert and before update.
 
If the status message is approved and business day is 5(Last Modified date +7), I have to update the next pick-list field to "No" and update the date. I am able to achieve this using workflow field update.
 
Now based on the field update, i have to update the status message field(x) using trigger.
 
This is working fine for first record of the object. For the upcoming records the field (status message) is not updated using trigger where as the field update is happening correctly.
 
Kindly advice.

HI All,

 

We have a requirement to schedule a report on every Monday @10.00am and whenever there is a change in the report

We should email this report to Salesforce users and non Salesforce users.

The report is created with filter criteria like test is checked.

Currently we scheduled the report on every Monday @10.00 am and emailed to Salesforce users.

Is there any way to email the same report to non Salesforce users as well as when there is a change in the report?

Kindly advise.

 

Regards,

Abinaya S

Hi all,

I am unable to download xlsx files which is available in my vf page in chrome and IE. Kindly help me. 

In my controller i am using this stmt : attachBody = EncodingUtil.base64Encode(itrAttach.Body);

In VF Page : <a download="{!attachItem.attachName}" href="data:{!attachItem.attachContentType};base64,{!attachItem.attachBody}" > {!attachItem.attachName} </a>

Thanks in advance.

Regards,
Abinaya.
Hi all,

I would like to know how the business hours diff calculation is working?  I am facing a issue on it.

Start Time is : 7/30/2014 3:11 PM
End Time is  : 7/30/2014 3:00 PM

Business Hours is 9 AM to 6 PM (IST).

In code we have used  the below formula.

BusinessHours.diff(businessHoursId, StartTime, EndTime).

Please let me know how the calculation works?

Thanks in advance!!!

Regards,
Abinaya S
hi team,

Kindly help me how to clone the record with the selected field values. This should redirect to the edit page of the new cloned record

Regards,
Abi

Hi,

I need to write test class for inner class coverage. 

Class:

public class PerformanceReport
{
public String strFromDate {get; set;}
public String strToDate {get; set;}
public List<PerformanceReportClass> LstPerformanceReportClass {get;set;}
public Class PerformanceReportClass
{
public String strMRName{get;set;}
public String strMonth1{get;set;}
public String strMonth2{get;set;}
public String strMonth3{get;set;}
public String strMonth4{get;set;}
public String strMonth5{get;set;}
public String strMonth6{get;set;}
public String strMonth7{get;set;}
public String strMonth8{get;set;}
public String strMonth9{get;set;}
public String strMonth10{get;set;}
public String strMonth11{get;set;}
public String strMonth12{get;set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass1{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass2{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass3{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass4{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass5{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass6{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass7{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass8{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass9{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass10{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass11{get; set;}
public List<ReqmtDetailsClass> lstReqmtDetailsClass12{get; set;}
}
public class ReqmtDetailsClass
{
public string ReqmtName {get; set;}
public string ReqmtStatus {get; set;}
public string ReqmtPostdDate {get; set;}
public string ResumeReqstd {get; set;}
public string ResumeSubmtd {get; set;}
public string ResumeFirstPosted {get; set;}
public string ElapsedTimeFirstResumePosted {get; set;}
public string ReqmtClosedDate {get; set;}
public string ReqmtClosedHrs {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass2 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass3 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass4 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass5 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass6 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass7 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass8 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass9 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass10 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass11 {get; set;}
public List<CandtDetailsClass> lstCandtdetailClass12 {get; set;}
}

public class CandtDetailsClass
{
public string CandtName{get; set;}
public string CandtEmail{get; set;}
}
public PageReference GetReportDetails()
{
List<User> lstAllUser = new List<User>([SELECT id, name, LastModifiedDate, isActive from user where userroleid in (select id from userrole where name='Management Representative')]);
List<User> lstUser = new List<User>();
List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();
List<RequirementAssignment__c> FilterReqmtAssign ;
List<RequirementAssignment__c> FilterReqmtAssignMonthly ;
List<Requirement__c> lstReqmts = new List<Requirement__c>();
if(strFromDate != null && strToDate != null)
{
DateTime startDT = DateTime.parse(strFromDate);
system.debug('Date:' + startDT);
DateTime endDT = DateTime.parse(strToDate);
system.debug('Date:' + endDT);
Date NewStartDate;
Integer startMonth = startDT.monthgmt();
Integer endMonth = endDT.monthgmt();
Integer startYear = startDT.yeargmt();
Integer endYear = endDT.yeargmt();
for(User allUser : lstAllUser)
{
if(allUser.IsActive == true)
{
lstUser.add(allUser);
}
else
{
if(allUser.LastModifiedDate > startDT)
{
lstUser.add(allUser);
}
}
}
lstReqmtAssign = [select Status__c, Requirement__c, Lead_Recruiter__c, Recruiter__c, createddate, createdbyid from RequirementAssignment__c where createddate >: startDT and createddate <: endDT ];

LstPerformanceReportClass = new List<PerformanceReportClass>();
for(User MRUSer : lstUser)
{
FilterReqmtAssign = new List<RequirementAssignment__c>();
for(RequirementAssignment__c ReqmAssign : lstReqmtAssign)
{
if(MRUSer.id == ReqmAssign.createdbyid)
{
FilterReqmtAssign.Add(ReqmAssign);
}
}
PerformanceReportClass objPerformanceReportClass = new PerformanceReportClass();
objPerformanceReportClass.strMonth1 = objPerformanceReportClass.strMonth2 = objPerformanceReportClass.strMonth3 = objPerformanceReportClass.strMonth4 = objPerformanceReportClass.strMonth5 = objPerformanceReportClass.strMonth6 = objPerformanceReportClass.strMonth7 = objPerformanceReportClass.strMonth8 = objPerformanceReportClass.strMonth9 = objPerformanceReportClass.strMonth10 = objPerformanceReportClass.strMonth11 = objPerformanceReportClass.strMonth12 = string.valueOf(0);
Integer count = 0;
NewStartDate = startDT.date();
Integer incrMonth = NewStartDate.month();
objPerformanceReportClass.strMRName = MRUSer.name;
if(FilterReqmtAssign != null)
{
for(integer i=startMonth; i<=endMonth; i++)
{
FilterReqmtAssignMonthly = new List<RequirementAssignment__c>();
for(RequirementAssignment__c ReqmAssignUser : FilterReqmtAssign)
{
DateTime ReqmtAssignDt = ReqmAssignUser.createddate;
Date ReqmAssignDate = Date.NewInstance(ReqmtAssignDt.yeargmt(), ReqmtAssignDt.monthgmt(), ReqmtAssignDt.daygmt());
System.Debug('Reqmt Assign Date:' +ReqmAssignDate);
System.Debug('Original Date:' + NewStartDate.month());
if((ReqmAssignDate.month() == incrMonth) && (ReqmAssignDate.year() == NewStartDate.year()))
{
FilterReqmtAssignMonthly.Add(ReqmAssignUser);
}
}
incrMonth++;
System.Debug('List Size:' +FilterReqmtAssignMonthly.size());
if(i==1)
{
objPerformanceReportClass.strMonth1 = string.valueOf(FilterReqmtAssignMonthly.size());
System.Debug('objReqmtAssignClass.strDate1:' +objPerformanceReportClass.strMonth1);
objPerformanceReportClass.lstReqmtDetailsClass1 = new List<ReqmtDetailsClass>();
Set<ID> setReqId = new Set<ID>();
for(RequirementAssignment__c Reqmt : FilterReqmtAssignMonthly)
{
System.Debug('Filter List Monthly'+FilterReqmtAssignMonthly);
System.Debug('Monthly Reqmt' +Reqmt);
setReqId.add(Reqmt.Requirement__c);
}
System.Debug('Id Set:' +setReqId);
if(setReqId.size()>0)
{
for(ID ReqID : setReqId)
{
System.Debug('Reqmt Id:' + ReqID);
List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c where id =:ReqID];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);
List<Candidate_Mapping__c> lstCandtMapping = [select Candidate__r.Candidate_Full_Name__c , Candidate__r.Email__c from Candidate_Mapping__c where Requirement__c =:ReqID];
System.Debug('Candidates List:' +lstCandtMapping);
if(lstReqmtsResume.size()>0)
{
for(Requirement__c req:lstReqmtsResume)
{
ReqmtDetailsClass objReqmtDetailsClass1 = new ReqmtDetailsClass();
objReqmtDetailsClass1.lstCandtdetailClass = new List<CandtDetailsClass>();
System.Debug('Reqmt Resume:' +req);
objReqmtDetailsClass1.ReqmtName = string.valueOf(req.Name);
objReqmtDetailsClass1.ReqmtStatus = string.valueOf(req.Status__c);
objReqmtDetailsClass1.ReqmtPostdDate = string.valueOf(req.createddate);
objReqmtDetailsClass1.ResumeReqstd = string.valueOf(req.No_Of_Resumes__c);
objReqmtDetailsClass1.ResumeSubmtd = string.valueOf(req.Resumes_Submitted__c);
objReqmtDetailsClass1.ResumeFirstPosted = string.valueOf(req.Assign_Candidate_date__c);
objReqmtDetailsClass1.ElapsedTimeFirstResumePosted = string.valueOf(req.First_Response__c);
objReqmtDetailsClass1.ReqmtClosedDate = string.valueOf(req.Req_Closed_Date__c);
objReqmtDetailsClass1.ReqmtClosedHrs = string.valueOf(req.Req_Closed_hrs__c);
System.Debug('objReqmtDetailsClass1:'+objReqmtDetailsClass1);
objPerformanceReportClass.lstReqmtDetailsClass1.add(objReqmtDetailsClass1);
for(Candidate_Mapping__c candt :lstCandtMapping)
{
CandtDetailsClass objCandtDetailsClass1 = new CandtDetailsClass();
objCandtDetailsClass1.CandtName = string.valueOf(candt.Candidate__r.Candidate_Full_Name__c);
objCandtDetailsClass1.CandtEmail = string.valueOf(candt.Candidate__r.Email__c);
objReqmtDetailsClass1.lstCandtdetailClass.add(objCandtDetailsClass1);
}
}
}
}
}

}
else if(i==2)
{
objPerformanceReportClass.strMonth2 = string.valueOf(FilterReqmtAssignMonthly.size());
System.Debug('objReqmtAssignClass.strDate2:' +objPerformanceReportClass.strMonth2);
objPerformanceReportClass.lstReqmtDetailsClass2 = new List<ReqmtDetailsClass>();
Set<ID> setReqId = new Set<ID>();
for(RequirementAssignment__c Reqmt : FilterReqmtAssignMonthly)
{
System.Debug('Filter List Monthly'+FilterReqmtAssignMonthly);
System.Debug('Monthly Reqmt' +Reqmt);
setReqId.add(Reqmt.Requirement__c);
}
System.Debug('Id Set:' +setReqId);
if(setReqId.size()>0)
{
for(ID ReqID : setReqId)
{
System.Debug('Reqmt Id:' + ReqID);
List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c where id =:ReqID];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);
if(lstReqmtsResume.size()>0)
{
for(Requirement__c req:lstReqmtsResume)
{
ReqmtDetailsClass objReqmtDetailsClass2 = new ReqmtDetailsClass();
System.Debug('Reqmt Resume:' +req);
objReqmtDetailsClass2.ReqmtName = string.valueOf(req.Name);
objReqmtDetailsClass2.ReqmtStatus = string.valueOf(req.Status__c);
objReqmtDetailsClass2.ReqmtPostdDate = string.valueOf(req.createddate);
objReqmtDetailsClass2.ResumeReqstd = string.valueOf(req.No_Of_Resumes__c);
objReqmtDetailsClass2.ResumeSubmtd = string.valueOf(req.Resumes_Submitted__c);
objReqmtDetailsClass2.ResumeFirstPosted = string.valueOf(req.Assign_Candidate_date__c);
objReqmtDetailsClass2.ElapsedTimeFirstResumePosted = string.valueOf(req.First_Response__c);
objReqmtDetailsClass2.ReqmtClosedDate = string.valueOf(req.Req_Closed_Date__c);
objReqmtDetailsClass2.ReqmtClosedHrs = string.valueOf(req.Req_Closed_hrs__c);
System.Debug('objReqmtDetailsClass2:'+objReqmtDetailsClass2);
objPerformanceReportClass.lstReqmtDetailsClass2.add(objReqmtDetailsClass2);
}}}}}}
LstPerformanceReportClass.add(objPerformanceReportClass);
}}}
return null;
}}

Test Class:

@isTest
private class testclassperformancereport
{
static testmethod void myTestclass()
{
Candidate_Mapping__c cm = new Candidate_Mapping__c();

Candidate__c cc1=new Candidate__c();
cc1.Name='test';
cc1.Last_name__c='testonek';
cc1.Current_city__c='chennai';
cc1.Current_state__c='Maine';
cc1.Gender__c='Male';
cc1.Employer_Name__c='ttt';
cc1.Email__c='test@gmail.com';
cc1.interview_contact_phone__c='Mobile Phone';
cc1.Contract_type__c='Corp to Corp';
cc1.visa_type__c='H1 B';
cc1.cost__c =100;
cc1.mobile_phone_no__c='9890043500';
cc1.employer_contact_email__c='test@gmail.com';
cc1.Employer_Contact_Name_Name__c='tt';
cc1.Employer_Mobile_No__c='9988009876';
cc1.Employer_Name__c = 'jos';
cc1.Employer_Work_Phone_No__c = '(425) 264-6771';
cc1.Followup_Date__c =date.today();

System.test.startTest();
insert cc1;

cm.Candidate__c=cc1.id;
system.debug('candid:'+cc1.id);

Requirement__c rc1=new Requirement__c();

rc1.Name='SampathReq';
rc1.Job_Title__c='.net';
rc1.Duration__c='6';
rc1.No_Of_Resumes__c=2;
rc1.Min_Cost__c=100;
rc1.Max_Cost__c=200;
rc1.Rate__c=200;
rc1.Rate_Basis__c='Hourly';
rc1.Status__c='open';
rc1.Position_Type__c='Contract';
rc1.State__c='CA';
rc1.City__c='CA';
rc1.Est_Start_Date__c=date.today();
insert rc1;
User lruser = [select u.id from user u where (u.Profile.Name ='Lead Recruiter' or u.Profile.Name ='LR Chatter Only User') and u.ManagerId!=null and u.IsActive= True limit 1] ;
User ruser = [select u.id from user u where (u.Profile.Name ='Recruiter' or u.Profile.Name ='R Chatter Only User') and u.ManagerId!=null and u.IsActive= True limit 1] ;

RequirementAssignment__c reqas = new RequirementAssignment__c();

reqas.Requirement__c = rc1.id;
reqas.AssignStatus__c= 'true';
reqas.Won__c= 'no';
reqas.Lead_Recruiter__c = lruser.id;
//reqas.Recruiter__c = ruser.id;
insert reqas;

cm.Requirement__c=rc1.id;
system.debug('candid:'+cc1.id);

cm.Employer_s_Authorization__c = 'test';
cm.status1__c = 'Applied';
cm.LR_Comments__c = 'test by lr';
cm.MR_Comments__c = 'test by MR';
cm.Requirement_Owner_Email__c = 'testOwner@preludesys.com';
cm.Manager_Email_ID__c = 'testOwner1@preludesys.com';
cm.LR_Status__c = 'Approved';
cm.MR_Status__c = 'Approved';
cm.LR_Status_Date__c = string.valueOf(date.today());
cm.Submitted_to_Client__c = 'Yes';
cm.Interview_Scheduled__c = 'Yes';
cm.Interview_Accepted__c = 'Yes';
cm.Client_Interviewed__c = 'Yes';
cm.Client_Offered__c = 'Yes';
cm.Comments__c = '';
cm.MR_Status1__c = 'Approved' ;

User user = [Select Id from User limit 1] ;

EmailTemplate et = [Select Id, Subject, HtmlValue, Body from EmailTemplate where Name = 'Candidate Approval Email with link EZRE'];
List<ContentVersion> contentList = new List<ContentVersion>();

ContentWorkspace library = [SELECT id FROM ContentWorkspace LIMIT 1];
System.Debug('library.id:'+ library.id);

ContentVersion contentVersionObj = new ContentVersion();

contentVersionObj.title = 'Google';//contentVersionObj.Enablement_Area__c = 'Acct Mgmt';
contentVersionObj.FirstPublishLocationId = library.id;
contentVersionObj.Candidate_Id__c = cc1.Id;
contentVersionObj.VersionData = Blob.valueOf('Ayangar') ;
contentVersionObj.PathOnclient = 'http://www.google.com';
contentVersionObj.Title ='Management Approach';

insert contentVersionObj;
System.Debug('ContentVersionObj:'+ contentVersionObj);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('Sasikumar.Word');
efa.setBody(Blob.ValueOf(et.Body));
System.Debug('efa:' +efa);
String[] toAddresses = new string[]{'dummy@yahoo.com'};
mail.setTargetObjectId(user.Id);
mail.setToAddresses(toAddresses);

mail.setTemplateId(et.Id);

mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
mail.saveAsActivity = false;
// Sends the email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});

insert cm;

datetime nowdate = datetime.now();

string strfromdate = nowdate.format('MM/dd/yyyy hh:mm a');

datetime newdate= nowdate.addMonths(2);

string strtodate = newdate.format('MM/dd/yyyy hh:mm a');

List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();

PerformanceReport pr = new PerformanceReport();

list<PerformanceReportClass> c = new List<PerformanceReportClass>();

datetime startdate = datetime.parse(strfromdate);
system.debug('startdate :' + startdate);

datetime enddate = datetime.parse(strtodate);
system.debug('enddate :' + enddate);

lstReqmtAssign = [select Status__c, Requirement__c, Lead_Recruiter__c, Recruiter__c, createddate, createdbyid from RequirementAssignment__c where createddate >= 2013-09-01T00:00:00.000+0000 and createddate <=2013-09-25T00:00:00.000+0000 ];

System.debug('lstReqmtAssign: ' + lstReqmtAssign);


List<Requirement__c> lstReqmtsResume= [Select id, Name, Status__c, createddate, No_Of_Resumes__c, Resumes_Submitted__c, Assign_Candidate_date__c, First_Response__c, Req_Closed_Date__c, Req_Closed_hrs__c from Requirement__c where id =:rc1.id];
System.Debug('list Reqmts Resume:' +lstReqmtsResume);

List<Candidate_Mapping__c> lstCandtMapping = [select Candidate__r.Candidate_Full_Name__c , Candidate__r.Email__c from Candidate_Mapping__c where Requirement__c =:rc1.id];
System.Debug('Candidates List:' +lstCandtMapping);

pr.GetReportDetails();

}
}

 

What ever i modify in the test class, the code coverage is 3% only, Kindly help meto fix this.

 

Regards,

Abinaya.

 

Hi,

 

I have a requirement object and in that i have a status picklist which contains 4 status.

If the status is reopen, then the no.of resumes in the requirement object should be 0. And if the no.of resumes is 0, then an error message should be thrown like "enter the no. of resumes".

I am updating few other fields based on the reopen status in a trigger. So I am updating no.of resumes to 0 in that trigger and created a validation rule in requirement object like

if (no.of resumes == 0, true, false)
error message : enter the no.of resumes.


But the error message is throwing whenever i have mentioned no.of resumes greater than 0 (i.e 1).

 

 

Kindly advice.

Hi all,

 

I am facing too many soql queries in 2 of my triggers. 

 

In the first trigger i am facing issue in List<Candidate__c> candidatelist = [Select Id, Placed__c, Star_Candidate__c from candidate__c where id =: candidateids limit 1];

 

In the second trigger i am facing issue in listCM = [Select Candidate__c, Requirement__c from Candidate_Mapping__c where id =:contentId];

 

Please find the triggers below. 

 

trigger candidatestartedupdate on Candidate_Mapping__c (after update)
{

if(Trigger.isUpdate)
{

string testId = Trigger.new[0].Id;

set<ID> candidateids = New set<ID>();

set<ID> requirementids = New set<ID>();

// List<Candidate_Mapping__c> cm1 = [select candidate__c, requirement__c, status1__c,Candidate_started__c from Candidate_Mapping__c where id =:testId limit 1];

for(Candidate_Mapping__c cm : Trigger.new)
{

if (cm.Candidate_started__c == 'yes')
{
requirementids.add(cm.requirement__c);

candidateids.add(cm.candidate__c);

}

}

List<Requirement__c> reqlist = [Select Id, won__c from requirement__c where id in : requirementids limit 1];

system.debug('reqlist size:' + reqlist.size());

List<Candidate__c> candidatelist = [Select Id, Placed__c, Star_Candidate__c from candidate__c where id =: candidateids limit 1];

system.debug('candidatelist size:' + candidatelist.size());


for(integer i = 0 ; i< reqlist.size(); i++)
{
reqlist[i].won__c = true;
}

for(integer j = 0 ; j< candidatelist.size(); j++)
{
candidatelist[j].Star_Candidate__c = true;
candidatelist[j].Placed__c = true;
}

update reqlist;

update candidatelist;

}


}

 

 

 

trigger updateresumessubmitted on Candidate_Mapping__c (after insert, after update)
{

integer ressubmitted;
integer ressubmitted1;
string UserId = UserInfo.getUserId();
System.Debug('UserId =' + UserId);

Candidate_Mapping__c cm = Trigger.new[0];

List<Aggregateresult> ar= new List<Aggregateresult>();
//Map<Integer,Aggregateresult> getRequirement = new Map<Integer,Aggregateresult>();
set<Id> RequirementIds = new Set<Id>();
List<Requirement__c> reqlist = new List<Requirement__c>();
List<Candidate_Mapping__c> listCM = new List<Candidate_Mapping__c>();

if(Trigger.isUpdate || Trigger.isInsert)
{

string contentId = Trigger.new[0].Id;

listCM = [Select Candidate__c, Requirement__c from Candidate_Mapping__c where id =:contentId];

for(Candidate_Mapping__c cm1 : listCM)
{
system.debug('cm1:' + cm1);

RequirementIds.add(cm1.Requirement__c);
}

reqlist = [Select Id, Submitted_Resumes__c, status__c,cumulative_resumes_submitted__c from requirement__c where id =:RequirementIds limit 1];
system.debug('reqlist :' +reqlist);

ar = [SELECT count(Id) cnt FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c in:RequirementIds];
system.debug('ar:' +ar);

for(AggregateResult ar1 : ar)
{
ressubmitted = Integer.valueOf(ar1.get('cnt'));
system.debug('ressubmitted :' +ressubmitted);

for(requirement__c req : reqlist)
{
req.cumulative_resumes_submitted__c = ressubmitted;
system.debug('cumulative_resumes_submitted__c :' + req.cumulative_resumes_submitted__c);
system.debug('status__c12 :'+ req.status__c);
if(req.status__c == 'Open')
{
system.debug('status__c123 :'+ req.status__c);
for(integer i = 0 ; i< reqlist.size(); i++)
{
reqlist[i].Submitted_Resumes__c = ressubmitted;
}
}

if(req.status__c == 'Re-open' )
{
system.debug('status__c1 :'+ req.status__c);
system.debug('cm.Status1__c11 :'+ cm.Status1__c);
system.debug('submitted_resumes :' + req.Submitted_Resumes__c);
system.debug('cm.LRdate__c :' + cm.LRdate__c);
if(cm.status1__c == 'applied' && cm.createdbyid == UserId || cm.status1__c == 'LR Approved' && cm.createdbyid == UserId || cm.status1__c == 'Approved' && cm.createdbyid == UserId )
{
system.debug('status__c00:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c + 1;
system.debug('submitted_resumes0 :' + req.Submitted_Resumes__c);
}
else if (cm.status1__c == 'LR Rejected' && cm.createdbyid == UserId && req.Submitted_Resumes__c == 0 || cm.status1__c == 'Rejected' && cm.createdbyid == UserId && req.Submitted_Resumes__c == 0)
{
system.debug('status__c 1123:'+ req.status__c);
req.Submitted_Resumes__c = 0;
system.debug('submitted_resumes3 :' + req.Submitted_Resumes__c);
}

else if (cm.status1__c == 'rejected' || cm.status1__c == 'LR Rejected')
{
// system.debug('cm.LRdate__c :' + cm.LRdate__c);
system.debug('status__c 1122:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c - 1;
system.debug('submitted_resumes2 :' + req.Submitted_Resumes__c);
}
else
{
system.debug('status__c 1121:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c;
system.debug('submitted_resumes1 :' + req.Submitted_Resumes__c);
}
}

system.debug('cm.Status1__c :'+ cm.Status1__c);
system.debug('status__c :'+ req.status__c);
system.debug('submitted_resumes3 :' + req.Submitted_Resumes__c);

upsert reqlist;
system.debug('reqlist1:' +reqlist);

//}

}
}
}

}

  • September 18, 2013
  • Like
  • 0

Hi,

 

My account object have certain record types and also the page has been customized.

 

My requirement is for Profile A : He should be able to view the standard Account layout

And for profile B: He should view the customized Account Object.

 

Is it Possible??

 

Thanks in Advance

  • September 13, 2013
  • Like
  • 0

Hi,

 

I need to send an attachment  via email through apex.

 

What I do in my code is create a case, then request for the attachment and once the attachment is introduces I send the email. This attachment can be in multiple formats (xls, txt,...).

 

I am able to send the attachment, but not in the correct format...Can you tell me please what I am doing wrong?

 

public PageReference uploadAndSendEmail() {
     
    //Upload the file
    attachment.OwnerId = UserInfo.getUserId();
    attachment.ParentId = case1.Id; // the record the file is attached to
    attachment.IsPrivate = false;
   
   //I get the intranet Id of the user
    User u=[SELECT Id,Intranet_ID__c FROM User WHERE Id=:case2.OwnerId];
    string interfaceId=u.Intranet_ID__c;
    if (attachment.Body!=NULL){
    	try {
      		//Introduce the attachment
      		insert attachment;
      		//and create and send email
        	Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        	String[] toAddresses = new String[] {'a.***@****.com'};
        	mail.setToAddresses(toAddresses);
        	
        	Messaging.EmailFileAttachment[] fileAttachments = new Messaging.EmailFileAttachment[1];
  	        Messaging.EmailFileAttachment fileAttachment = new Messaging.EmailFileAttachment();
      		fileAttachment.setBody(attachment.body);
      		fileAttachment.setFileName(attachment.name);
      		fileattachment.setContentType(attachment.ContentType);
      		fileAttachments[0] = fileAttachment;
   		mail.setFileAttachments(fileAttachments);
        	mail.setSubject('New Request: ' + Case2.Subject + ' - ' + Case2.Id + ' - PROJ=32 -     ISSUE='+Case2.Footprints_ID__c);// New Request: {!Case.RecordType} - {!Case.Id} - PROJ=32 - ISSUE={!Case.Footprints_ID__c}
        	mail.setPlainTextBody('Sender= '+string.valueOf(u.Intranet_ID__c)+'\n'+
        							'New Category='+Case2.Footprints_Category__c+'\n'+
        							'NewSubcategory='+Case2.Footprints_SubCategory__c+'\n'+
        							'SFID='+Case2.Id+'\n'+
        							'SF=Yes\n'+
        							'Atlas Code: '+ Case2.Atlas_Code__c+'\n'+
        							'Ebilling Email: '+ Case2.E_billing_Email__c+'\n'+
        							'Ebilling Frequency: '+ Case2.E_billing_Frequency__c+'\n'+
        							'Comments: '+ Case2.Comments_for_Admin__c);
        	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
      		
    	} catch (DMLException e) {
      		ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
      		return null;
    	} finally {
      		attachment = new Attachment(); 
    	}
    }else{
//DOESNT MATTER. Sends a different email
      }
    	
  }
    //Fin attachments

 

Any help is appreciated.

 

Thanks!

 

Antonio

Hi,

I created some distrubution lists using custom settings, in each distribution list i have email field,created 10 records for each distribution list,.

 

I need to send automatic emails based on email templates on scheduled base.

 

 

please help how to write code for this

 

Hi,

 

 I have 3 fields

1)Lab_Process_Time_Days_HH_MM__c -> Text Data type

2)eDNA_Created_On__c -> Date/Time

3)Sample_Received_On__c ->Date/Time

 

I want the first field "Lab_Process_Time_Days_HH_MM__c" to be calculated automatically in this way

 

Lab_Process_Time_Days_HH_MM__c =eDNA_Created_On__c -Sample_Received_On__c

 

Please help me hw to do it.

 

Thanks in Advance

I have this trigger in sandbox and in production:

 

Trigger CriarTarefaCase_Solicitacao_Pagamento on Case (after insert, after update) {
    
    Set<String> setsubject=new Set<String>();
    List<Task> lstNewTask=new List<Task>();
    

    for(Task tsk:[SELECT Id, whatid, subject, status FROM Task WHERE (subject = 'Solicitação de Pagamento - Lançar PP' OR subject = 'Solicitação de Pagamento - Malote' OR (subject = 'Solicitação de Pagamento - Aprovar solicitação' AND status <> 'Concluído') OR subject = 'Solicitação de Pagamento - Não aprovada' OR subject = 'Solicitação de Pagamento - Solicitar Nota Fiscal') AND whatid IN :Trigger.new]){

        setsubject.add(tsk.subject);

    }
    for (Case c: trigger.new){
        if (c.status <> 'Fechado' && c.outro_motivo__c == 'SIM'){

         if ((c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0)
             && c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados'){

            if(!setsubject.contains('Solicitação de Pagamento - Lançar PP')){
               
               Task t=new Task();                           
               t.whatID = c.ID;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Lançar PP';
               t.ActivityDate = Date.today();
               lstNewTask.add(t);
            }
            }
        }
        if (c.status <> 'Fechado'){

         if ((c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0)
             && c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados'){

            if(!setsubject.contains('Solicitação de Pagamento - Lançar PP')){
               
               Task t=new Task();                           
               t.whatID = c.ID;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Lançar PP';
               t.ActivityDate = Date.today();
               lstNewTask.add(t);
            }
            }
        }
        if (c.status <> 'Fechado'){

         if ((c.forma_de_pagamento__c == 'MALOTE' || c.forma_de_pagamento__c == 'DEPÓSITO + MALOTE')
             && c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados'){

            if(!setsubject.contains('Solicitação de Pagamento - Malote')){
               
               Task t=new Task();                           
               t.whatID = c.ID;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Malote';
               t.ActivityDate = Date.today();
               t.Tarefa_de_fechamento__c = 'SIM';
               t.Ownerid = '005U0000002KGXU';
               lstNewTask.add(t);
            }
           }
    }
        if (c.status <> 'Fechado' && c.outro_motivo__c == 'SIM'){

         if ((c.forma_de_pagamento__c == 'MALOTE' || c.forma_de_pagamento__c == 'DEPÓSITO + MALOTE')
             && c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados'){

            if(!setsubject.contains('Solicitação de Pagamento - Malote')){
               
               Task t=new Task();                           
               t.whatID = c.ID;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Malote';
               t.ActivityDate = Date.today();
               t.Tarefa_de_fechamento__c = 'SIM';
               t.Ownerid = '005U0000002KGXU';
               lstNewTask.add(t);
            }
           }
    }
        if (c.status <> 'Fechado' && c.outro_motivo__c == null){
        
         if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' && c.motivo_a__c == 'Divisão de resultados') 
             && c.Forma_de_pagamento__c == 'MALOTE' && (c.Quantas_PP_s_pagamento__c < 1 || c.Quantidade_de_PP_s_Estojo__c < 1)){

        if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){
               
               Task t=new Task();                           
               t.whatID = c.ID;
               t.Solicitar_Malote__c = true;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Aprovar solicitação';
               t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA';
               t.ActivityDate = Date.today();
               t.Ownerid = '005U0000000FDE9';
               lstNewTask.add(t);
        }
           }
        }
                      if (c.status <> 'Fechado' && c.outro_motivo__c == null){

         if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' || c.motivo_a__c == 'Divisão de resultados') 
             && c.Forma_de_pagamento__c == 'DEPÓSITO + MALOTE' && (c.Quantas_PP_s_pagamento__c < 1 || c.Quantidade_de_PP_s_Estojo__c < 1)){

                          if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){
               
               Task t=new Task();                           
               t.whatID = c.ID;
               t.Solicitar_Malote__c = true;
               t.Solicitar_Dep_sito__c = true;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Aprovar solicitação';
               t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA';
               t.ActivityDate = Date.today();
               t.Ownerid = '005U0000000FDE9';
               lstNewTask.add(t);
                          }
             }
                      }
                      if (c.status <> 'Fechado' && c.outro_motivo__c == null){
    
    if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' || c.motivo_a__c == 'Divisão de resultados') && c.Forma_de_pagamento__c != 'MALOTE' && 
        (c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0)){
        
                          if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){
            
          Task t=new Task();
               t.whatID = c.ID;
               t.Solicitar_PP__c = true;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Aprovar solicitação';
               t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA';
               t.ActivityDate = Date.today();
               t.Ownerid = '005U0000000FDE9';
               lstNewTask.add(t);
                }
                  }
                      }
                      if (c.status <> 'Fechado' && c.outro_motivo__c == null){
    
                          if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' || c.motivo_a__c == 'Divisão de resultados') && c.Forma_de_pagamento__c == 'MALOTE' && c.outro_motivo__c != 'NÃO' && (c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0)){
        
                          if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){
            
          Task t=new Task();
               t.whatID = c.ID;
               t.Solicitar_PP__c = true;
               t.Solicitar_Malote__c = true;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Aprovar solicitação';
               t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA';
               t.ActivityDate = Date.today();
               t.Ownerid = '005U0000000FDE9';
               lstNewTask.add(t);
                          }
                }
                  }
                      if (c.status <> 'Fechado' && c.outro_motivo__c == null){
    
                          if ((c.motivo_a__c == 'Cache' || c.motivo_a__c == 'Mostruarios' || c.motivo_a__c == 'Laboratórios por fora do sistema' || c.motivo_a__c == 'Devolução de venda' || c.motivo_a__c == 'Divisão de resultados') && c.Forma_de_pagamento__c == 'DEPÓSITO + MALOTE' && (c.Quantas_PP_s_pagamento__c > 0 || c.Quantidade_de_PP_s_Estojo__c > 0)){
        
                          if(!setsubject.contains('Solicitação de Pagamento - Aprovar solicitação')){
            
          Task t=new Task();
               t.whatID = c.ID;
               t.Solicitar_PP__c = true;
               t.Solicitar_Malote__c = true;
               t.Solicitar_Dep_sito__c = true;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Aprovar solicitação';
               t.Respons_vel_por_resolver_a_tarefa__c = 'CARLOS BALMA';
               t.ActivityDate = Date.today();
               t.Ownerid = '005U0000000FDE9';
               lstNewTask.add(t);
                          }
                }
                      }
        if (c.status <> 'Fechado' && c.outro_motivo__c == 'NÃO'){
               
            if(!setsubject.contains('Solicitação de Pagamento - Não aprovada')){
            
               Task t=new Task();                           
               t.whatID = c.ID;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Não aprovada';
               t.ActivityDate = Date.today();
               lstNewTask.add(t);
            }
            }
                      if (c.status <> 'Fechado' && c.outro_motivo__c == 'SIM'){
    
                          if ((c.Forma_de_pagamento__c == 'DEPÓSITO + MALOTE' || c.Nota_fiscal__c == 'SIM') && (c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados')){
                
        if(!setsubject.contains('Solicitação de Pagamento - Solicitar Nota Fiscal')){
            
          Task t=new Task();
               t.whatID = c.ID;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Solicitar Nota Fiscal';
               t.ActivityDate = Date.today();
               lstNewTask.add(t);
                }
    }
                  }
                      if (c.status <> 'Fechado'){
    
                          if ((c.Forma_de_pagamento__c == 'DEPÓSITO + MALOTE' || c.Nota_fiscal__c == 'SIM') && (c.motivo_a__c != 'Cache' && c.motivo_a__c != 'Mostruarios' && c.motivo_a__c != 'Laboratórios por fora do sistema' && c.motivo_a__c != 'Devolução de venda' && c.motivo_a__c != 'Divisão de resultados')){
                
        if(!setsubject.contains('Solicitação de Pagamento - Solicitar Nota Fiscal')){
            
          Task t=new Task();
               t.whatID = c.ID;
               t.Solicita_o_de_Pagamento__c = c.motivo_a__c;
               t.Subject = 'Solicitação de Pagamento - Solicitar Nota Fiscal';
               t.ActivityDate = Date.today();
               lstNewTask.add(t);
                }
    }
                  }
    }
    insert lstNewTask;
}

 

 

The first task works in production and in sandbox.

"Solicitação de Pagamento - Lançar PP"

 

But the second, doesn't work only in production.

"Solicitação de Pagamento - Malote"

 

Thanks!

Hi,

 

I am facing an issue like "too many sqol queries : 101" when i run a test class.

 

I will post my code here:

 

 

trigger updateassreqwon on Requirement__c (after update) 


if(Trigger.isUpdate) 

string reqId = Trigger.old[0].Id;

Requirement__c listR = [Select Id, Name, job_title__c, won__c from Requirement__c where Id =:reqId limit 1]; 

// List<RequirementAssignment__c> listreq = [Select Id, Name, won__c, Lead_Recruiter__c, Recruiter__c,Requirement__c from RequirementAssignment__c where requirement__c=:reqId limit 1];

// System.Debug('listreq :' +listreq); 

for(Requirement__c req:Trigger.old) 


Requirement__c R = new Requirement__c(won__c = listR.won__c);

List<RequirementAssignment__c> RAA = new List<RequirementAssignment__c>(); 

{
for(RequirementAssignment__c pc: [Select Id, Name, won__c, Lead_Recruiter__c, Recruiter__c,Requirement__c from RequirementAssignment__c where requirement__c=:reqId limit 1])

System.Debug('pc.Lead_Recruiter__c :' + pc.Lead_Recruiter__c); 
if(pc.Lead_Recruiter__c == null) 
{

System.Debug('pc.Lead_Recruiter__c :' + pc.Lead_Recruiter__c); 

user up = [Select u.Id from User u where (u.Profile.Name ='Lead Recruiter' or u.Profile.Name ='LR Chatter Only User') and Isactive = true limit 1]; 
pc.Lead_Recruiter__c = up.id; 

if(R.won__c == true) 
pc.won__c = 'Yes'; 
else 
pc.won__c = 'No'; 
System.Debug('pc.won__c :' + pc.won__c); 
RAA.add(pc); 



if(RAA.size() >0 )

Database.DMLOptions dml = new Database.DMLOptions(); 
// dml.optAllOrNone = false;
database.update(RAA,dml); 


} // if listreq.size Ends 
}

}
}

 

 

In this trigger, i am facing soql limit error in for(RequirementAssignment__c pc: [Select Id, Name, won__c, Lead_Recruiter__c, Recruiter__c,Requirement__c from RequirementAssignment__c where requirement__c=:reqId limit 1]) line.

 

trigger updateresumessubmitted on Candidate_Mapping__c (after insert, after update)
{

integer ressubmitted;
integer ressubmitted1;
string UserId = UserInfo.getUserId();
System.Debug('UserId =' + UserId);

if(Trigger.isUpdate || Trigger.isInsert)
{

for(Candidate_Mapping__c cm : Trigger.new)
{
system.debug('cm:' + cm);

List<Requirement__c> reqlist = [Select Id, Submitted_Resumes__c, status__c,cumulative_resumes_submitted__c from requirement__c where id =:cm.requirement__c limit 1];

system.debug('reqlist :' +reqlist);

//List <AggregateResult> ar = [SELECT count(Id) cnt FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c =:cm.requirement__c];

//List <Candidate_Mapping__c> ar = [SELECT Id FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c =:cm.requirement__c limit 1];
// system.debug('ar:' +ar);

for(AggregateResult ar1 : [SELECT count(Id) cnt FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c =:cm.requirement__c])
{
ressubmitted = Integer.valueOf(ar1.get('cnt'));
system.debug('ressubmitted :' +ressubmitted);

for(requirement__c req : reqlist)
{
req.cumulative_resumes_submitted__c = ressubmitted;
system.debug('cumulative_resumes_submitted__c :' + req.cumulative_resumes_submitted__c);
system.debug('status__c12 :'+ req.status__c);
if(req.status__c == 'Open')
{
system.debug('status__c123 :'+ req.status__c);
for(integer i = 0 ; i< reqlist.size(); i++)
{
reqlist[i].Submitted_Resumes__c = ressubmitted;
}
}

if(req.status__c == 'Re-open' )
{
system.debug('status__c1 :'+ req.status__c);
system.debug('cm.Status1__c11 :'+ cm.Status1__c);
system.debug('submitted_resumes :' + req.Submitted_Resumes__c);
system.debug('cm.LRdate__c :' + cm.LRdate__c);
if(cm.status1__c == 'applied' && cm.createdbyid == UserId || cm.status1__c == 'LR Approved' && cm.createdbyid == UserId || cm.status1__c == 'Approved' && cm.createdbyid == UserId )
{
system.debug('status__c00:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c + 1;
system.debug('submitted_resumes0 :' + req.Submitted_Resumes__c);
}
else if (cm.status1__c == 'LR Rejected' && cm.createdbyid == UserId && req.Submitted_Resumes__c == 0 || cm.status1__c == 'Rejected' && cm.createdbyid == UserId && req.Submitted_Resumes__c == 0)
{
system.debug('status__c 1123:'+ req.status__c);
req.Submitted_Resumes__c = 0;
system.debug('submitted_resumes3 :' + req.Submitted_Resumes__c);
}

else if (cm.status1__c == 'rejected' || cm.status1__c == 'LR Rejected')
{
// system.debug('cm.LRdate__c :' + cm.LRdate__c);
system.debug('status__c 1122:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c - 1;
system.debug('submitted_resumes2 :' + req.Submitted_Resumes__c);
}
else
{
system.debug('status__c 1121:'+ req.status__c);
req.Submitted_Resumes__c = req.Submitted_Resumes__c;
system.debug('submitted_resumes1 :' + req.Submitted_Resumes__c);
}
}

system.debug('cm.Status1__c :'+ cm.Status1__c);
system.debug('status__c :'+ req.status__c);
system.debug('submitted_resumes3 :' + req.Submitted_Resumes__c);

upsert reqlist;
system.debug('reqlist1:' +reqlist);

}

}
}
}

}

 

In this trigger, i am facing soql limit error in for(AggregateResult ar1 : [SELECT count(Id) cnt FROM Candidate_Mapping__c where (Status1__c != 'rejected' and Status1__c != 'LR Rejected' ) and requirement__c =:cm.requirement__c].

 

 

When i run the below test class i am facing error in any one of the above 2 stmts. 

 

 

@isTest
private class testclassCandidateMapfromCandidatesEdit
{
static testMethod void myUnitTest()
{

String oppid;
String cid;
String Userid;
Integer i,j,k;

Id id1 = UserInfo.getUserRoleId();
UserRole test1 = [Select Name from UserRole where id = :id1 limit 1];
system.test.starttest();

Profile p = [SELECT Id FROM Profile where Name = 'R Chatter Only User' ];
userRole r=[select id from userrole where Name = 'Recruiter' ];
User u = new User(Alias = 'testa', Email='standarduser1@testorg.com',
EmailEncodingKey='UTF-8', LastName='Testaa', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='standarduser1@testorg.com.ezredev',userRoleid=r.id);

System.runAs(u)
{
Candidate_Mapping__c coa =new Candidate_Mapping__c();

coa.status1__c = 'Applied';
coa.Employer_s_Authorization__c = 'test';
coa.LR_Comments__c = 'test by lr';
coa.MR_Comments__c = 'test by MR';
coa.Requirement_Owner_Email__c = 'testOwner@preludesys.com';
coa.Manager_Email_ID__c = 'testOwner1@preludesys.com';
coa.R_Comments__c = '';
coa.LR_Status__c = 'Rejected';
coa.MR_Status__c = 'Applied';
coa.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa.Submitted_to_Client__c = 'Yes';
coa.Interview_Scheduled__c = 'Yes';
coa.Interview_Accepted__c = 'Yes';
coa.Client_Interviewed__c = 'Yes';
coa.Client_Offered__c = 'Yes';
coa.Candidate_started__c = 'Yes';
coa.Comments__c = '';

candidate__c cc1=new candidate__c();

cc1.Name='test';
cc1.Last_name__c='testoneo';
cc1.Current_city__c='chennai';
cc1.Current_state__c='Maine';
cc1.Gender__c='Male';
cc1.Employer_Name__c='ttt';
cc1.Email__c='test@gmail.com';
cc1.interview_contact_phone__c='Mobile Phone';
cc1.Contract_type__c='Corp to Corp';
cc1.visa_type__c='H1 B';
cc1.cost__c =100;
cc1.mobile_phone_no__c='9890043500';
cc1.employer_contact_email__c='test@gmail.com';
cc1.Employer_Contact_Name_Name__c='tt';
cc1.Employer_Mobile_No__c='9988009876';
cc1.Employer_Name__c = 'jos';
cc1.Employer_Work_Phone_No__c = '(425) 264-6771';

cc1.Followup_Date__c =date.today();
insert cc1;
coa.Candidate__c=cc1.id;
system.debug('candid:'+cc1.id);

requirement__c rc1=new requirement__c();

rc1.Name='SampathReq';
rc1.Job_Title__c='.net';
rc1.Duration__c='6';
rc1.No_Of_Resumes__c=2;
rc1.Min_Cost__c=100;
rc1.Max_Cost__c=200;
rc1.Rate__c=200;
rc1.Rate_Basis__c='Hourly';
rc1.Status__c='open';
rc1.Position_Type__c='Contract';
rc1.State__c='CA';
rc1.City__c='CA';
rc1.Est_Start_Date__c=date.today();
rc1.won__c = true;
insert rc1;
coa.Requirement__c=rc1.id;

RequirementAssignment__c oppa=new RequirementAssignment__c();
oppa=new RequirementAssignment__c();
oppa.Requirement__c=rc1.Id;
oppa.Recruiter__c =u.Id;
oppa.won__c = 'yes';
System.Debug('U:'+ oppa.Recruiter__c);
insert oppa;

insert coa;

List<ContentVersion> cv = new List<ContentVersion>();
cv = [Select Id, Candidate_ID__c From ContentVersion where Candidate_ID__c =:coa.Candidate__c limit 1] ;
System.Debug('CV : '+ cv);
if(cv.Size()>0)
{
for(ContentVersion cv1 : cv)
{
Candidate__c can = new Candidate__c(Id = cc1.Id);
can.Resume_Attach__c = '0584000000003RrAAI';
update can;
}
}

CandidateMapfromCandidatesEdit cc = new CandidateMapfromCandidatesEdit();

cc.save();
apexpages.currentpage().getparameters().put('cid' , coa.id);
cc.save();
system.assert(coa!= null);
cc.cancel();
cc.save();
}

Profile p1 =[SELECT Id From Profile where Name= 'LR Chatter Only User'];
userRole r1 =[SELECT Id FROM UserRole where Name = 'Lead Recruiter'];
User u1 = new User(Alias = 'testuser', Email='testUser@testorg.com',
EmailEncodingKey='UTF-8', LastName='TestUseraa', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p1.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='testUser@testorg.com.ezredev',userRoleid=r1.id);
System.runAs(u1){
Candidate_Mapping__c coa1 =new Candidate_Mapping__c();

coa1.status1__c = 'Applied';
coa1.Employer_s_Authorization__c = 'test';
coa1.LR_Comments__c = 'test by lr';
coa1.MR_Comments__c = 'test by MR';
coa1.Requirement_Owner_Email__c = 'testOwn1@preludesys.com';
coa1.Manager_Email_ID__c = 'testOwn1@preludesys.com';

coa1.R_Comments__c = '';
coa1.LR_Status__c = 'Rejected';
coa1.MR_Status__c = 'Applied';
coa1.LR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa1.MR_Status_Date__c = DateTime.now().format('MM-dd-yyyy hh:mm a z', 'America/Los_Angeles');
coa1.Submitted_to_Client__c = 'Yes';
coa1.Interview_Scheduled__c = 'Yes';
coa1.Interview_Accepted__c = 'Yes';
coa1.Client_Interviewed__c = 'Yes';
coa1.Client_Offered__c = 'Yes';
coa1.Candidate_started__c = 'Yes';
coa1.Comments__c = '';

candidate__c cc1=new candidate__c();
cc1.Name='testtwo';
cc1.last_name__c='testtwo';
cc1.current_city__c='chennai';
cc1.current_state__c='Maine';
cc1.gender__c='Male';
cc1.Employer_Name__c='ttt';
cc1.email__c='test@gmail.com';
cc1.interview_contact_phone__c='Mobile Phone';
cc1.contract_type__c='w2';
cc1.visa_type__c='H1 B';
cc1.cost__c =100;
cc1.mobile_phone_no__c='9890043500';
cc1.employer_contact_email__c='test@gmail.com';
cc1.Employer_Contact_Name_Name__c='tyt';
cc1.Employer_Mobile_No__c='9988009876';

insert cc1;
coa1.Candidate__c=cc1.id;
system.debug('candid:'+cc1.id);

requirement__c rc1=new requirement__c();
rc1.Name='SampathReq0';
rc1.Job_Title__c='.net0';
rc1.Duration__c='6';
rc1.No_Of_Resumes__c=2;
rc1.Min_Cost__c=100;
rc1.Max_Cost__c=200;
rc1.Rate__c=200;
rc1.Rate_Basis__c='Hourly';
rc1.Status__c='open';
rc1.Position_Type__c='Contract';
rc1.State__c='CA';
rc1.City__c='CA';
rc1.Est_Start_Date__c=date.today();
rc1.won__c = true;
insert rc1;
coa1.Requirement__c=rc1.id;

RequirementAssignment__c oppa=new RequirementAssignment__c();
oppa=new RequirementAssignment__c();
oppa.Requirement__c=rc1.Id;
oppa.lead_recruiter__c =u1.Id;
oppa.won__c = 'yes';
System.Debug('U:'+ oppa.lead_recruiter__c);
insert oppa;
insert coa1;

List<ContentVersion> cv = new List<ContentVersion>();
cv = [Select Id, Candidate_ID__c From ContentVersion limit 1] ;
if(cv.Size()>0)
{
for(ContentVersion cv1 : cv)
{
Candidate__c can = new Candidate__c(Id = cv1.Id);

//can.Cost__c = 0;
can.Resume_Attach__c = cv1.Id;
update can;
}
}

CandidateMapfromCandidatesEdit cc = new CandidateMapfromCandidatesEdit();
cc.save();
apexpages.currentpage().getparameters().put('cid' , coa1.id);

cc.save();

system.assert(coa1!= null);

cc.cancel();

cc.save();
}
system.test.stoptest();
}
}

 

Some times i am facing issue in the first trigger and some times i am facing this issue in 2nd trigger.

 

Kindly advice.

 

 

 

 

 

  • September 11, 2013
  • Like
  • 0

Hi there,

 

what can be changed in this to avoid 'Too many SOQL queries: 101' issue?

 

thanks

Manohar

 

 

trigger UpdateApprovalPercentForRest on Opportunity (after delete, after undelete, after update) {

    List<Opportunity> buildsToUpdate = new List<Opportunity>{};

    for( Opportunity parent: Trigger.new)
    {                                                    
        List<Opportunity> restBuildswiththePartner =[SELECT Partner_Cap_Reached__c , Build_Partner__c,Construction_Approval_Payment__c,
                                                                StageName,Substantial_Completion_Payment__c 
                                                                FROM Opportunity WHERE Build_Partner_ID__c = :parent.Build_Partner_ID__c AND 
                                                                StageName NOT IN ('Construction Approved', 'Substantial Completion Pending Approval',
                                                                    'Substantial Completion', 'Final Completion Pending Approval', 
                                                                    'Final Completion', 'Cancelled - Customer', 'Cancelled - SCF') ];
 
        for(Opportunity o : restBuildswiththePartner){
            if (o.Partner_Cap_Reached__c == true && (o.Construction_Approval_Payment__c != 0.00 && o.Substantial_Completion_Payment__c != 0.80 ) && (o.StageName != 'Construction Approved' && o.StageName != 'Substantial Completion Pending Approval' && o.StageName != 'Substantial Completion' && o.StageName != 'Final Completion Pending Approval' && o.StageName != 'Final Completion' && o.StageName != 'Cancelled - Customer' && o.StageName != 'Cancelled - SCF')) {
                  o.Construction_Approval_Payment__c = 0.00;
                  o.Substantial_Completion_Payment__c = 0.80;
                  o.Final_Completion_Payment__c = 0.20;
                  buildsToUpdate.add(o);
            }
        
            if (o.Partner_Cap_Reached__c == false && (o.Construction_Approval_Payment__c != 0.40 && o.Substantial_Completion_Payment__c != 0.40 ) && (o.StageName != 'Construction Approved' && o.StageName != 'Substantial Completion Pending Approval' && o.StageName != 'Substantial Completion' && o.StageName != 'Final Completion Pending Approval' && o.StageName != 'Final Completion' && o.StageName != 'Cancelled - Customer' && o.StageName != 'Cancelled - SCF')) {
                  o.Construction_Approval_Payment__c = 0.40;
                  o.Substantial_Completion_Payment__c = 0.40;
                  o.Final_Completion_Payment__c = 0.20;
                  buildsToUpdate.add(o);
            }
        }
    
        if (!buildsToUpdate.isEmpty()){
            update buildsToUpdate;
        }                                                                                                                    
   }
}

 

 

 

where i get the WareHouse  App and  Recruiting App ? ple send me the link (not pdf ).

 

                                      (i want developed App to do practice )

Hi,

 

Whenever a candidate is approved and not submitted to client by the requirement owner on same date, an e-mail has to be sent to the requirement owner by end of day. I have selected the candidates which are appoved and not submitted to client using SOQL. 

 

My query is "SELECT Candidate__c,Requirement__c, Requirement_Code__c, Requirement_Owner__c,Req_Owner_Email__c,status1__c FROM Candidate_Mapping__c where  Submitted_to_Client__c =''and status1__c = 'Approved' ". 

 

No.of rows retrieved is 55 in my sandbox environment. 

 

I have used text template to send this email to the owners. I am facing a issue like "No of Email Invocation is more than 10" Governor limits.

 

 

Code using text template:

 

public class assigncandidatestatusemailalert
{

public void SendEmail()
{

List<Candidate_Mapping__c> candidatemappinglist = new List<Candidate_Mapping__c>( [SELECT Candidate__c, Id, Req_Owner_Email__c, Requirement__c, Requirement_Owner__c, Requirement_Owner_Email__c, Status1__c,LastModifiedDate FROM Candidate_Mapping__c where Submitted_to_Client__c = '' limit 30]);

system.debug('candidatemappinglist :' + candidatemappinglist );

String CandID, ReqmtID;

if(candidatemappinglist != null)
{
Messaging.SingleEmailMessage mail;

for (Candidate_Mapping__c cm :candidatemappinglist )
{
CandID = cm .Candidate__c;
system.debug('candID:' + CandID);

ReqmtID = cm.Requirement__c;
system.debug('ReqmtID:' + ReqmtID);

Candidate__c Candt = [Select Id, Candidate_Full_Name__c from Candidate__c where Id = :CandID];
Requirement__c Reqmt = [Select Id,Name,Opportunity_Code__c,OwnerId from Requirement__c where id = :ReqmtID];
System.debug('Reqmt:' + Reqmt);
User u = [select Id, Email, Name from User where Id = :Reqmt.OwnerId];
System.debug('user:' + u);

EmailTemplate et = [Select Id, Subject, HtmlValue, Body from EmailTemplate where Name = 'Submitted to Client Alert'];
System.Debug('EmailTemplate Id: ' + et.id);
System.Debug('et : ' + et);
// mail.setSenderDisplayName('Abinaya');

// String htmlBody = et.HtmlValue;
String plainBody = et.Body;


if(u.Name != null)
{
plainBody = plainBody.replace('{!Requirement__c.OwnerFullName}', u.Name);
}

else
{
plainBody = plainBody.replace('{!Requirement__c.OwnerFullName}', ' ');
}

if(Candt.Candidate_Full_Name__c != null)
{
// htmlBody = htmlBody.replace('{!Candidate__c.Candidate_Full_Name__c}', Candt.Candidate_Full_Name__c);
plainBody = plainBody.replace('{!Candidate__c.Candidate_Full_Name__c}', Candt.Candidate_Full_Name__c);
System.Debug('Candt Name:' + Candt.Candidate_Full_Name__c);
}
else
{
//htmlBody = htmlBody.replace('{!Candidate__c.Candidate_Full_Name__c}', ' ');
plainBody = plainBody.replace('{!Candidate__c.Candidate_Full_Name__c}', ' ');
}

if(Candt.Id != null)
{
// htmlBody = htmlBody.replace('{!Candidate__c.Id}', Candt.Id);
plainBody = plainBody.replace('{!Candidate__c.Id}', Candt.Id);
System.Debug('Candt Id:' + Candt.Id);
}
else
{
// htmlBody = htmlBody.replace('{!Candidate__c.Id}', ' ');
plainBody = plainBody.replace('{!Candidate__c.Id}', ' ');
}

if(Reqmt.Name != null )
{
// htmlBody = htmlBody.replace(' {!Requirement__c.Name}', Reqmt.Name);
plainBody = plainBody.replace('{!Requirement__c.Name}', Reqmt.Name);
System.Debug('Reqmt Name:' + Reqmt.Name);
}
else
{
// htmlBody = htmlBody.replace('{!Requirement__c.Name}', ' ');
plainBody = plainBody.replace('{!Requirement__c.Name}', ' ');
}

if(Reqmt.Opportunity_Code__c != null)
{
// htmlBody = htmlBody.replace('{!Requirement__c.Opportunity_Code__c}', Reqmt.Opportunity_Code__c );
plainBody = plainBody.replace('{!Requirement__c.Opportunity_Code__c}', Reqmt.Opportunity_Code__c );
System.Debug('Candt Name:' + Reqmt.Opportunity_Code__c );
}
else
{
// htmlBody = htmlBody.replace('{!Requirement__c.Opportunity_Code__c}', ' ');
plainBody = plainBody.replace('{!Requirement__c.Opportunity_Code__c}', ' ');
}

mail = new Messaging.SingleEmailMessage();

String[] address = new String[]{u.email};
mail.setToAddresses(address);


//System.Debug('HtmlBody:' + htmlBody);

System.Debug('Plain Body:' + plainBody);

// List<User>user = new List<User>([Select Id from User where IsActive = true and ProfileId = '00e40000000wnXc' ]);
// System.Debug('UserID: ' + user.id);

//String subject = et.Subject;
//mail.setTemplateId(et.id);
mail.setPlainTextBody(plainBody);
// mail.setHtmlBody(htmlBody );


String[] bccaddress = new String[]{'abinaya_s@preludesys.com'};

mail.setBccAddresses(bccaddress);

mail.saveAsActivity = false;
// mail.setTargetObjectId(user.Id);


Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}
}

}

}

 

 

So I am trying to send email through visualforce email template. 

 

For this i have created a class, component and visualforce email template.

 

Class:

 

public class SubmittedtoClientalert
{
public final List<Candidate_Mapping__c> candidatemappinglist ;
public final test[ ] candiateassign= new List<test>();
public final List<Candidate_Mapping__c> one = new List<Candidate_Mapping__c>();

public SubmittedtoClientalert()
{
candidatemappinglist = [SELECT Candidate__c,Requirement__c, Requirement_Code__c, Requirement_Owner__c,Req_Owner_Email__c,status1__c FROM Candidate_Mapping__c where Submitted_to_Client__c =''and status1__c = 'Approved' limit 30];

system.debug('candidatemappinglist :' + candidatemappinglist );

String CandID, ReqmtID;

if(candidatemappinglist != null)
{
Messaging.SingleEmailMessage mail;

for (Candidate_Mapping__c cm :candidatemappinglist )
{
test t= new test();
CandID = cm .Candidate__c;
system.debug('candID:' + CandID);
ReqmtID = cm.Requirement__c;
system.debug('ReqmtID:' + ReqmtID);

Candidate__c Candt = [Select Id, Candidate_Full_Name__c from Candidate__c where Id = :CandID];
Requirement__c Reqmt = [Select Id,Name,Opportunity_Code__c,OwnerId from Requirement__c where id = :ReqmtID];
System.debug('Reqmt:' + Reqmt);
User u = [select Id, Email, Name from User where Id = :Reqmt.OwnerId];
System.debug('user:' + u);
one.add(new Candidate_Mapping__c( LR_Comments__c= Candt.Candidate_Full_Name__c ,R_Comments__c= Reqmt.Name,MR_Comments__c= Reqmt.Opportunity_Code__c,status1__c= cm.status1__c));

}
}

}

public List<Candidate_Mapping__c> getcandidatemappinglist()
{
return candidatemappinglist ;
}

public List<Candidate_Mapping__c> getone()
{
return one;
}

public class test
{
public String candidatename { get; set; }
public String requirementname{ get; set; }
public String reqcode { get; set; }
public String status { get; set; }
}
}

 

Component:

 

<apex:component controller="SubmittedtoClientalert" access="global">
<apex:dataTable value="{!one}" var="proj" border="2">
<apex:column width="30%" style="align:left">
<apex:facet name="header">Candidate Name</apex:facet>
{!proj.LR_Comments__c}
</apex:column>
<apex:column width="30%" style="align:left">
<apex:facet name="header">Requirement Name</apex:facet>
{!proj.R_Comments__c}
</apex:column>
<apex:column width="40%" style="halign:left">
<apex:facet name="header">Requirement Code</apex:facet>
{!proj.MR_Comments__c}
</apex:column>
</apex:dataTable>
</apex:component>

 

 

I am retrieving the output in visualforce template if the query limit is 30. Otherwise too many queries 101 error is throwing.

 

How to resolve this error?. And also i need to seperate the candidate list based on the requirement owner and send email to the requirement owner with their candidate list.

 

Kindly advice.

In my custom object i have 7 status fields. All these are pick-list fields.
 
If the user update first status field, status message will be updated in the x field. I am doing this using trigger before insert and before update.
 
If the status message is approved and business day is 5(Last Modified date +7), I have to update the next pick-list field to "No" and update the date. I am able to achieve this using workflow field update.
 
Now based on the field update, i have to update the status message field(x) using trigger.
 
This is working fine for first record of the object. For the upcoming records the field (status message) is not updated using trigger where as the field update is happening correctly.
 
Kindly advice.