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

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 8
    Replies
I want to write one trigger on task 
whenever we create any account name as priya then that user cannot create any task.

Please provide me some suggestion.

Thanks,
Priya Aakanksha
I want to create Pop up message when the record type is changing from pre-sales person to salesperson.
The pre-sales person will lose the record after changing the record type at that moment I want to pop up(Toast) message as "successfully record gone to sales" for the Pre-sales person.

Please suggest to me some idea From LWC or any other way
I created one batch class that is throwing error : (First error: Update failed. First exception on row 0 with id 00Q0w000002hR7ZEAU; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, LeadTrigger: execution of AfterUpdate

caused by: System.AsyncException: Future method cannot be called from a future or...)
-----------------------------------------------------------------------
I need to run one batch class that will update one checkbox with below conditions :
If true, update Delay in response field = TRUE.
The batch class should only address leads where the ‘Lead Response time by SM’ is in the last 24 hours.
----------Code----
global class LeadActivityBatchClass implements database.Batchable<sobject>,schedulable{
  
    global Database.queryLocator start(Database.BatchableContext bc){
        String RecordUrl = '';
        Datetime Response = System.now().addhours(-24);
        String query ='SELECT Id,Delay_in_response__c,Status,DC_Lead_Status__c,Lead_Response_time_by_SM__c,(select id,recording_url__c from Tasks) FROM Lead where Lead_Response_time_by_SM__c >:Response';
        
            return Database.getQueryLocator(query); // you can modify the query as per your requirement.
    }
    
    
    global void execute (Database.BatchableContext BC, List<Lead> LdList){
    List<Lead> leadlist = new list<lead>();
        For(lead ld:ldlist){
       if(!System.isFuture()){
      If(ld.Status == 'Meeting Scheduled' && ld.DC_Lead_Status__c == 'Meeting Scheduled'){
                ld.Delay_in_response__c=true;
                leadlist.add(ld);
      }
        }
        }
        update leadlist;
       }            
     
     global void finish(Database.BatchableContext BC){      
        
    }
 global void execute(SchedulableContext sc) {
        LeadActivityBatchClass b1 = new LeadActivityBatchClass();
        ID batchprocessid = Database.executeBatch(b1,200);   
        
    }  
}
-------------
Please provide some solution.
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