• Venkateswarlu P
  • NEWBIE
  • 122 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 13
    Replies
Error : Class sendemail must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)

my batch class :
global class sendemail implements Database.Batchable <sobject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
        String Query;
        Query = 'SELECT Name,Id From Opportunities WHERE CloseDate = Tommorow';
        return Database.getquerylocator(Query);
        }
global void execute(Database.BatchableContext bc, List<Opportunities> opplist) {
        for(Opportunities opp :opplist){
        opp.CloseDate = 'Tommorow'; 
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'nihar.annamaneni@gmail.com'});
        email.setSubject('opportunity closed date');
        email.setPlainTextBody('Dear user, Your opportunity is closed date is tommorow');
        emails.add(email);
        }
        Messaging.sendEmail(emails);
        update opplist;
        }
global void finish(database.BatchableContext bc){
        }
}
  • May 04, 2018
  • Like
  • 0
User-added image
How to generate these kind of reports
Step 1: Display a list of Contacts with a radio button to select one Contact
Step 2: Show the selected Contact in an edit form (You can hardcode a few fields for this assignment). We may update the field value here. On clicking next, Save the updated Contact
Step 3: Show a confirmation screen with the Update Contact.
global class Batch_contact_delete implements Database.Batchable<sobject> {
    global Database.QueryLocator start(Database.BatchableContext bc){
        string query='Select LastName,CreatedDate,AccountId,Account.Id from Contact where CreatedDate=LAST_MONTH';
        return Database.getQueryLocator(query);
    }
    global Void execute(Database.BatchableContext bc,List<contact> conList){
        delete conlist;
    }
    global void finish(Database.BatchableContext bc){
         system.debug('****************Start Finish********************');
    }
}
-------------------
Test Class
--------------------
@isTest
private class Batch_contact_delete_Test_Class {
	@isTest
    static void delConAcc(){
        Account a = new Account();
        a.Name='Raju';
        Insert a;
        Contact c = new contact();
        c.LastName='Ravi';
        c.AccountId=a.id;
        insert c;
        Test.startTest();
        	Batch_contact_delete bd = new Batch_contact_delete();
        	Id JobId = Database.executeBatch(bd,10);
        Test.stopTest();        
        Integer count = [Select count() from Contact where accountId=:a.id];
        System.assertEquals(0, count);
    }
}

I am getting Code covarage as 66% only. Is there any issue with Test class 
public class Contact_Trigger_Handler {
	//whenever a new contact is created, create an event for it.
    public static void eventOnContact(List<contact> conList) {
        List<Event> eventList = new List<Event>();
        For(Contact c : conList){
            Event e = new Event();
            e.Subject=c.LastName;
            e.WhatId = c.accountId;
            e.whoId = c.Id;
            e.Type = 'Contact';
            e.IsAllDayEvent = true;                 	
        	e.StartDateTime = DateTime.now();
            e.EndDateTime=DateTime.now();
            eventList.add(e);            
        }
        insert eventList;        
    }
Test Class
-------------------------------------------------------
@isTest
    static void event(){
        Contact c = new Contact();
        c.lastName='Pawan';
        insert c;   
        Event e = new Event();
            e.Subject=c.lastName;
            e.WhatId = c.accountId;
            e.whoId = c.Id;
            e.Type = 'Contact';
            e.IsAllDayEvent = true;                 	
            e.StartDateTime = DateTime.now();
            e.EndDateTime=DateTime.now();           
        insert e;
        Integer count = [select count() from event limit 1];
        system.assertEquals(count, 1);
        system.assertEquals(e.Subject, c.lastName);
    }

 
public class DML_Account_DetailPage {    
    public string inputAccName		{set;get;}
    public string inputAccPhone		{set;get;}
    public string inputAccRating	{set;get;}	
    public string inputAccIndustry	{set;get;}
   
    public PageReference Create()
    {
        List<Account> accsList=[select id from Account where name=:inputAccName and phone=:inputAccPhone];
        if(accsList.size()>0)
        {
            ApexPages.message msg=new ApexPages.message(ApexPages.severity.ERROR,'Duplicate Record Found');
            ApexPages.addMessage(msg);
            return null;
        }
        else
        {
            Account acc=new Account();
            acc.name=inputAccName;
            acc.phone=inputAccPhone;
            acc.rating=inputAccRating;
            acc.Industry=inputAccIndustry;
            insert acc;
            PageReference p= new PageReference('/'+acc.id);
            return p;           
        }
    }
}
How to write test class for sosl and page reference.
 
public class SOQL_1 {
    public List<Account> accList     {set;get;}
    //Contructor
    public SOQL_1(){
        accList=[SELECT Name,Phone,Industry,Rating from Account];
    }
}
-----------------------------
Test Class
-----------------------------
@isTest
private class Test_Class_3 {	
	@isTest
    static void accList(){
        SOQL_1 s1=new SOQL_1();
        Account a = new Account();
        a.name='Ravi';
        a.phone='12345';
        insert a;
        
        Account a2=[Select Id,Name,Phone from Account where name='Ravi' LIMIT 1];
        System.assert(a2!=null);        
    }    
}
Is this Correct.
 
public class Map_Opportunities {
    public Map<string,List<Opportunity>> oppMap        {set;get;}    
    public List<Account> accList                    {set;get;}
    
    public Map_Opportunities(){
        oppMap = new Map<string,List<Opportunity>>();  
        accList=new List<Account>();
        
        accList = [SELECT name,(SELECT Name,stageName FROM Opportunities)FROM Account];
        for (Account a :accList){
            oppMap.put(a.Name, a.Opportunities);
        }                    
    }
}
-------------------------------------------
Test Class
--------------------------------------------
@isTest
    static void mapOpportunits(){
        Map_Opportunities mp = new Map_Opportunities();
        List<Opportunity> optyList = new List<Opportunity>();
        account acc = new Account();
        acc.name = 'Ravi';
        insert acc;
        
        opportunity op = new Opportunity();
        op.Name = 'Xyz';
        op.AccountId = acc.id;
        op.CloseDate = system.today();
        op.StageName ='Closed Won';    
        optyList.add(op);
        insert optyList;
        mp.oppMap.put(acc.Name, optyList);
    }
85% code is covered and Displaying Error : oppMap.put(a.Name, a.Opportunities);
public class Map_Accounts {   
    public Map<Id,Account> accMap        {set;get;}
    public List<Account> accList         {set;get;}
    public Account a                    {set;get;}    
    // Constructor
    public Map_Accounts(){
        accMap = new Map<id,Account>();         
        accList=[Select Id, Name from Account limit 5];
        accMap.putAll(accList);
              
        for (Id idKeys : accMap.keySet()){
            a = accMap.get(idKeys);
        }        
    }  
}
User Object has Records and Custom Object[Emp] has no records in it. User object has records in it, so we can't create a master detail relation.Created lookup relation, Then try to convert look up to master by clicking on change field type there is no master detail option to select.
emp Object has below fields.
User-added image
public static void accountOptyCount(List<Opportunity> optyList){
        List<Account> accList=new List<Account>();
        Set<Id> optyIds = new Set<Id>();        
        For(Opportunity op:optyList){
           optyIds.add(op.AccountId);
           System.debug('optyIds List=======>: '+optyIds); 
        }
        accList=[SELECT Id,optyCount__c,(SELECT Id from Opportunities) from Account where Id in:optyIds];
        System.debug('accList List=======>: '+accList);
        For(Account a:accList){
            a.optyCount__c=a.Opportunities.size();
            System.debug('Opportunity count=======>: '+a.optyCount__c);
           /* Decimal sum=0;
            For(Opportunity opp:a.Opportunities){                
                sum=sum+1;
                System.debug('Sum=======>: '+sum);
            }
            a.optyCount__c=sum; */
        }
        update accList;
    }
===========
If(Trigger.isBefore && Trigger.isInsert){        
        Opportunity_Trigger_handler.accountOptyCount(Trigger.new);}
Final output comming as Account and Opportunity ID. i want to display Account name and opportunity names

public class Map_Opportunities {
    public Map<string,List<Opportunity>> oppMap        {set;get;}
    public List<Opportunity> optyList                {set;get;}
    
    public Map_Opportunities(){
        oppMap = new Map<string,List<Opportunity>>();  
        
        for (Account acc: [SELECT name,(SELECT Name FROM Opportunities)FROM Account]){            
            oppMap.put(acc.Name,acc.Opportunities);            
        }        
    }
}
///VF
<apex:page controller="Map_Opportunities">
    <apex:form >
        <apex:pageBlock title="Account Map">
            <apex:pageBlockButtons location="Bottom" style="opportunity">                
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1" collapsible="false" >
                <apex:pageBlockTable value="{!oppMap}" var="m">
                    <apex:column value="{!m}" headerValue="Account Name"/>
                    <apex:column value="{!oppMap[m]}" headerValue="Opportunity Name"/>
                </apex:pageBlockTable>                
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
Hi I have a custom setting which will contain the some part of "Subject", now when I will receive an email I need to compare this custom setting value from the "Subject" of the email. below is the code but Contains function is not working as it works only for Sequencing string.
In below code consider str2 is the custom setting value and str1 is the subject value from the inbound email

string str1= 'As Oy Viherlaaksonranta 9 osoitteenmuutos';
string str2= 'As Oy osoitteenmuutos';

if(str2.contains(str1)){
   system.debug('inside if');
}
Create object : Hire_Form__c
Fields :
1.       First Name
2.       Last name
3.       Email
4.       Phone
5.       Status (In Progress , Completed , Rejected)
6.       Candidate (Contact Lookup)
7.       Description
 
Create Trigger on Hire_form__c
1.       When hire_form__c  record is insert set status = ‘In Progress’. Create new contact record with firstname , lastname , email, phone. Set contact id in Candidate field on  Hire_form object. Create new case record for new created contact record. Set status in case = ‘New’.
2.       When Hire_form is updated with status = ‘Completed’ , then update the status of related case ‘Closed’.
Create Trigger on Case
1.       When case is updated with Status = ‘Closed’ , then check  if parent contact’s related hire form status is not ‘Completed’ , then show error message ‘You can not close the case until hire form  is completed’.
 
 
Error : Class sendemail must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)

my batch class :
global class sendemail implements Database.Batchable <sobject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
        String Query;
        Query = 'SELECT Name,Id From Opportunities WHERE CloseDate = Tommorow';
        return Database.getquerylocator(Query);
        }
global void execute(Database.BatchableContext bc, List<Opportunities> opplist) {
        for(Opportunities opp :opplist){
        opp.CloseDate = 'Tommorow'; 
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        email.setToAddresses(new String[] {'nihar.annamaneni@gmail.com'});
        email.setSubject('opportunity closed date');
        email.setPlainTextBody('Dear user, Your opportunity is closed date is tommorow');
        emails.add(email);
        }
        Messaging.sendEmail(emails);
        update opplist;
        }
global void finish(database.BatchableContext bc){
        }
}
  • May 04, 2018
  • Like
  • 0
public class Contact_Trigger_Handler {
	//whenever a new contact is created, create an event for it.
    public static void eventOnContact(List<contact> conList) {
        List<Event> eventList = new List<Event>();
        For(Contact c : conList){
            Event e = new Event();
            e.Subject=c.LastName;
            e.WhatId = c.accountId;
            e.whoId = c.Id;
            e.Type = 'Contact';
            e.IsAllDayEvent = true;                 	
        	e.StartDateTime = DateTime.now();
            e.EndDateTime=DateTime.now();
            eventList.add(e);            
        }
        insert eventList;        
    }
Test Class
-------------------------------------------------------
@isTest
    static void event(){
        Contact c = new Contact();
        c.lastName='Pawan';
        insert c;   
        Event e = new Event();
            e.Subject=c.lastName;
            e.WhatId = c.accountId;
            e.whoId = c.Id;
            e.Type = 'Contact';
            e.IsAllDayEvent = true;                 	
            e.StartDateTime = DateTime.now();
            e.EndDateTime=DateTime.now();           
        insert e;
        Integer count = [select count() from event limit 1];
        system.assertEquals(count, 1);
        system.assertEquals(e.Subject, c.lastName);
    }

 
User Object has Records and Custom Object[Emp] has no records in it. User object has records in it, so we can't create a master detail relation.Created lookup relation, Then try to convert look up to master by clicking on change field type there is no master detail option to select.
emp Object has below fields.
User-added image
public static void accountOptyCount(List<Opportunity> optyList){
        List<Account> accList=new List<Account>();
        Set<Id> optyIds = new Set<Id>();        
        For(Opportunity op:optyList){
           optyIds.add(op.AccountId);
           System.debug('optyIds List=======>: '+optyIds); 
        }
        accList=[SELECT Id,optyCount__c,(SELECT Id from Opportunities) from Account where Id in:optyIds];
        System.debug('accList List=======>: '+accList);
        For(Account a:accList){
            a.optyCount__c=a.Opportunities.size();
            System.debug('Opportunity count=======>: '+a.optyCount__c);
           /* Decimal sum=0;
            For(Opportunity opp:a.Opportunities){                
                sum=sum+1;
                System.debug('Sum=======>: '+sum);
            }
            a.optyCount__c=sum; */
        }
        update accList;
    }
===========
If(Trigger.isBefore && Trigger.isInsert){        
        Opportunity_Trigger_handler.accountOptyCount(Trigger.new);}
Final output comming as Account and Opportunity ID. i want to display Account name and opportunity names

public class Map_Opportunities {
    public Map<string,List<Opportunity>> oppMap        {set;get;}
    public List<Opportunity> optyList                {set;get;}
    
    public Map_Opportunities(){
        oppMap = new Map<string,List<Opportunity>>();  
        
        for (Account acc: [SELECT name,(SELECT Name FROM Opportunities)FROM Account]){            
            oppMap.put(acc.Name,acc.Opportunities);            
        }        
    }
}
///VF
<apex:page controller="Map_Opportunities">
    <apex:form >
        <apex:pageBlock title="Account Map">
            <apex:pageBlockButtons location="Bottom" style="opportunity">                
            </apex:pageBlockButtons>
            <apex:pageBlockSection columns="1" collapsible="false" >
                <apex:pageBlockTable value="{!oppMap}" var="m">
                    <apex:column value="{!m}" headerValue="Account Name"/>
                    <apex:column value="{!oppMap[m]}" headerValue="Opportunity Name"/>
                </apex:pageBlockTable>                
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
How can I get the current Salesforce User ID in an Apex class?

Any help is appreciated!

Chris