• Priya Aakanksha
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 8
    Replies
How to write validation for when lead status is working then mobile or email is mandatory?

I wrote this validation like this:
--------------------
AND((ISPICKVAL(Status ,"Working"))
OR(
ISBLANK(Email),ISBLANK( MobilePhone )
)
)
---------
But nor working , it is asking for both
 
If now time - lead created time is greater than 2 hours, AND Last Activity date is NULL, then trigger the Alert Email.

I wrote batch class its showing complete but not getting any mails
here is my code -----
=============================
global class Lead_Escalation implements database.Batchable<sobject>,schedulable{
    
    global Id userId;
    global database.QueryLocator start(database.BatchableContext bc){
      string  query;
         string a ='Website' ;
         string b ='Phone' ;
        Datetime d2= system.now().addhours(32);
    
       if(!test.isRunningTest()){
       query='select id,Name,Owner.ID,LastModifiedDate,owner.firstname,CREATEDDATE,owner.name,owner.lastname,Owner.Email,LeadSource,LASTACTIVITYDATE FROM lead where (CREATEDDATE=:d2 AND LASTACTIVITYDATE= Null AND(LeadSource=:a OR LeadSource=:b))';
       }else{
       query='select id,Name,Owner.ID,LastModifiedDate,owner.firstname,CREATEDDATE,owner.name,owner.lastname,Owner.Email,LeadSource,LASTACTIVITYDATE FROM lead limit 1';
            }
            
            return database.getQueryLocator(query);
      }
    
        global void execute(database.BatchableContext bc,list<lead>ldlist){
        emailtemplate LeadEscalationTemplate=[SELECT Id, Subject FROM EmailTemplate WHERE name='LeadEscalationTemplate'];
            
            list<user> userlist=[select id,name,isactive,profileid,profile.name,email,userrole.name from user where userrole.name = 'National Sales Head - Retail' AND isactive=true];
   
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
     
        list<task> tklist=new list<task>();
            
            list<string>toadd=new list<string>();
            for(user us:userlist){
            toadd.add(us.email);
            }
        for(lead l:ldlist){
           
            {
                if(test.isRunningTest()  || l.CREATEDDATE.hour() > 2){
                
                toadd.add(l.owner.email);
                Messaging.SingleEmailMessage message= new Messaging.SingleEmailMessage();
                     
                message.setSubject('Reminder :Enquiry for '+'l.name' + ' to be acted on.');
                    List<String> sendTo = new List<String>();
                    sendTo.add(tklist[0].Owner.Email);
                    
                  message.setToAddresses(sendTo);
                  message.setccaddresses(toadd);
          //      mail.settoaddresses(toadd);
                  message.setTargetObjectId(l.ownerid); 
                  message.setWhatId(l.id);
                  message.setBccAddresses(new string[]{'priyaaakanksha28@gmail.com'});
                  message.setsenderdisplayname('kk');
                  message.setSaveAsActivity(false);
                  message.setTemplateID(LeadEscalationTemplate.id);
        //        message.setHtmlBody(body);
                  mails.add(message);
                
                
               
               task tasks=new task();       
               tasks.WhoId=l.id;
               tasks.OwnerId=l.ownerid;
                
               tasks.Subject='Reminder';
               tasks.Description='It has been two hours since this lead is created and no activity is created. Please contact the customer';
               tasks.Task_Info__c='ALERT';
               tasks.Priority='Medium';
               tasks.Status='Open';
          //     tasks.Assigned To='Owner';
                  tklist.add(tasks);
   
     } 
            }                                                                                      
                                               
        if(!test.isRunningTest()){
            if(mails.size() > 0){
                Messaging.sendEmail(mails); 
            }
            if(tklist.size() > 0){
                insert tklist;
            }
            
        }
        
    }
   }
    global void finish(database.BatchableContext bc){
        
    }
    global void execute(SchedulableContext sc) {
        Lead_Escalation b2 = new Lead_Escalation();
        ID batchprocessid = Database.executeBatch(b2,50);  
    }
    
}
==============================================
Please help me out from this issue that i m not getting any mails
Reminder Email:
Batch class to be written on Lead object that runs every hour.
Criteria:
If the is no activity created for a lead (with Source = Web or Phone) for 2 hours after the lead creation time, a reminder email is to go to the lead owner.
Email Content:
It has been two hours since this lead is created. Please contact the customer.
Detail Link

A task also has to be created.
Subject: Reminder
Comments: It has been two hours since this lead is created and no activity is created. Please contact the customer.
Status : Open
Priority: Medium
Due date : Today
Assigned To: Lead Owner
====================================
i wrote batch class but its showing error 

global class Lead_Escalation implements database.Batchable<sobject>,schedulable{
    global database.QueryLocator start(database.BatchableContext bc){
       
         integer day=system.today().day();
         string  query;
       // string a ='Website' ;
        //string b ='Phone' ;
         if(!test.isRunningTest()){
             query='select id,Name,Owner.ID,Assigned To,activityid,owner.firstname,owner.lastname,Owner.Email,LeadSource from lead where activityid=null AND (LeadSource=:Website OR LeadSource=:Phone) order by id';
            }else{
                query='select id,Name,Owner.ID,owner.firstname,owner.lastname,Owner.Email,LeadSource from lead limit 1';
            }
            
            return database.getQueryLocator(query);
    }
    
    global void execute(database.BatchableContext bc,list<lead>ldlist){
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
     
        list<task> tklist=new list<task>();
        for(lead l:ldlist){
        
                string body= 'Dear '+' '+'l.owner.name'+'l.name'+'\n'+
                    'It has been two hours since this lead is created. Please contact the customer';
            {  
                   Messaging.SingleEmailMessage message= new Messaging.SingleEmailMessage();
                message.setSubject('Reminder :Enquiry for '+'l.name' + ' to be acted on.');
          //      mail.settoaddresses(toadd);
                message.setBccAddresses(new string[]{'priyaaakanksha28@gmail.com'});
                message.setsenderdisplayname('NN');
                message.setSaveAsActivity(false);
                message.setHtmlBody(body);
                mails.add(message);
                
             /*   
               task tasks=new task();       
                tasks.WhoId=l.id;
                tasks.OwnerId=l.ownerid;
                
               tasks.Subject='Reminder';
               tasks.Description='Dear '+' '+'l.owner.name'+'l.name'+'\n'+
                    'It has been two hours since this lead is created. Please contact the customer'.
               tasks.TaskInfo__c='alert';
               tasks.Priority='Medium';
               tasks.Status='Open';
         //      tasks.Assigned To='Owner';
                
                
                tklist.add(tasks);
   */
     }
        if(!test.isRunningTest()){
            if(mails.size() > 0){
                Messaging.sendEmail(mails); 
            }
            if(tklist.size() > 0){
                insert tklist;
            }
            
        }
        
    }
   }
    global void finish(database.BatchableContext bc){
        
    }
    global void execute(SchedulableContext sc) {
        Lead_Escalation b2 = new Lead_Escalation();
        ID batchprocessid = Database.executeBatch(b2,50);  
    }
    
}
 
I wants to send email templates to user using batch apex but while executing email template its going but that value (opportunity name)is not coming in salesforce.
error is showing in batch class
1)Method does not exist or incorrect signature: void day() from the type User
2)Field is not writeable: Opportunity.IsWon 
========================================
if(Opp.LastModifiedBy.day() > system.today()+30){
                opp.LofB__c='Retail';
              opp.ISWON ='false';
i wants to attach pdf as file not as attachments while sending mail it should save in notes and attachments.
@AuraEnabled
    public static void updatePicturePath(String recId){
        //In Lightning Experience, Attachments are stored in ContentDocuments
        ContentDocumentLink docLink = [ SELECT ContentDocumentId
                               FROM ContentDocumentLink
                               WHERE LinkedEntityId = :recId order by Id desc Limit 1];
        //ContentVersion Id uniquely identifies the attachment
        ContentVersion ver = [SELECT Id FROM ContentVersion Where ContentDocumentId = :docLink.ContentDocumentId];
        //Update the Picture_Path field with the url of the image
        Speaker__c speaker = [SELECT Id FROM Speaker__c WHERE Id = :recId];
        speaker.Picture_Path__c = '/sfc/servlet.shepherd/version/download/'+ ver.Id;
        upsert speaker;
    }
====================================
Unexpected token 'void'.
global class SendReminderEmail implements Database.Batchable<sObject> {
    global Database.QueryLocator start(Database.BatchableContext bc) {
    }
    global void execute(Database.BatchableContext bc, List<Speaker__c> scope) {
    }
    global void finish(Database.BatchableContext bc) {
    }
}
========================================
Compile Error: Missing return statement required return type: Database.QueryLocator at line 2 column 34    
how to do two action with one button one should send mail and another get attached in note and attachements
This is my batch class so that i was facing an error regarding the trigger firing like 
Class BirthdayNotificationBatchClass must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)
Class BirthdayNotificationBatchClass must implement the method: void System.Schedulable.execute(System.SchedulableContext)

Please help me out from this 
I wants to send email templates to user using batch apex but while executing email template its going but that value (opportunity name)is not coming in salesforce.
error is showing in batch class
1)Method does not exist or incorrect signature: void day() from the type User
2)Field is not writeable: Opportunity.IsWon 
========================================
if(Opp.LastModifiedBy.day() > system.today()+30){
                opp.LofB__c='Retail';
              opp.ISWON ='false';
i wants to attach pdf as file not as attachments while sending mail it should save in notes and attachments.
@AuraEnabled
    public static void updatePicturePath(String recId){
        //In Lightning Experience, Attachments are stored in ContentDocuments
        ContentDocumentLink docLink = [ SELECT ContentDocumentId
                               FROM ContentDocumentLink
                               WHERE LinkedEntityId = :recId order by Id desc Limit 1];
        //ContentVersion Id uniquely identifies the attachment
        ContentVersion ver = [SELECT Id FROM ContentVersion Where ContentDocumentId = :docLink.ContentDocumentId];
        //Update the Picture_Path field with the url of the image
        Speaker__c speaker = [SELECT Id FROM Speaker__c WHERE Id = :recId];
        speaker.Picture_Path__c = '/sfc/servlet.shepherd/version/download/'+ ver.Id;
        upsert speaker;
    }
====================================
Unexpected token 'void'.
how to do two action with one button one should send mail and another get attached in note and attachements
This is my batch class so that i was facing an error regarding the trigger firing like 
Class BirthdayNotificationBatchClass must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)
Class BirthdayNotificationBatchClass must implement the method: void System.Schedulable.execute(System.SchedulableContext)

Please help me out from this