• prai
  • NEWBIE
  • 10 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 2
    Replies
Hi,
I have schedule my class and i want to send the notification when schedule job failes. Here is the code which i have implemented:

global class CaseAssignmentScheduler00 implements Schedulable  
{
    public static dateTime dt=System.now().addMinutes(5);
    public static String Csec=String.valueof(dt.second());
    public static String Cmin=String.valueof(dt.minute());
    public static String Chr=String.valueof(dt.hour());
    public static String Cday=String.valueof(dt.day());
    public static String Cmonth=String.valueof(dt.month());
    public static String CYear=String.valueof(dt.Year());
    public static String SchTimer= Csec+' '+Cmin+' '+Chr+' '+Cday+' '+Cmonth+' ? '+CYear;
    list<string> emailaddress = new list<string>(); 
    public static integer count=0;
    global void execute(SchedulableContext SC)     
    {
       
        try{
            CaseRoundRobinAssignmentController.CaseAssignmentFromQueue();
            doScheduling();
            
        }
        catch(exception e){
    }
    
    public void doScheduling(){
        system.debug('*************SchTimer:'+SchTimer);
        CaseAssignmentScheduler00 cas = new CaseAssignmentScheduler00();
        system.schedule('CaseAssignmentScheduler00: Assigning Cases from Queue to Active Users at '+System.now().format(), SchTimer, cas);
        //checkJobStatus();     
            
            for( CronTrigger c:[Select c.TimesTriggered, c.TimeZoneSidKey, c.State, c.StartTime, c.PreviousFireTime, c.OwnerId, c.NextFireTime, c.LastModifiedById, c.Id, c.EndTime, c.CronExpression, c.CreatedDate, c.CreatedById From CronTrigger c where c.NextFireTime=null  AND c.State='DELETED' Limit 100]){
                System.abortJob(c.id);
            }
    }
    
    /****** Send email notification to Admin if Job fails*****/
    public void checkJobStatus(){
        // Featch the Email ID from custom setting
        for(Case_Scheduler_Email__c Em : Case_Scheduler_Email__c.getAll().values()){
                             emailaddress.add(Em.Email__c);      
        }
        
        for(AsyncApexJob aj: [Select Id, Status, NumberOfErrors, JobItemsProcessed,TotalJobItems, ExtendedStatus, createdDate ,ApexClassID, MethodName
                from AsyncApexJob where Status = 'Failed' LIMIT 1])
                { 
                   
                    {
                            
                        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                        mail.setToAddresses(emailaddress);
                        mail.setSenderDisplayName('Case Scheduler Job');
                        mail.setSubject('Case Scheduler Job Fails');
                        mail.setHtmlBody('The Scheduled batch Apex job got failed. Please check the schedule job and take the necessary action. ' +'Here is the Error Message: ' + aj.ExtendedStatus);
    
                        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                   }
               }
        }
}
Seem this code is not working. can any one help me on this ?

 
  • April 05, 2016
  • Like
  • 0
Hi All,
i have wrote the trigger and now i am writting test class for this  but code coverage is going only 67%, Please help me to increase the code coverage:
Here is the trigger:
trigger deleteandedittask on Task (before delete, before update) {
   
  
  string rtypeid = [Select id,Name from RecordType where  sObjectType='Task' and isActive=true and Name = 'FA-CRM System Task'].id;
  set<Id> bypassProfileIdSet = new Set<id>();  
  bypassProfileIdSet.add(RoleProfile__c.getInstance('API Users').ID__c);
  bypassProfileIdSet.add(RoleProfile__c.getInstance('System Administrator').ID__c);
    
   if(trigger.isUpdate)
    {
      if(!bypassProfileIdSet.contains(userinfo.getprofileid()))    
      {  
        for (task t : Trigger.New)  
        {
           
            String strwhatId = ''; String strwhoId = '';
            If(t.whatid != null)strwhatid = String.valueOf(t.Whatid).substring(0 , 3);
            If(t.whoid != null) strwhoid = String.valueOf(t.Whoid).substring(0 , 3);
           if(strwhatid == '001' || strwhoid== '003' && t.whatid==null )
           {
           
            if( Trigger.oldMap.get(t.id).Status =='Completed')  
            {
                
                if(t.RecordTypeId == rtypeid)
                {
               
                    if(Trigger.oldMap.get(t.id).Status != Trigger.newmap.get(t.id).Status)
                    t.Status.addError('Cannot edit or delete Activity History.');
                   
                    if(Trigger.oldMap.get(t.id).priority != Trigger.newmap.get(t.id).priority)
                    t.Priority.addError('Cannot edit or delete Activity History.');
                   
                    if(Trigger.oldMap.get(t.id).Subject != Trigger.newmap.get(t.id).subject)
                    t.Subject.addError('Cannot edit or delete Activity History.');
                   
                    if(Trigger.oldMap.get(t.id).Ownerid != Trigger.newmap.get(t.id).Ownerid)
                    t.Ownerid.addError('Cannot edit or delete Activity History.');
                    else 
                    t.addError('Cannot edit or delete Activity History'); 
                }
                else 
                t.addError('Cannot edit or delete Activity History');   
                
             }
           } 
        }
      }   
    }
    if(Trigger.IsDelete)
    {
      if(!bypassProfileIdSet.contains(userinfo.getprofileid()))    
      {          
         for (task t : Trigger.old) 
        {
           String strwhatId = ''; String strwhoId = '';
           If(t.whatid != null)strwhatid = String.valueOf(t.Whatid).substring(0 , 3);
           If(t.whoid != null) strwhoid = String.valueOf(t.Whoid).substring(0 , 3);
          
          if(strwhatid == '001' || (strwhoid== '003' && t.Whatid==null))
           {
            
            if(( Trigger.oldMap.get(t.id).Status =='Completed')  ) { 
                            t.addError('Cannot edit or delete Activity History.');
             }   
           }
           
        }
      }    
    } 
}

And here is my test class:

private class Testdeleteandedittask {

  static testMethod void myUnitTest() {
        //Init and Creating data
        List<Profile> ProfileList=new List<Profile>();
        String Userrecord='FA-CRM Platform';
        Profile pro = [SELECT Id FROM profile WHERE name =:Userrecord];
        User u1 = new User(alias = 'TaskF', email='newTaskuser@testorg.com', emailencodingkey='UTF-8', lastname='TaskFormat', languagelocalekey='en_US',localesidkey='en_US', profileid = pro.Id,timezonesidkey='America/Los_Angeles', username='newTaskFormat1@testorg.com',LR_Firm_ID__c=2);
        insert u1;
        Test.startTest();
        System.Runas(u1){
        String rectype=[Select id,Name from RecordType where  sObjectType='Task' and isActive=true and Name = 'Advisor Tasks'].id;
        Map<String,RecordType> RecortypeMap=new Map<String,RecordType>(); 
            for(RecordType r:[select id,name from RecordType Where SobjectType = 'Account' and name='Person'])
            {
                RecortypeMap.put(r.name,r);
            }
            
           List<Account> AccountList=new List<Account>();
            Account acc1 = new Account(name='account1',Mailing_Line1__c='Line1',PrimaryPhoneType__c='Business',PrimaryPhone__c='5423534', PrimaryPhoneFormat__c='TEST', SecondaryPhoneFormat__c='TEST');
            AccountList.add(acc1);
            Account acc2 = new Account(name='account2',Mailing_Line1__c='Line2',PrimaryPhoneType__c='Business',PrimaryPhone__c='5423534', PrimaryPhoneFormat__c='TEST', SecondaryPhoneFormat__c='TEST');
            AccountList.add(acc2);
            insert AccountList;
         Profile[] Pr = [Select id from PRofile limit 2];
                            
            RoleProfile__c obj1 = new RoleProfile__c();
            obj1.Name  = 'API Users';
            obj1.ID__c = PR[0].id;
            obj1.Type__c = 'Profile';
            Insert obj1;
            RoleProfile__c obj2 = new RoleProfile__c();
            obj2.Name  = 'System Administrator';
            obj2.ID__c = PR[1].id;
            obj2.Type__c = 'Profile';
            Insert obj2;
                
           
            List<Task> tasklist = new List<Task>();
            for(integer i=0;i<5;i++){
            Task task = new Task();
            task.Status='In Progress';
            task.Priority='Normal';
            task.whatid=AccountList[1].id;
            task.subject='sw test'+i;
            task.Comments__c='Completedd';
            task.Description='compl'; 
            tasklist.add(task);
            }
            Task task1 = new Task();
                task1.Status='In Progress';
                task1.Priority='Normal';
                task1.whatid=AccountList[0].id;
                task1.subject='sw test'+7;
                task1.Comments__c='Completedd';
                task1.Description='compl';
            insert task1; 
               
            Task task2 = new Task();
                task2.Status='In Progress';
                task2.Priority='Normal';
                task2.whatid=AccountList[0].id;
                task2.subject='sw test'+8;
                task2.Comments__c='Completedd';
                task2.Description='compl';
            insert task2;
            task2.Priority='High';
            task2.subject='sw test'+9;
            update task2; 
          //  tasklist.add(task);
            insert tasklist;
             System.assert(tasklist.size()>0);
            
            List<Event> Eventlist = new List<Event>();
            for(integer i=0;i<5;i++){
            Event event = new Event();
            event.EndDateTime = System.Now()+10;
            event.StartDateTime = System.Now()+10;
            event.whatid=AccountList[0].id;
            event.subject='ev test'+i;
            Eventlist.add(event);
            }
            insert eventlist;
            Event event2 = new Event();
            event2.EndDateTime = System.Now()+10;
            event2.StartDateTime = System.Now()+10;
            event2.whatid=AccountList[0].id;
            event2.subject='ev test'+7;
            insert event2;
            System.assert(tasklist.size()>0);
            
            List<Event> NewEventlist = new List<Event>();
            for(Event ev23:eventlist){
                ev23.Event_Status__c='Completed';
                ev23.Comments__c='Closed in Update ';
                NewEventlist.add(ev23);
            }
            update NewEventlist;
            System.assert(NewEventlist.size()>0);
            
            List<Task> TaskListForupdateDelete=new List<Task>(); 
            List<Event> eventListForupdateDelete=new List<Event>();  
            
            for(Task t:[select id,RecordTypeId,Status,Whatid,Subject from Task where id in:taskList ])
            {
                t.RecordTypeId= rectype;
                t.status='Completed' ;
                t.priority='High';
                t.subject='sw Etest';
            TaskListForupdateDelete.add(t);
            }
           // system.assertEquals(TaskListForupdateDelete[0].Whatid,AccountList[0].id );
            
            for(Event e:[select id,Whatid,Subject,StartDateTime,EndDateTime from Event where id in:EventList ])
            {
            eventListForupdateDelete.add(e);
            }
            system.assertEquals(EventListForupdateDelete[0].Whatid,AccountList[0].id );
            update TaskListForupdateDelete; 
         
              delete task1;
              delete event2;
           
            //
            Test.stopTest();
        }
    } 
    
}
  • October 06, 2015
  • Like
  • 0
Hi,
I have one Custom object and with lookup of User object, When we save this custom object first it will check the related user is active or not. if not active then it has to activate the user and save record.
One @Future method is allready written for User object.

Here is the error which i am getting:
first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User, original object: ClientReview__c: []

Here is my method which i wrote in class:
 Public void ToActiveateUser(List<ClientReview__c> clientReviewList)
    {
      List<ClientReview__c> alertReviewList = new List<ClientReview__c>();
        Map<String,RepCode__c> repCodeMap=this.getRepCodeMap(clientReviewList);
        List<Id> AdvisorUsers = new List<Id>();
        for(ClientReview__c review:clientReviewList){
            String repCode=review.ClientRepCode__c;
            if(repCode !='')
            {
                RepCode__c rc=repCodeMap.get(repCode);
                if(rc!=null)
                {
                    String ownerId=rc.Advisor__r.Advisor_User__pc;
                    if(ownerId != '')
                        AdvisorUsers.add(review.OwnerId);
                }   
            }
        }
      if(AdvisorUsers.size()>0)
      {
         List<User> advisorUser = [Select Id,IsActive FROM User WHERE Id IN:AdvisorUsers];
         List<User> updateuser = new List<user>();
         for( User usr: advisorUser)
         {
           if(usr.IsActive == false)
           {
               usr.IsActive = true;
               updateuser.add(usr);
            }   
         }
         if(updateuser.size()>0)
            update updateuser; 
             
      }  
    }

And i am calling this method in Trigger:

Trigger Supervision_Sharing on ClientReview__c (after insert) {
    SupervisionOperations so=new SupervisionOperations();   
    so.ToActiveateUser(Trigger.New);
}
 
  • May 12, 2015
  • Like
  • 0
I have created a Big VF page.
i want to add "Back to Top" link at the bottom of my VF page which, once you clicked  it will take them back to top of page and cursor point to specific field.

I wrote the code:
<div align="right"> <a href="#" ID="#backToTop"> Back To Top</a> </div>
but this is returing back to top of page. but i dont know how to set the cursor position.

Please help me to get this.
Thanks.


  • August 05, 2014
  • Like
  • 0

I am getting error while running the page.

First time when i run the page it is working perfect, but when i am running next time(Record more then 11) getting this error:

Here is code which i wrote:

String accSizeInInteger='select id,name,OwnerId,RepCode__r.Name,Tax_ID_Type__c,Tax_ID__c from Account where RepCode__c= \''+repblast.Current_Rep__c+'\'' ;
      
      if(ClientName!=null)
        {
            accSizeInInteger+=' and name like \'%'+ClientName+'%\'';
        }
        if(Type!=null)
        {
            accSizeInInteger+=' and Tax_ID_Type__c like \'%'+Type+'%\'';
        }
        if(doNotInclude.size()>0)
        {
            accSizeInInteger+=' and id not in '+doNotInclude;
        }
      
        List<Account> accListSize=new List<Account>();
        accListSize=Database.query(accSizeInInteger);

 

Please help any one.

Thanks

  • November 14, 2013
  • Like
  • 0

Hello everyone,

 

i written one trigger which is sending mail, when you edit the record or create the new record based on conditions.

Now ounce’s the Customer received mail, he will reply back with some date field value and text value.

If the customer reply back to mail, SF object will update the value based on email content.

This part is working when you reply from Outlook, Gmail or Yahoo.

 

But Customer is using Lotus note and when they replaying back, data are not updating into SF. Even I not receiving any exception or error message.

 

Any help is highly appreciated.

  • June 14, 2012
  • Like
  • 0
Hi,
Need salesforce project support in california timings. Intrested please respond.

Thanks,
 
I have created a Big VF page.
i want to add "Back to Top" link at the bottom of my VF page which, once you clicked  it will take them back to top of page and cursor point to specific field.

I wrote the code:
<div align="right"> <a href="#" ID="#backToTop"> Back To Top</a> </div>
but this is returing back to top of page. but i dont know how to set the cursor position.

Please help me to get this.
Thanks.


  • August 05, 2014
  • Like
  • 0