• SHAHNA MULLA
  • NEWBIE
  • 80 Points
  • Member since 2018

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 27
    Replies

Hello,
I am trying to create an apex class that will send an email alert 60 days and 45 days before a contract end date. Here are the requirements:
On the account object, there is a date field called, Contract_End_Date__c. An alert must be sent to a user 60 days and 45 days before the Contract_End_Date__c. An alert is sent to one person when the Contract_Amount__c is greater than or equal to 2500 and to a different person when the Contract_Amount__c is less than 2500.

My idea was to create an apex class with a scheduler class and have it run every night to check if Today's date is 60 days or 45 days from the Contract_End_Date__c. Below is my code but I am getting this error: Dependent class is invalid and needs recompilation: Class RenewCredit : Static method cannot be referenced from a non static context: void CreditRenewalNotification.NotifyRenewal()

 

Apex Class: 

public with sharing class CreditRenewalNotification
{
    
    public static void NotifyRenewal()
    {
        Messaging.SingleEmailMessage AlertOver = new Messaging.SingleEmailMessage(); //Alert when greater than or equal to 2500
        Messaging.SingleEmailMessage AlertUnder = new Messaging.SingleEmailMessage(); //Alert when less than 2500
        
        String[] toAdd1 = new String[] 
        {
            'test@test.com'
        };
        
        String[] toAdd2 =  new String[] 
        {
            'tes1@test.com'
            
        };
        
        Account[] acct = [SELECT Id, Name, Contract_Start_Date__c, Contract_End_Date__c, Contract_Amount__c FROM Account WHERE Contract_End_Date__c != NULL AND Contract_Amount__c != NULL];
        
        for(Account a: acct)
        {
            String sURL = URL.getSalesforceBaseUrl().toExternalForm()+ '/'+a.Id;
            Date tod = System.today();
            System.debug('%%%%%%%%% '+tod);
            Date contEnd = a.Contract_End_Date__c;
            System.debug('&&&&& '+contEnd);
            Integer dayDiff = contEnd.daysBetween(tod);
            System.debug('******* '+dayDiff);
            
            
            if(dayDiff == 60)
            {    
                Integer days = 60;
                
            	if(a.Contract_Amount__c >= 2500)
                {
                    String bod = 'The following account will need to be renewed in '+days+'.<br/>';
                    bod += 'Name: '+a.Name+ '<br/>';
                    bod += 'Contract Start Date: '+a.Contract_Start_Date__c+ '<br/>';
                    bod += 'Contract End Date: '+a.Contract_End_Date__c+ '<br/>';
                    bod += 'Contract Amount: $'+a.Contract_Amount__c+ '<br/>';
                    bod += 'Link: '+sURL+ '<br/>';
                    
                    AlertOver.setSubject('ALERT: '+a.Name+ 'has a contract expiring in '+days+' days.');
                    AlertOver.setToAddresses(toAdd1);
                    AlertOver.setSaveAsActivity(False);
                    AlertOver.setHtmlBody(bod);
                    
                    try {
                            Messaging.sendEmail(new Messaging.Email[] {
                                AlertOver
                            });
                        } catch (Exception e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
                        }
                
                }
                else
                {
                    
                    String bod = 'The following account will need to be renewed in '+days+'.<br/>';
                    bod += 'Name: '+a.Name+ '<br/>';
                    bod += 'Contract Start Date: '+a.Contract_Start_Date__c+ '<br/>';
                    bod += 'Contract End Date: '+a.Contract_End_Date__c+ '<br/>';
                    bod += 'Contract Amount: $'+a.Contract_Amount__c+ '<br/>';
                    bod += 'Link: '+sURL+ '<br/>';
                    
                    AlertUnder.setSubject('ALERT: '+a.Name+ 'has a contract expiring in '+days+' days.');
                    AlertUnder.setToAddresses(toAdd2);
                    AlertUnder.setSaveAsActivity(False);
                    AlertUnder.setHtmlBody(bod);
                    
                    
                    try {
                            Messaging.sendEmail(new Messaging.Email[] {
                                AlertUnder
                            });
                        } catch (Exception e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
                        }
                    
                }
            }
            if(dayDiff == 45)
            {
                Integer days1 = 45;
                
                if(a.Contract_Amount__c >= 2500)
                {
                    try {
                            Messaging.sendEmail(new Messaging.Email[] {
                                AlertOver
                            });
                        } catch (Exception e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
                        }
                    
                }
                else
                {
                    try {
                            Messaging.sendEmail(new Messaging.Email[] {
                                AlertUnder
                            });
                        } catch (Exception e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
                        }
                    
                }    
            }
        }
    	
    }
}


Scheduler class:

global class RenewCredit implements Schedulable{
global void execute(SchedulableContext SC) {
        CreditRenewalNotification cred = new CreditRenewalNotification();
        cred.NotifyRenewal();
    }
}


Any help one this would be great! Thanks!
 
Hi All,
If Rating(Piclist field) is "Warm" then only  FieldA,FieldB and FieldC should be editable for other picklist value should not ediatble.

Thanks in advance.
 
Hello All,

Kindly give the suggestions on my scenrio:

I am creating a Custom object (Registration form) here i am make Vfpage also and i want to save the data into the database via VF Page;
Here i am using apex class and VF page(IT WORKS FINE)
Now i want to use some Radio button on it like Gender==Male and Female in Radio Button,so on this i have to create the datatype???
As i have to save the records in database through VF page entry.

public class BuilderSaveClass {
    
    public string name                         {set;get;}
    public string location                    {set;get;}
    public string state                     {set;get;}
    public boolean ActiveStatus             {Set;get;}
   // public list<SelectOption> country       {set;get;}  
    
    public void saveMe(){
       // country=new list<selectOption>();
        //country.add(new SelectOption('India','India'));
          //  country.add(new SelectOption('UK','UK'));
        Builder__c     bc=new Builder__c();
        bc.Name=name;
        bc.Location__c=location;
        bc.State__c=state;
        bc.Active__c=ActiveStatus;
            insert bc;
    }
    
    
    public void cancelMe(){
        name=null;
        location=null;
        state=null;
        ActiveStatus=null;
        
        
    }
}

VF PAGE
<apex:page controller="BuilderSaveClass">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons location="top" >
                <apex:commandButton value="saveMe" action="{!saveMe}"/>
                <apex:commandButton value="Cancel" action="{!cancelMe}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1" id="id">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Name"/>
                    <apex:inputText value="{!name}"/>   
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Location"/>
                    <apex:inputText value="{!location}"/>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    State:<apex:selectList size="1" value="{!state}">
                    <apex:selectOption itemLabel="None" itemValue="None"></apex:selectOption>
                    <apex:selectOption itemLabel="Delhi" itemValue="DElhi"></apex:selectOption>
                    <apex:selectOption itemLabel="UP" itemValue="UP"></apex:selectOption>
                    <apex:selectOption itemLabel="PUNJAB" itemValue="PUNJAB"></apex:selectOption>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem>
                    ActiveStatus:<apex:inputCheckbox value="{!ActiveStatus}"/>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
        
    </apex:form>
</apex:page>
I want to query in Salesforce database for an inactive user to check if he is owning any records or not?
I tried to query in Salesforce data loader but it only queries on one entity at a time. Also, the same behavior is shown for Reports wherein one entity gets queried at a time. 

Please advise further. Thanks
Hi,
i am trying to create record for organization object but It is not available in my salesforce developer account, 
Can anybody help me to add organization object in salesforce developer account as like contact,case,account,etc.,

Thanks..,
Hello,

I am trying to create a visualforce page listing all the etitlements based on the userId. I have created a global class and using its function in a different class and when I am trying to show the data on the vf page it is showing me the error.

Here is my code: 
VF page

<apex:page standardcontroller="Claim_Request__c" extensions="EntitlementData" >
        <html>
            <head>
           
            </head>
            <body>
                <apex:pageBlock title="Entitlement details of the employee">
                    <apex:pageBlockSection columns="1">
                        <apex:form >
                            
                                <table>
                                    <tr>
                                        <th>Entitlement Type</th>
                                        <th>Entitlement Amount</th>
                                         <th>Entitlement Applicability</th>
                                    </tr>
                                    <apex:repeat value="{!entitlements}" var="entitle">
                                           <apex:repeat value="{!entitlements[entitle]}" var="map">

                                    <tr>
                                        <td><apex:outputfield value="{!map.Entitlement_Type__c}" /></td>
                                        <td><apex:outputfield value="{!map.Entitlement_Amount__c}"/></td>
                                        <td><apex:outputfield value="{!map.Applicability__c}"/></td>
                                    </tr>
                                        </apex:repeat>
                                    </apex:repeat>
                                </table>    
                                <br/>
                            
                        </apex:form>
                    </apex:pageBlockSection>
                </apex:pageBlock>
            </body>
        </html>
</apex:page>

Controller

public class EntitlementData 
{   
    Map<Id, Object > entitlements {get;set;}
    
    public user usr;
    public EntitlementData(ApexPages.StandardController controller )
    {
        
        List <Id> lst = new list<Id>();
           TESTQurty bg1 = new TESTQurty();
    
        //query to take out the current user department information
        user usr = [select id from user where id =: Userinfo.getUserId()]; 
           lst.add(usr.Id);
        entitlements = bg1.getEmployeeEntitlements(lst);
    }
}

Global Class

public class TESTQurty {
    // Global Enums 
    public enum APPLICABILITY {MONTHLY, ANNUALLY}
    public enum CATEGORY {ORGANIZATIONAL, DEPARTMENTAL}
   
    // Global Constants
    public final String ENTL_DPT_REC_TYPE = 'Department Entitlement';
    public final String ENTL_GBL_REC_TYPE = 'Global Entitlement';
   
    public User usr;
  
    // Global data structures
    // To Store Entitlement Information
    public class Entitlements {
        Decimal Amount {get;set;}
        String Type {get;set;} // Entitlement Types e.g. Phone, Broadband etc.
        APPLICABILITY Applicability {get;set;}
        CATEGORY Category {get;set;}
        
        public Entitlements(Decimal Amt, String EType, APPLICABILITY apl, CATEGORY cat)
        {
            Amount = Amt; 
            Type=EType; 
            Applicability=apl; 
            Category=cat;
            
        }
    }
    
    // To Store Claimed Data
    public  class ClaimedInfo {
        Decimal Amount {get;set;}
        String Type {get;set;} // Entitlement Types e.g. Phone, Broadband etc.
        String Month {get;set;} 
        String Year {get;set;}
        
        public ClaimedInfo(Decimal amt, String cType, String mon, string yr)
        {
            amount = amt;
            Type = cType;
            month = mon;
            year= yr;
        }
    }
    
    // Utility method to get the list of all entitlements 
    // applicable to the given list of employee ids
    public Map<Id, List<Entitlements>> getEmployeeEntitlements(List<Id> EmployeeIds){
        
        
        // Local variables
        Map<Id, List<Entitlements>> mapEntilementsByEmpIds = new Map<Id, List<Entitlements>>();
        Map<Id, List<Entitlements>> mapEntilementsByDepts = new Map<Id, List<Entitlements>>();
        List<Entitlement__c> lstEntitlementsByEmp = new List<Entitlement__c>();
        List<Entitlements> lsEntitlementGlobal = new List<Entitlements>();
        
        // Get list of departments for the given list of employees
        //Set<Id> lstDepartments = new Set<Id>();
        Map<Id,Id> mapDeptByEmp = new Map<Id, Id>();
        // Query Employee and get Department details
        for(Employee__c emps: [SELECT Id,Department_Number__c from Employee__c where Id =: EmployeeIds]){
            // Check if exist in the set if not then add
            if(!mapDeptByEmp.containsKey(emps.id))
                mapDeptByEmp.put(emps.id, emps.Department_Number__c);    
            
        }// End of for
        System.debug('Emp By Dept : ' + mapDeptByEmp);
        
        
                
        // Query Entitlements Object to get list of all entitlements 
        for(Entitlement__c entl : [SELECT Entitlement_Type__c,
                                        Entitlement_Amount__c,
                                        Applicability__c,
                                        RecordType.Name,
                                        Department_Number__c
                                    FROM Entitlement__c 
                                    WHERE 
                                        (Department_Number__c = : mapDeptByEmp.values()
                                    AND RecordType.Name =: ENTL_DPT_REC_TYPE) 
                                     OR RecordType.Name =: ENTL_GBL_REC_TYPE]){
            
            // Check if this is the record is global or departmental
            if(entl.RecordType.Name == ENTL_GBL_REC_TYPE){
                lsEntitlementGlobal.add(new Entitlements (entl.Entitlement_Amount__c,
                                                          entl.Entitlement_Type__c,                                                    
                                                         (entl.Applicability__c=='Monthly')?APPLICABILITY.MONTHLY:APPLICABILITY.ANNUALLY,
                                                         CATEGORY.ORGANIZATIONAL
                                                         ));
            } else if(entl.RecordTYpe.Name == ENTL_DPT_REC_TYPE )    {        
            
                    // Check if employee exists in the map
                    if (!mapEntilementsByDepts.containsKey(entl.Department_Number__c) ){
                        
                        List<Entitlements> lstEntitlement = new List<Entitlements>();
                        
                        lstEntitlement.add(new Entitlements(entl.Entitlement_Amount__c,
                                                          entl.Entitlement_Type__c,                                                    
                                                         (entl.Applicability__c=='Monthly')?APPLICABILITY.MONTHLY:APPLICABILITY.ANNUALLY,
                                                         CATEGORY.DEPARTMENTAL));
                        
                        mapEntilementsByDepts.put(entl.Department_Number__c, lstEntitlement);
                        
                    } else {
                        

                        mapEntilementsByDepts.get(entl.Department_Number__c).add(new Entitlements(entl.Entitlement_Amount__c,
                                                                                                  entl.Entitlement_Type__c,                                                    
                                                                                                  (entl.Applicability__c=='Monthly')?APPLICABILITY.MONTHLY:APPLICABILITY.ANNUALLY,
                                                                                                  CATEGORY.DEPARTMENTAL));
                        
                    } /// End of Check if employee exists in the map
            
            
            } // End of else if
        
        } // End of for
        system.debug(lsEntitlementGlobal);
        system.debug(mapEntilementsByDepts);
        
        
        
        // Populate the final out put map based on employee
        for(Id empId:EmployeeIds ){
            
            
            // Add departmental entitlements for the employee
            mapEntilementsByEmpIds.put(empId, mapEntilementsByDepts.get(mapDeptByEmp.get(empId)));        
                        
            // Add global list applicable for the employee
            mapEntilementsByEmpIds.get(empId).addAll(lsEntitlementGlobal);
        }// End of for        
        
        return mapEntilementsByEmpIds;
        
    } // End of getEmployeeEntitlements

Thanks in Advance
Hi Everyone,

Someone please help me, to Query Any records which contains any numeric value on 2nd place.
For eg: I have 7 accounts with name : 

UnitedAccount,
B12Account,
c13Account,
e6account,
BerlingtonAccount,
75account,
p18TestAccount etc.

I want to query details of those accounts whose name has numeric value on 2nd place.
So, output should be for these accounts:

B12Account,
c13Account,
e6account,
71account,
p18TestAccount

So, what query can i write to fetch these accounts details?
Any help would be greatly appreciated.
Hi,
We have a custom Object Donations which hold the donations history. have 2 fields called - Total Gifts(amount) and other one Average Gift(Amount). when a donor makes a donation then we need these 2 fields to calculate and automatically update accordingly. Can someone help me as what to do please...
Hi, 

  I want to create a record lock when "Opportunity stage is StageEQUALSClosed Lost,Closed Other,Closed - Cancelled,Closed Other Renewal,    record must be locked, except for system administer profile.  Please suggest me how to do record lock when this conditions are met. 

Thanks
Sudhir
  • August 09, 2018
  • Like
  • 0

Hello,
I am trying to create an apex class that will send an email alert 60 days and 45 days before a contract end date. Here are the requirements:
On the account object, there is a date field called, Contract_End_Date__c. An alert must be sent to a user 60 days and 45 days before the Contract_End_Date__c. An alert is sent to one person when the Contract_Amount__c is greater than or equal to 2500 and to a different person when the Contract_Amount__c is less than 2500.

My idea was to create an apex class with a scheduler class and have it run every night to check if Today's date is 60 days or 45 days from the Contract_End_Date__c. Below is my code but I am getting this error: Dependent class is invalid and needs recompilation: Class RenewCredit : Static method cannot be referenced from a non static context: void CreditRenewalNotification.NotifyRenewal()

 

Apex Class: 

public with sharing class CreditRenewalNotification
{
    
    public static void NotifyRenewal()
    {
        Messaging.SingleEmailMessage AlertOver = new Messaging.SingleEmailMessage(); //Alert when greater than or equal to 2500
        Messaging.SingleEmailMessage AlertUnder = new Messaging.SingleEmailMessage(); //Alert when less than 2500
        
        String[] toAdd1 = new String[] 
        {
            'test@test.com'
        };
        
        String[] toAdd2 =  new String[] 
        {
            'tes1@test.com'
            
        };
        
        Account[] acct = [SELECT Id, Name, Contract_Start_Date__c, Contract_End_Date__c, Contract_Amount__c FROM Account WHERE Contract_End_Date__c != NULL AND Contract_Amount__c != NULL];
        
        for(Account a: acct)
        {
            String sURL = URL.getSalesforceBaseUrl().toExternalForm()+ '/'+a.Id;
            Date tod = System.today();
            System.debug('%%%%%%%%% '+tod);
            Date contEnd = a.Contract_End_Date__c;
            System.debug('&&&&& '+contEnd);
            Integer dayDiff = contEnd.daysBetween(tod);
            System.debug('******* '+dayDiff);
            
            
            if(dayDiff == 60)
            {    
                Integer days = 60;
                
            	if(a.Contract_Amount__c >= 2500)
                {
                    String bod = 'The following account will need to be renewed in '+days+'.<br/>';
                    bod += 'Name: '+a.Name+ '<br/>';
                    bod += 'Contract Start Date: '+a.Contract_Start_Date__c+ '<br/>';
                    bod += 'Contract End Date: '+a.Contract_End_Date__c+ '<br/>';
                    bod += 'Contract Amount: $'+a.Contract_Amount__c+ '<br/>';
                    bod += 'Link: '+sURL+ '<br/>';
                    
                    AlertOver.setSubject('ALERT: '+a.Name+ 'has a contract expiring in '+days+' days.');
                    AlertOver.setToAddresses(toAdd1);
                    AlertOver.setSaveAsActivity(False);
                    AlertOver.setHtmlBody(bod);
                    
                    try {
                            Messaging.sendEmail(new Messaging.Email[] {
                                AlertOver
                            });
                        } catch (Exception e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
                        }
                
                }
                else
                {
                    
                    String bod = 'The following account will need to be renewed in '+days+'.<br/>';
                    bod += 'Name: '+a.Name+ '<br/>';
                    bod += 'Contract Start Date: '+a.Contract_Start_Date__c+ '<br/>';
                    bod += 'Contract End Date: '+a.Contract_End_Date__c+ '<br/>';
                    bod += 'Contract Amount: $'+a.Contract_Amount__c+ '<br/>';
                    bod += 'Link: '+sURL+ '<br/>';
                    
                    AlertUnder.setSubject('ALERT: '+a.Name+ 'has a contract expiring in '+days+' days.');
                    AlertUnder.setToAddresses(toAdd2);
                    AlertUnder.setSaveAsActivity(False);
                    AlertUnder.setHtmlBody(bod);
                    
                    
                    try {
                            Messaging.sendEmail(new Messaging.Email[] {
                                AlertUnder
                            });
                        } catch (Exception e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
                        }
                    
                }
            }
            if(dayDiff == 45)
            {
                Integer days1 = 45;
                
                if(a.Contract_Amount__c >= 2500)
                {
                    try {
                            Messaging.sendEmail(new Messaging.Email[] {
                                AlertOver
                            });
                        } catch (Exception e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
                        }
                    
                }
                else
                {
                    try {
                            Messaging.sendEmail(new Messaging.Email[] {
                                AlertUnder
                            });
                        } catch (Exception e) {
                            System.debug('An unexpected error has occurred: ' + e.getMessage());
                        }
                    
                }    
            }
        }
    	
    }
}


Scheduler class:

global class RenewCredit implements Schedulable{
global void execute(SchedulableContext SC) {
        CreditRenewalNotification cred = new CreditRenewalNotification();
        cred.NotifyRenewal();
    }
}


Any help one this would be great! Thanks!