• kasa venkat 14
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 10
    Replies
if i create a case no one can modifyed before 48 hours, i want to send an email to the user or a group? how can i do this can any one suggest?
this is the class.


public class SLS_Notification_Engine {


    // Dummy contact for use of template
    Contact cnt;
    
    
    
    /*
     *  @Method Name  :  SLS_Notification_Engine
     *  @Description  :  Constructor    
     */
    public SLS_Notification_Engine() {
       
       cnt = [select id, Email from Contact where lastname != null limit 1];
       Map<String, RecordType> mapCaseRTbyDeveloperName = new Map<String, RecordType>();   
       for(RecordType rt:StaticConstants.getRecordTypeIDsByObject('Case')){
               mapCaseRTbyDeveloperName.put(rt.DeveloperName, rt);
           }  
       
       notifyCreator(mapCaseRTbyDeveloperName);
       notifyRequester(mapCaseRTbyDeveloperName);         
    }
    
   

    public void notifyCreator( Map<String,RecordType> mapRecordTypes) {
        
        list<case> finalLstCases = new list<case>();
        list<messaging.singleEmailMessage> lstMessages = new list<messaging.singleEmailMessage>();
        List<Messaging.SingleEmailMessage> msgListToBeSend = new List<Messaging.SingleEmailMessage>();  
        list<case> lstCases = new List<case>();
        ID orgWideEmailID = [select id,DisplayName from OrgWideEmailAddress where DisplayName=:SLS_StaticConstants.SLS_PSD_ORG_WIDE_ADDR_DNAME].id;
        
        ID reqTemplateID = [select id from EmailTemplate where DeveloperName=:SLS_StaticConstants.SLS_REQ_NOTIFY_Temp_NAME].id;
        lstCases = [select recordTypeId,status,notify_creator__c,caseNumber,notifiedCreator__c,ownerChangeDate__c,ownerId,owner.Name,owner.Email,lastModifiedDate from case 
                    where recordTypeId = :mapRecordTypes.get(SLS_StaticConstants.SLS_Case_RecordType).Id 
                    and status=:'Open' 
                    and notify_creator__c != null 
                    and notify_creator__c!= 'No Notification'
                    and notifiedCreator__c =: false
                    and ownerChangeDate__c != null
                    ];
        
        system.debug('------lstCases in notifyCreator method ***--'+lstCases.size() );
        system.debug('------lstCases in notifyCreator method ***--'+lstCases );
        
        if( lstCases != null && !lstCases.isEmpty() ) {
            
            for(case creatorCAS : lstCases) {
                            
                Date modifedDate = date.newInstance(creatorCAS.lastModifiedDate.year(),creatorCAS.lastModifiedDate.month(),creatorCAS.lastModifiedDate.day());
                
                if(modifedDate == creatorCAS.ownerChangeDate__c && creatorCAS.notify_creator__c!='No Notification' && system.today() > (creatorCAS.ownerChangeDate__c + integer.ValueOf(creatorCAS.notify_creator__c))  )  { //change the criteria to greater than after testing , + integer.ValueOf(creatorCAS.notify_creator__c)
                    creatorCAS.notifiedCreator__c = true;
                    finalLstCases.add(creatorCAS);    
                }                                    
            }
        }
        system.debug('------finalLstCases  in notifyCreator method ***--'+finalLstCases.size() );
       
        if( finalLstCases!= null && !finalLstCases.isEmpty() ) {
  
            lstMessages.clear();
            for(case creatorCase : finalLstCases) {
                    
                Messaging.SingleEmailMessage creatorMail = new Messaging.SingleEmailMessage();
                creatorMail.setTemplateId(reqTemplateID);
                creatorMail.setWhatId(creatorCase.id);
                creatorMail.setTargetObjectId(cnt.id);
                creatorMail.setToAddresses(new string[]{creatorCase.owner.Email});
                lstMessages.add(creatorMail);
                Savepoint sp = Database.setSavepoint();
                Messaging.sendEmail(lstMessages);// Dummy email send
                Database.rollback(sp);// Email will not send as it is rolled Back
                
                // Send actual notification email
                for (Messaging.SingleEmailMessage email : lstMessages) {
                    
                    Messaging.SingleEmailMessage emailToSend = new Messaging.SingleEmailMessage();
                    emailToSend.setOrgWideEmailAddressId(orgWideEmailID);
                    emailToSend.setToAddresses(email.getToAddresses());
                    emailToSend.setPlainTextBody(email.getPlainTextBody());
                    emailToSend.setHTMLBody(email.getHTMLBody());
                    emailToSend.setSubject(email.getSubject());
                    msgListToBeSend.add(emailToSend);
                
                }
            } 
        }
        
        system.debug('------------lstMessages in creator method ---'+lstMessages.size() );
        try{        
            if( msgListToBeSend!=null && !msgListToBeSend.isEmpty() )
            {               
               Messaging.sendEmail(msgListToBeSend);              
            }  
            
            if(finalLstCases!= null && !finalLstCases.isEmpty() ) {
                 StaticFunctions.runOnce();
                StaticFunctions.runOnceAfterTrigger();
                update finalLstCases;                 
            }
        }
        catch(exception e) {
            system.debug('Exception occured while updating notified creator'+e);
        }
    
    }
    
    
   
    
    public void notifyRequester( Map<String,RecordType> mapRecordTypes) {
    
        list<case> finalLstCases = new list<case>();
        list<messaging.singleEmailMessage> lstMessages = new list<messaging.singleEmailMessage>();
        List<Messaging.SingleEmailMessage> msgListToBeSend = new List<Messaging.SingleEmailMessage>();
        ID orgWideEmailID = [select id,DisplayName from OrgWideEmailAddress where DisplayName=:SLS_StaticConstants.SLS_PSD_ORG_WIDE_ADDR_DNAME].id;        
        ID reqTemplateID = [select id from EmailTemplate where DeveloperName=:SLS_StaticConstants.SLS_CRTR_NOTIFY_Temp_NAME].id;
        list<case> lstCases = new list<case>();
        lstCases = [ select recordTypeId,caseNumber,status,Requester_Email__c,notify_requestor__c,notifiedRequester__c,Requester__c,Requester__r.Name,External_Requester__c,ownerChangeDate__c,lastModifiedDate from case where 
                     recordTypeId = :mapRecordTypes.get(SLS_StaticConstants.SLS_Case_RecordType).Id 
                     and  status =:'Open' 
                     and  (Requester_Email__c  != null or Requester_Email__c != '' ) 
                     and  notify_requestor__c != null 
                     and  notify_requestor__c!= 'No Notification'
                     and  notifiedRequester__c =: false
                     and  ownerChangeDate__c != null ]; 
        
        system.debug('------ lstCases size in requester method **----'+lstCases.size() );
        system.debug('------ lstCases size in requester method **----'+lstCases);
        
        if(lstCases!=null && !lstCases.isEmpty() ) {
            for(case requesterCAS : lstCases) {
            
                Date mofiedDate = date.newInstance(requesterCAS.lastModifiedDate.year(),requesterCAS.lastModifiedDate.month(),requesterCAS.lastModifiedDate.day()); 
                    
                    if( requesterCAS.ownerChangeDate__c == mofiedDate && requesterCAS.notify_requestor__c!= 'No Notification' && system.today() > (requesterCAS.ownerChangeDate__c + integer.ValueOf(requesterCAS.notify_requestor__c) ) )  { //change the criteria to greater than after testing,
                        requesterCAS.notifiedRequester__c = true;
                        finalLstCases.add(requesterCAS);    
                    } 
                         
            }
        }
        system.debug('-----finalLstCases in requester**---'+finalLstCases.size() );
        
        
        if(finalLstCases!=null && !finalLstCases.isEmpty() ) {
            
            lstMessages.clear();
            
            for(case requesterCase : finalLstCases) {
            
                if( string.isNotBlank(requestercase.Requester_Email__c) ) {
                    
                    Messaging.SingleEmailMessage requesterMail = new Messaging.SingleEmailMessage();
                    requesterMail.setTemplateId(reqTemplateID);
                    requesterMail.setWhatId(requesterCase.id);
                    requesterMail.setTargetObjectId(cnt.id);
                    requesterMail.setToAddresses(new string[]{requestercase.Requester_Email__c});
                    lstMessages.add(requesterMail);
                    Savepoint sp = Database.setSavepoint();
                    Messaging.sendEmail(lstMessages); // Dummy email send
                    Database.rollback(sp); // Email will not send as it is rolled Back
                    
                } 
                
                for (Messaging.SingleEmailMessage email : lstMessages) {
                        Messaging.SingleEmailMessage emailToSend = new Messaging.SingleEmailMessage();
                        emailToSend.setOrgWideEmailAddressId(orgWideEmailID);
                        emailToSend.setToAddresses(email.getToAddresses());
                        emailToSend.setPlainTextBody(email.getPlainTextBody());
                        emailToSend.setHTMLBody(email.getHTMLBody());
                        emailToSend.setSubject(email.getSubject());
                        msgListToBeSend .add(emailToSend);
                    }
                
                               
            }
        }
        
        system.debug('----------------------lstMessages in requester ***---------'+lstMessages.size() );
        try {
            if(!msgListToBeSend.isEmpty() ) {
                Messaging.sendEmail(msgListToBeSend);
            }
            if(!finalLstCases.isEmpty() ) {
                StaticFunctions.runOnce();
                StaticFunctions.runOnceAfterTrigger();

                update finalLstCases;
            }
        }
        catch(Exception e) {
            system.debug('Exception occured while updating notified requester'+e);
        }
    
    }

}


@isTest()
public class test_schedule_SLS_Notification_Engine {

    static testMethod void testScheduleSLSCases() {
           
        
        list<contact> lstContacts = TestData.createContacts();
        insert lstContacts;
        
        Employee__c empObj = SLS_TestData.createEmployees();
        insert empObj;
         
        list<case> lstCases = SLS_TestData.createSLSCases(empObj);        
        system.debug('-----lstCases in test class **---'+lstCases);
        
        lstCases[0].notify_creator__c   = '2';
        lstCases[0].notify_requestor__c = '2';
        update lstCases[0];
        
        Test.startTest();
        String CRON_EXP = '0 0 * * * ? *';
        String jobId = System.schedule('ScheduleSLSCasesClassTest',CRON_EXP,new schedule_SLS_Notification_Engine() );
        Test.stopTest(); 
        
    }
 }
Hi all, i have two users both have same profile,i have custom object,if user1 creates a record user2  have the access to edit that record.but i dont want that user2 no need the access to edit that so can u help me on this. 

Thanks 
i have a picklist values draft,prepublished,published,cancelled.if the status is in draft then only record is deleted by user other then not delete. how to do this?
Hi i have a requirment, i have a multipicklist field with values(India,chaina,usa) if i select any one of this values i want to be header of the page.
for example if i select INDIA  and click on save button.it add as a Header of the page.is it possible to do??
thanks for advace

<apex:page controller="customPickListInVFDemoController" tabStyle="Account" > 
  <apex:form >
    <apex:pageBlock id="out">
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}" rerender="out" status="actStatusId"/>
            <apex:actionStatus id="actStatusId">
                <apex:facet name="start">
                    <img src="/img/loading.gif" />
                </apex:facet>
            </apex:actionStatus>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Target Audiance" collapsible="false">
            <apex:selectList value="{!selectedCountry1}" multiselect="True" size="1">
                
                <apex:selectOption itemValue="India" itemLabel="India"/>
                <apex:selectOption itemValue="usa" itemLabel="usa"/>
            </apex:selectList>
            <apex:outputText value="{!selectedCountry1}" label="You have selected:"/>
        </apex:pageBlockSection>
     </apex:pageblock>
  </apex:form>
</apex:page>

public class customPickListInVFDemoController {
public String selectedCountry1{get;set;}
public String selectedCountry2{get;set;}
    public customPickListInVFDemoController(){
    }
     
    public List<SelectOption> getCountriesOptions() {
        List<SelectOption> countryOptions = new List<SelectOption>();
        
        countryOptions.add(new SelectOption('india','india'));
        countryOptions.add(new SelectOption('usa','usa'));
        return countryOptions;
    }
    public PageReference save(){
        return null;
    }
}
Hi, I have two customfields, checkbox and Lookup fields, my requirement is if i check that checkbox then only lookup field is displayed otherwise not displayed,can we write any validationrule on this or any coding??
if i create a case no one can modifyed before 48 hours, i want to send an email to the user or a group? how can i do this can any one suggest?
if i create a case no one can modifyed before 48 hours, i want to send an email to the user or a group? how can i do this can any one suggest?
Hi all, i have two users both have same profile,i have custom object,if user1 creates a record user2  have the access to edit that record.but i dont want that user2 no need the access to edit that so can u help me on this. 

Thanks 
Hi i have a requirment, i have a multipicklist field with values(India,chaina,usa) if i select any one of this values i want to be header of the page.
for example if i select INDIA  and click on save button.it add as a Header of the page.is it possible to do??
thanks for advace

<apex:page controller="customPickListInVFDemoController" tabStyle="Account" > 
  <apex:form >
    <apex:pageBlock id="out">
        <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!save}" rerender="out" status="actStatusId"/>
            <apex:actionStatus id="actStatusId">
                <apex:facet name="start">
                    <img src="/img/loading.gif" />
                </apex:facet>
            </apex:actionStatus>
        </apex:pageBlockButtons>
        <apex:pageBlockSection title="Target Audiance" collapsible="false">
            <apex:selectList value="{!selectedCountry1}" multiselect="True" size="1">
                
                <apex:selectOption itemValue="India" itemLabel="India"/>
                <apex:selectOption itemValue="usa" itemLabel="usa"/>
            </apex:selectList>
            <apex:outputText value="{!selectedCountry1}" label="You have selected:"/>
        </apex:pageBlockSection>
     </apex:pageblock>
  </apex:form>
</apex:page>

public class customPickListInVFDemoController {
public String selectedCountry1{get;set;}
public String selectedCountry2{get;set;}
    public customPickListInVFDemoController(){
    }
     
    public List<SelectOption> getCountriesOptions() {
        List<SelectOption> countryOptions = new List<SelectOption>();
        
        countryOptions.add(new SelectOption('india','india'));
        countryOptions.add(new SelectOption('usa','usa'));
        return countryOptions;
    }
    public PageReference save(){
        return null;
    }
}
Hi, I have two customfields, checkbox and Lookup fields, my requirement is if i check that checkbox then only lookup field is displayed otherwise not displayed,can we write any validationrule on this or any coding??
Hello,

Requirement
1. I wants Last modified time of any of record.
2. Whenever new records been created, whenever first time record is updated that modified time should come as custom field.
3. If update has been done with in 1st minute(60seconds) the field should come as blank, if update has been done after 1minute the field should show last modified time.