• SFDC Coder 8
  • NEWBIE
  • 150 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 31
    Questions
  • 24
    Replies
Hi All,
I want to send a mail when ever I updated a checkboc (Check__c) in my custom object. (Object1__c).
How can I do this through Apex?
Please help me

Thanks in Advance.
Hi All,
I have custom object Obj1__c.
I have a filed Category__c.
When record is updated I want to send a mail to the queue.
Suppaose if I give a value for Category__c is ABC, I want send a mail to ABC queue.
Like this I have  6 queues. Based on the value I give for category__c, I want send a mail to different queues.
How can I do this.
Please help me.
Hi All,
I have one custom as Student__c. I have one custom picklist as Status__c and values for Status__c are New,Joined. Default value for Status__c is New.
I have one more field as Total_Students__c (Number Data type).
After creating first record, if Status__c is changed to Joined then I want to auto fill Total_Students__c = 1.
After creating second record, if Status__c is changed to Joined then I want to auto fill Total_Students__c = 2.
Like this I want auto number fill for  Total_Students__c when ever Status__c is changed to Joined.

Please suggest me how can I do this?

Thanks in Advance

 
Hi All,
I have one custom object. When ever I created a record in this object, I want to send it to a queue for approval.
When it is approved by that queue user, I want to send it to another queue and want to get it approve.

How can I do this?
Please help me

Thanks in Advance.
Hi All,
I have written a batch apex to insert records.
I have written a test class for the same. But some lines are not covering.
Please help me cover those lines.
Here is my code
global class batchInsert Implements Schedulable, Database.Batchable<sObject>{
global void execute(SchedulableContext sc) {
    Database.executeBatch(this);
}

global database.queryLocator start(Database.BatchableContext BC) {
    
    Date d = System.today(); 
    Datetime dt = (DateTime)d; 
    String dayOfWeek = dt.format('EEEE');
   
    if (dayOfWeek == 'Monday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Monday__c='Yes']);
    else if (dayOfWeek == 'Tuesday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Tuesday__c='Yes']);
    else if (dayOfWeek == 'Wednesday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Wednesday__c='Yes']);
    else if (dayOfWeek == 'Thursday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Thursday__c='Yes']);
    else if (dayOfWeek == 'Friday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Friday__c='Yes']);
    else if (dayOfWeek == 'Saturday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Saturday__c='Yes']);
    else 
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Sunday__c='Yes']);
    

} 

global void execute(Database.BatchableContext BC, list <Obj1__c> scope) {

    List <Obj2__c> creList = new List<Obj2__c>();
    Date d = System.today(); 
    Datetime dt = (DateTime)d; 
    String dayIs = dt.format('EEEE');
 
    
    for(Obj1__c c : scope) {
            Obj2__c obj             = new Obj2__c();
        
           
            
            obj.F1__c=c.F1__c;
            obj.F2__c=c.F2__c;
           
            if(dayIs=='Monday' && c.Monday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Monday' &&c.Monday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Tuesday' &&c.Tuesday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Tuesday' &&c.Tuesday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Wednesday' &&c.Wednesday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Wednesday' &&c.Wednesday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Thursday' &&c.Thursday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Thursday' &&c.Thursday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Friday' &&c.Friday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Friday' &&c.Friday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Saturday' &&c.Saturday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Saturday' &&c.Saturday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Sunday' &&c.Sunday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Sunday' &&c.Sunday__c == 'No'){
            obj.F3__c='No';
            }
           
           creList.add(obj);
    } 

    
        insert creList;
     
} 

global void finish(Database.BatchableContext BC) {


} 
}
Test Class:
@isTest(seealldata=true)
public class  testSendeBatch
{

Public static testMethod void method3()
{ 

Obj1__c cp=new Obj1__c();
cp.F1__c='Test';
cp.F2__c='Test2';

batchInsert sb=new batchInsert();
     
        Test.startTest();
        Database.executeBatch(sb);
        Test.stopTest();
       
    }
 
 
  }
I am not able to cover lines between Line number 12 to 25 and Line number 46 to 87.
Please help me how to cover these lines.
Thanks in Advance

 
Hi All,
I am getting Null value while fetching value for day of week.
Here is my code.
global class batchInsert Implements Schedulable, Database.Batchable<sObject>{

	private Date d;
	
	public batchInsert(Date d) {
        d = (Date)d;
    }
    
    
	global database.queryLocator start(Database.BatchableContext BC) {
	    Datetime dt = d; 
	    String dayOfWeek = dt.format('EEEE');
	    ...
	} 

	global void execute(Database.BatchableContext BC, list <Obj1__c> scope) {
	    List <Obj2__c> creList = new List<Obj2__c>();
	    Datetime dt = (DateTime)d; 
	    String dayIs = dt.format('EEEE');
	    ...
	}


I am not getting value at Line 12 for dayOfWeek (String dayOfWeek = dt.format('EEEE');)

Please suggest me what change I need to do.
Thanks in Advance

Hi All,
I have written a batch apex to insert records.
I have written a test class for the same. But some lines are not covering.
Please help me cover those lines.
Here is my code
global class batchInsert Implements Schedulable, Database.Batchable<sObject>{
global void execute(SchedulableContext sc) {
    Database.executeBatch(this);
}

global database.queryLocator start(Database.BatchableContext BC) {
    
    Date d = System.today(); 
    Datetime dt = (DateTime)d; 
    String dayOfWeek = dt.format('EEEE');
   
    if (dayOfWeek == 'Monday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Monday__c='Yes']);
    else if (dayOfWeek == 'Tuesday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Tuesday__c='Yes']);
    else if (dayOfWeek == 'Wednesday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Wednesday__c='Yes']);
    else if (dayOfWeek == 'Thursday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Thursday__c='Yes']);
    else if (dayOfWeek == 'Friday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Friday__c='Yes']);
    else if (dayOfWeek == 'Saturday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Saturday__c='Yes']);
    else 
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Sunday__c='Yes']);
    

} 

global void execute(Database.BatchableContext BC, list <Obj1__c> scope) {

    List <Obj2__c> creList = new List<Obj2__c>();
    Date d = System.today(); 
    Datetime dt = (DateTime)d; 
    String dayIs = dt.format('EEEE');
 
    
    for(Obj1__c c : scope) {
            Obj2__c obj             = new Obj2__c();
        
           
            
            obj.F1__c=c.F1__c;
            obj.F2__c=c.F2__c;
           
            if(dayIs=='Monday' && c.Monday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Monday' &&c.Monday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Tuesday' &&c.Tuesday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Tuesday' &&c.Tuesday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Wednesday' &&c.Wednesday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Wednesday' &&c.Wednesday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Thursday' &&c.Thursday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Thursday' &&c.Thursday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Friday' &&c.Friday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Friday' &&c.Friday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Saturday' &&c.Saturday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Saturday' &&c.Saturday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Sunday' &&c.Sunday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Sunday' &&c.Sunday__c == 'No'){
            obj.F3__c='No';
            }
           
           creList.add(obj);
    } 

    
        insert creList;
     
} 

global void finish(Database.BatchableContext BC) {


} 
}

Test class
@isTest(seealldata=true)
public class  testSendeBatch
{

Public static testMethod void method3()
{ 

Obj1__c cp=new Obj1__c();
cp.F1__c='Test';
cp.F2__c='Test2';

batchInsert sb=new batchInsert();
     
        Test.startTest();
        Database.executeBatch(sb);
        Test.stopTest();
       
    }
 
 
  }
I am not able to cover lines between Line number 12 to 25 and Line number 46 to 87.
Please help me how to cover these lines.
Thanks in Advance
 
Hi All,
I have written a trigger on Order.
I am giving errors in two scenarios. I have one custom field Blocked__c in account. If I have blocked__c = Y, I dont want to create order.
This condition is not working properly.
This is my code. Please tell me where is bug
trigger orderTrigger on Order (before insert) {

List<Order> ordLs = [Select Id, F1__c,Status,AccountId,Account.Blocked__c from Order where createdDate=today ];  

for (Order ordNew : Trigger.new)
  {      
    for(Order oa: ordLs)
        {         
               if(oa.AccountId == ordNew.AccountId && oa.F1__c == ordNew.F1__c && oa.status == 'confirmed')         
                  {              
                    ordNew.AccountId.addError('Some messge');        
                  } 
               if(oa.Account.Blocked__c=='Y') {
                   ordNew.AccountId.addError('Blocked'); 
               } 
         }
        
  }

}

Please help me.
Line Number 13 is not working properly. Please suggest me changes.
Thanks in Advance
Hi All,
I have two custom objects (Obj1__c & Obj2__c). I have account name as common in two objects.
I have three fields in Obj1 and Obj2.
When ever I am updating fileds in Obj1, I want to copy same information in Obj2 also.
I have written a trigger but its not copying fileds.
Here is my code
trigger updateFilds on Obj1__c (after update,before insert) {

      
  List<Id> accountIds = new List<Id>();


for(Obj1__c acc: trigger.new){
        accountIds.add(acc.AccId__c);
        
    }
    
    List<Obj2__c> obj2Lst= [Select Id,F1__c ,F2__c ,F3__c,Account_Name__C FROM Obj2__c where Account_Name__C IN:accountIds];
   
    if(Trigger.isUpdate ){
   
    for(Obj1__c new2: trigger.new){
        if(!obj2Lst.isEmpty()){
            new2.F1__c       = obj2Lst[0].F1__c ;
            new2.F2__c       = obj2Lst[0].F2__c ;
            new2.F3__c       = obj2Lst[0].F3__c ;
            
        }
    }     
    }   

}

Please help where it is going wrong.
Thanks in Advance
Hi All,
I am getting error in test class as constructor not defined.
Here is my code
 
@isTest
public class myClass_Test
{
public static testMethod void testMethod() {
        account acc = new account();
        acc.Name = 'test account';
        acc.F1__c='test';
       
        insert acc ;
        contact con=new contact();
        con.LastName=acc.F1__c;
     
        Obj1__c o = new Obj1__c ();
        o.F1__c = acc.Id;
        o.F2__c= con.LastName;
        
        
        insert o;
        
        
    PageReference myPage = Page.myPage;
    myPage.getParameters().put('id', o.Id);  
    Test.setCurrentPage(myPage);    
    ApexPages.StandardSetController control = new ApexPages.StandardSetcontroller(o);
    myClass pageControl = new myClass(control); 
     pageControl.bumpCases();
     pageControl.updateCases();   
     
    }

}
Controller Class
public with sharing class myClass 
{
    private ApexPages.StandardSetController standardController;

    public myClass(ApexPages.StandardSetController standardController)
    {
        this.standardController = standardController;
    }

    public PageReference bumpCases()
    {       
        // Get the selected records (optional, you can use getSelected to obtain ID's and do your own SOQL)
        List<Obj1__c> selectedCases = (List<Obj1__c>) standardController.getSelected();

        // Update records       
        for(obj1__c selectedCase : selectedCases)
        {
            if(selectedCase.status__c == 'Saved') 
                selectedCase.status__c = 'Cancelled';
            
        }       

        return null;        
    }

    public PageReference updateCases()
    {       
        // Call StandardSetController 'save' method to update (optional, you can use your own DML)
        return standardController.save();   
    }
}
Visualforce page
<apex:page standardController="obj1__c" extensions="myController" recordSetVar="Items" action="{!bumpCases}">
   <apex:form >
       <apex:pageBlock title="Bump Selected Items">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!updateCases}" value="Confirm"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!selected}" var="o">
                <apex:column value="{!o.status__c}"/>
                
            </apex:pageBlockTable> 
        </apex:pageBlock>
    </apex:form>    
</apex:page>

Please help me in this error
What change I need to do
Thanks in Advance
 
Hi All,
I am getting error in test class as constructor not defined.
Here is my code
@isTest
public class myClass_Test
{
public static testMethod void testMethod() {
        account acc = new account();
        acc.Name = 'test account';
        acc.F1__c='test';
       
        insert acc ;
        contact con=new contact();
        con.LastName=acc.F1__c;
     
        Obj1__c o = new Obj1__c ();
        o.F1__c = acc.Id;
        o.F2__c= con.LastName;
        
        
        insert o;
        
        
    PageReference myPage = Page.myPage;
    myPage.getParameters().put('id', o.Id);  
    Test.setCurrentPage(myPage);    
    ApexPages.StandardController control = new ApexPages.Standardcontroller(o);
    myClass pageControl = new myClass(control); 
     pageControl.bumpCases();
     pageControl.updateCases();   
     
    }

}

Controller
public with sharing class myClass 
{
    private ApexPages.StandardSetController standardController;

    public myClass(ApexPages.StandardSetController standardController)
    {
        this.standardController = standardController;
    }

    public PageReference bumpCases()
    {       
        // Get the selected records (optional, you can use getSelected to obtain ID's and do your own SOQL)
        List<Obj1__c> selectedCases = (List<Obj1__c>) standardController.getSelected();

        // Update records       
        for(obj1__c selectedCase : selectedCases)
        {
            if(selectedCase.status__c == 'Saved') 
                selectedCase.status__c = 'Cancelled';
            
        }       

        return null;        
    }

    public PageReference updateCases()
    {       
        // Call StandardSetController 'save' method to update (optional, you can use your own DML)
        return standardController.save();   
    }
}

Visualforce Page
<apex:page standardController="obj1__c" extensions="myController" recordSetVar="Items" action="{!bumpCases}">
   <apex:form >
       <apex:pageBlock title="Bump Selected Items">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!updateCases}" value="Confirm"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!selected}" var="o">
                <apex:column value="{!o.status__c}"/>
               
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>   
</apex:page>

Please help me in this error
What change I need to do
Thanks in Advance
Hi All,
I am new to salesforce.
I have created a custom button in visualforce page to change status field.
I have written visualforce page and controller class for the same.
I want to write test class for the same class.

Here is my code
 
public with sharing class changeStstus {

    Public id lid;
     Public Order lRec;
     Public string strRs{get;set;}  
     public string strSt{get;set;}
    
    public changeStstus(ApexPages.StandardController controller) {
        
        if(ApexPages.currentPage().getParameters().get('id') != null) {      
              lid= ApexPages.currentPage().getParameters().get('id');
            getRecord(lid);     
        }
      }
    
    public void getRecord(ID lid){
       lRec = [select id,F1__c,status from Order where id =:lid];
       strRs = lRec.F1__c;
       strSt='Saved';
      }
    
    public PageReference  Save(){
        lRec.F1__c = strRs;
        lRec.status= strSt;
        lRec lRec;  
        PageReference ReturnPage = new PageReference('/' + lRec.id); 
        ReturnPage.setRedirect(true); 
        return ReturnPage;
    }
   
    public PageReference  Cancel(){
        PageReference ReturnPage = new PageReference('/' + lRec.id); 
        ReturnPage.setRedirect(true); 
        return ReturnPage;  
    }

}

Please help me
Thanks in Advance
Hi All,
I am new to salesforce.
I have created a custom button in visualforce page to change status field.
I have written visualforce page and controller class for the same.
I want to write test class for the same class.

Here is my code
 
public with sharing class changeStstus {

    Public id lid;
     Public Order lRec;
     Public string strRs{get;set;}  
     public string strSt{get;set;}
    
    public changeStstus(ApexPages.StandardController controller) {
        
        if(ApexPages.currentPage().getParameters().get('id') != null) {      
              lid= ApexPages.currentPage().getParameters().get('id');
            getRecord(lid);     
        }
      }
    
    public void getRecord(ID lid){
       lRec = [select id,F1__c,status from Order where id =:lid];
       strRs = lRec.F1__c;
       strSt='Saved';
      }
    
    public PageReference  Save(){
        lRec.F1__c = strRs;
        lRec.status= strSt;
        lRec lRec;  
        PageReference ReturnPage = new PageReference('/' + lRec.id); 
        ReturnPage.setRedirect(true); 
        return ReturnPage;
    }
   
    public PageReference  Cancel(){
        PageReference ReturnPage = new PageReference('/' + lRec.id); 
        ReturnPage.setRedirect(true); 
        return ReturnPage;  
    }

}

Please help me

Thanks in Advance
Hi All,
I am new to salesforce.
I have custom button on account page that is get contact.
When I click on 'get contact', I want to get conatct record from contact object of the same account. (I have only one contact for each account).
How can I do this?

Please help me.

Thanks in Advance!
Hi All,
I am new to Salesforce.
I have written a batch apex to delete records and send a csv file to some email id.
I want to write test class for the same. Her is my code.
Batch Apex:
global class Del_leads implements Database.Batchable<sobject>
{  
       
   Public String s;
   public integer j; 
   Public string k='\n'+'IDName'+','+'CreatedDate';  
   Custom_Setting1__c mc=Custom_Setting1__c.getInstance('days');
   String dy=mc.day__c;
   global Database.QueryLocator start(Database.BatchableContext BC){
      
      return Database.getQueryLocator([SELECT Id,Subject FROM lead where createdData=:Today.addDays-(dy)]);     
   }
   
global void execute(Database.BatchableContext BC,List<Task> Lds){     
  
    s +=k+'\n'+ lds[j].Id+','+lds[j].CreatedDate;
          
  Blob b=Blob.valueOf(s);
  Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
  efa.setFileName(m+'attachment.csv');
  efa.setBody(b);
        
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
  mail.setToAddresses(new String[] {abc@test.com'});        
  mail.setSenderDisplayName('Batch Processing');
  mail.setSubject('Batch Process Completed');
  mail.setPlainTextBody('Please find the attachment of deleted records');
  mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});     
  Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });       
  delete Lds;           

}  
   
global void finish(Database.BatchableContext BC){     
  System.debug(LoggingLevel.WARN,'Deleting Leads Finished');
}

}
Test Class:
@isTest 
public class Del_leadsTest 
{
    static testMethod void testMethod1() 
	{
	
		Lead newLead = new Lead(firstName = 'Cole', lastName = 'Swain', company = 'BlueWave', status = 'contacted' ) ;
		insert 	newLead;
		
		Test.startTest();

			Del_leads obj = new Del_leads();
			obj.j=0;
			DataBase.executeBatch(obj);

		Test.stopTest();
		
	}
}

This test class is failing while running. Error is getting at custom setting line.
Please help me in writing test class for this.
Thanks in Advance
Hi All,
I am new to Salesforce.
I have written a batch apex to delete records and send a csv file to some email id.
I want to write test class for the same. Her is my code.
trigger TaskUpdate on Task (after update) {
  List<Id> Ids=new List<Id>();
    for(Task t:trigger.new)
         {
        if(String.valueOf(t.whatId).startsWith('001')==TRUE)
          {
            Ids.add(t.whatId);
           }
      
         }
Map<Id,contact>  con = new Map<Id,contact>([SELECT Id, P1__c,p2__c,P3__c,AccountId FROM contact WHERE Contact.AccountId IN:Ids]);        
    For(Task t2 : trigger.new)
    {
        if(con.get(t2.whoid) != null)
        {  
           con.get(t2.whoid).P1__c = t2.P1__c ;
           con.get(t2.whoid).p2__c = t2.p2__c ;
           con.get(t2.whoid).P3__c = t2.P3__c ;
           con.get(t2.whoid).P4__c= t2.P4__c;
           con.get(t2.whoid).P5__c= t2.P5__c;
           con.get(t2.whoid).P6__c= t2.P6__c;
           con.get(t2.whoid).P7__c= t2.P7__c;
           con.get(t2.whoid).P8__c__c= t2.P8__c;
           
          }

    }
       update con.values();                     
}

Please help me
Thanks in Advance
Hi All,
I am new to Salesforce.
I have written a batch apex to delete records and send a csv file to some email id.
I want to write test class for the same. Her is my code.
global class Del_leads implements Database.Batchable<sobject>
{  
       
   Public String s;
   public integer j; 
   Public string k='\n'+'IDName'+','+'CreatedDate';  
   
   
   global Database.QueryLocator start(Database.BatchableContext BC){
      
      return Database.getQueryLocator([SELECT Id,Subject FROM lead]);     
   }
   
global void execute(Database.BatchableContext BC,List<Task> Lds){     
  
    s +=k+'\n'+ lds[j].Id+','+lds[j].CreatedDate;
          
  Blob b=Blob.valueOf(s);
  Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
  efa.setFileName(m+'attachment.csv');
  efa.setBody(b);
        
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
  mail.setToAddresses(new String[] {abc@test.com'});        
  mail.setSenderDisplayName('Batch Processing');
  mail.setSubject('Batch Process Completed');
  mail.setPlainTextBody('Please find the attachment of deleted records');
  mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});     
  Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });       
  delete Lds;           

}  
   
global void finish(Database.BatchableContext BC){     
  System.debug(LoggingLevel.WARN,'Deleting Leads Finished');
}

}

Please help me
Thanks in Advance
Hi All,
I am new to Salesforce.
I have written a batch apex to delete records and send a csv file to some email id.
I want to write test class for the same. Here is my code
global class Del_leads implements Database.Batchable<sobject>
{  
       
   Public String s;
   public integer j; 
   Public string k='\n'+'IDName'+','+'CreatedDate';  
   
   
   global Database.QueryLocator start(Database.BatchableContext BC){
      
      return Database.getQueryLocator([SELECT Id,Subject FROM lead]);     
   }
   
global void execute(Database.BatchableContext BC,List<Task> Lds){     
  
    s +=k+'\n'+ lds[j].Id+','+lds[j].CreatedDate;
          
  Blob b=Blob.valueOf(s);
  Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
  efa.setFileName(m+'attachment.csv');
  efa.setBody(b);
        
  Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
  mail.setToAddresses(new String[] {abc@test.com'});        
  mail.setSenderDisplayName('Batch Processing');
  mail.setSubject('Batch Process Completed');
  mail.setPlainTextBody('Please find the attachment of deleted records');
  mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});     
  Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });       
  delete Lds;           

}  
   
global void finish(Database.BatchableContext BC){     
  System.debug(LoggingLevel.WARN,'Deleting Leads Finished');
}

}

Please help me
Thanks in Advance
Hi All,
I am new to Salesforce.
I have written a trigger on task to update contact record.
I want to write test class for the same. Here is my code.
trigger TaskUpdate on Task (after update) {
  List<Id> Ids=new List<Id>();
    for(Task t:trigger.new)
         {
        if(String.valueOf(t.whatId).startsWith('001')==TRUE)
          {
            Ids.add(t.whatId);
           }
      
         }
Map<Id,contact>  con = new Map<Id,contact>([SELECT Id, P1__c,p2__c,P3__c,AccountId FROM contact WHERE Contact.AccountId IN:Ids]);        
    For(Task t2 : trigger.new)
    {
        if(con.get(t2.whoid) != null)
        {  
           con.get(t2.whoid).P1__c = t2.P1__c ;
           con.get(t2.whoid).p2__c = t2.p2__c ;
           con.get(t2.whoid).P3__c = t2.P3__c ;
           con.get(t2.whoid).P4__c= t2.P4__c;
           con.get(t2.whoid).P5__c= t2.P5__c;
           con.get(t2.whoid).P6__c= t2.P6__c;
           con.get(t2.whoid).P7__c= t2.P7__c;
           con.get(t2.whoid).P8__c__c= t2.P8__c;
           
          }

    }
       update con.values();                     
}

Please help me to write test class for the above code.

Thanks in Advance
Hi All,
I am new to Salesforce.
I have written a contact trigger.
I have three pin codenumber fileds (P1__c,P2__c,P3__c) in Contact and I have three status pick list (St1__c,St2__c,St3__c) values for all three fields.
When ever user is updating new number in pin code numbers, I am updating all status values to none.
I want to write test class for the same. Here is my code
trigger statusChnageOnUpdate on Contact ( before update) {
    
    For (Contact c : Trigger.New) {
       for(Contact cOld :Trigger.old){
        if(c.P1__c != cOld.P1__c || c.P2__c != cOld.P2__c || c.P3__c != cOld.P3__c  ) { 
             c.St1__c = null;
             c.St2__c = null;
             c.St3__c = null;
            
          }
       }

    }
}

Please help me.
Thanks in Advance
Hi All,
I have one custom object. When ever I created a record in this object, I want to send it to a queue for approval.
When it is approved by that queue user, I want to send it to another queue and want to get it approve.

How can I do this?
Please help me

Thanks in Advance.
Hi All,
I am creating a task using batch apex. Through batch apex I am inserting 50% data into Task (From Custom object1).
Remaining data I have in Custom Object2.
I want to get that data by using Trigger
I want to compare Account Id of Task with Custom Object 2(I have Lookup to Account in Custom Object2).
Can I do this by using Trigger?
Now, on which object I have to trigger and how syntax should be?

Thanks in Advance
Hi All,
I have written a batch apex to insert records.
I have written a test class for the same. But some lines are not covering.
Please help me cover those lines.
Here is my code
global class batchInsert Implements Schedulable, Database.Batchable<sObject>{
global void execute(SchedulableContext sc) {
    Database.executeBatch(this);
}

global database.queryLocator start(Database.BatchableContext BC) {
    
    Date d = System.today(); 
    Datetime dt = (DateTime)d; 
    String dayOfWeek = dt.format('EEEE');
   
    if (dayOfWeek == 'Monday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Monday__c='Yes']);
    else if (dayOfWeek == 'Tuesday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Tuesday__c='Yes']);
    else if (dayOfWeek == 'Wednesday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Wednesday__c='Yes']);
    else if (dayOfWeek == 'Thursday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Thursday__c='Yes']);
    else if (dayOfWeek == 'Friday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Friday__c='Yes']);
    else if (dayOfWeek == 'Saturday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Saturday__c='Yes']);
    else 
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Sunday__c='Yes']);
    

} 

global void execute(Database.BatchableContext BC, list <Obj1__c> scope) {

    List <Obj2__c> creList = new List<Obj2__c>();
    Date d = System.today(); 
    Datetime dt = (DateTime)d; 
    String dayIs = dt.format('EEEE');
 
    
    for(Obj1__c c : scope) {
            Obj2__c obj             = new Obj2__c();
        
           
            
            obj.F1__c=c.F1__c;
            obj.F2__c=c.F2__c;
           
            if(dayIs=='Monday' && c.Monday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Monday' &&c.Monday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Tuesday' &&c.Tuesday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Tuesday' &&c.Tuesday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Wednesday' &&c.Wednesday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Wednesday' &&c.Wednesday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Thursday' &&c.Thursday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Thursday' &&c.Thursday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Friday' &&c.Friday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Friday' &&c.Friday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Saturday' &&c.Saturday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Saturday' &&c.Saturday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Sunday' &&c.Sunday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Sunday' &&c.Sunday__c == 'No'){
            obj.F3__c='No';
            }
           
           creList.add(obj);
    } 

    
        insert creList;
     
} 

global void finish(Database.BatchableContext BC) {


} 
}
Test Class:
@isTest(seealldata=true)
public class  testSendeBatch
{

Public static testMethod void method3()
{ 

Obj1__c cp=new Obj1__c();
cp.F1__c='Test';
cp.F2__c='Test2';

batchInsert sb=new batchInsert();
     
        Test.startTest();
        Database.executeBatch(sb);
        Test.stopTest();
       
    }
 
 
  }
I am not able to cover lines between Line number 12 to 25 and Line number 46 to 87.
Please help me how to cover these lines.
Thanks in Advance

 
Hi All,
I have written a batch apex to insert records.
I have written a test class for the same. But some lines are not covering.
Please help me cover those lines.
Here is my code
global class batchInsert Implements Schedulable, Database.Batchable<sObject>{
global void execute(SchedulableContext sc) {
    Database.executeBatch(this);
}

global database.queryLocator start(Database.BatchableContext BC) {
    
    Date d = System.today(); 
    Datetime dt = (DateTime)d; 
    String dayOfWeek = dt.format('EEEE');
   
    if (dayOfWeek == 'Monday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Monday__c='Yes']);
    else if (dayOfWeek == 'Tuesday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Tuesday__c='Yes']);
    else if (dayOfWeek == 'Wednesday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Wednesday__c='Yes']);
    else if (dayOfWeek == 'Thursday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Thursday__c='Yes']);
    else if (dayOfWeek == 'Friday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Friday__c='Yes']);
    else if (dayOfWeek == 'Saturday')
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Saturday__c='Yes']);
    else 
        return database.getQueryLocator([SELECT Id,F1__c,F2__c from Obj1__c where Sunday__c='Yes']);
    

} 

global void execute(Database.BatchableContext BC, list <Obj1__c> scope) {

    List <Obj2__c> creList = new List<Obj2__c>();
    Date d = System.today(); 
    Datetime dt = (DateTime)d; 
    String dayIs = dt.format('EEEE');
 
    
    for(Obj1__c c : scope) {
            Obj2__c obj             = new Obj2__c();
        
           
            
            obj.F1__c=c.F1__c;
            obj.F2__c=c.F2__c;
           
            if(dayIs=='Monday' && c.Monday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Monday' &&c.Monday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Tuesday' &&c.Tuesday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Tuesday' &&c.Tuesday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Wednesday' &&c.Wednesday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Wednesday' &&c.Wednesday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Thursday' &&c.Thursday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Thursday' &&c.Thursday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Friday' &&c.Friday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Friday' &&c.Friday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Saturday' &&c.Saturday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Saturday' &&c.Saturday__c == 'No'){
            obj.F3__c='No';
            }
            else if(dayIs=='Sunday' &&c.Sunday__c == 'Yes'){
            obj.F3__c='Yes';
            }
            else if(dayIs=='Sunday' &&c.Sunday__c == 'No'){
            obj.F3__c='No';
            }
           
           creList.add(obj);
    } 

    
        insert creList;
     
} 

global void finish(Database.BatchableContext BC) {


} 
}

Test class
@isTest(seealldata=true)
public class  testSendeBatch
{

Public static testMethod void method3()
{ 

Obj1__c cp=new Obj1__c();
cp.F1__c='Test';
cp.F2__c='Test2';

batchInsert sb=new batchInsert();
     
        Test.startTest();
        Database.executeBatch(sb);
        Test.stopTest();
       
    }
 
 
  }
I am not able to cover lines between Line number 12 to 25 and Line number 46 to 87.
Please help me how to cover these lines.
Thanks in Advance
 
Hi All,
I have written a trigger on Order.
I am giving errors in two scenarios. I have one custom field Blocked__c in account. If I have blocked__c = Y, I dont want to create order.
This condition is not working properly.
This is my code. Please tell me where is bug
trigger orderTrigger on Order (before insert) {

List<Order> ordLs = [Select Id, F1__c,Status,AccountId,Account.Blocked__c from Order where createdDate=today ];  

for (Order ordNew : Trigger.new)
  {      
    for(Order oa: ordLs)
        {         
               if(oa.AccountId == ordNew.AccountId && oa.F1__c == ordNew.F1__c && oa.status == 'confirmed')         
                  {              
                    ordNew.AccountId.addError('Some messge');        
                  } 
               if(oa.Account.Blocked__c=='Y') {
                   ordNew.AccountId.addError('Blocked'); 
               } 
         }
        
  }

}

Please help me.
Line Number 13 is not working properly. Please suggest me changes.
Thanks in Advance
Hi All,
I am getting error in test class as constructor not defined.
Here is my code
 
@isTest
public class myClass_Test
{
public static testMethod void testMethod() {
        account acc = new account();
        acc.Name = 'test account';
        acc.F1__c='test';
       
        insert acc ;
        contact con=new contact();
        con.LastName=acc.F1__c;
     
        Obj1__c o = new Obj1__c ();
        o.F1__c = acc.Id;
        o.F2__c= con.LastName;
        
        
        insert o;
        
        
    PageReference myPage = Page.myPage;
    myPage.getParameters().put('id', o.Id);  
    Test.setCurrentPage(myPage);    
    ApexPages.StandardSetController control = new ApexPages.StandardSetcontroller(o);
    myClass pageControl = new myClass(control); 
     pageControl.bumpCases();
     pageControl.updateCases();   
     
    }

}
Controller Class
public with sharing class myClass 
{
    private ApexPages.StandardSetController standardController;

    public myClass(ApexPages.StandardSetController standardController)
    {
        this.standardController = standardController;
    }

    public PageReference bumpCases()
    {       
        // Get the selected records (optional, you can use getSelected to obtain ID's and do your own SOQL)
        List<Obj1__c> selectedCases = (List<Obj1__c>) standardController.getSelected();

        // Update records       
        for(obj1__c selectedCase : selectedCases)
        {
            if(selectedCase.status__c == 'Saved') 
                selectedCase.status__c = 'Cancelled';
            
        }       

        return null;        
    }

    public PageReference updateCases()
    {       
        // Call StandardSetController 'save' method to update (optional, you can use your own DML)
        return standardController.save();   
    }
}
Visualforce page
<apex:page standardController="obj1__c" extensions="myController" recordSetVar="Items" action="{!bumpCases}">
   <apex:form >
       <apex:pageBlock title="Bump Selected Items">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!updateCases}" value="Confirm"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!selected}" var="o">
                <apex:column value="{!o.status__c}"/>
                
            </apex:pageBlockTable> 
        </apex:pageBlock>
    </apex:form>    
</apex:page>

Please help me in this error
What change I need to do
Thanks in Advance
 
Hi All,
I am getting error in test class as constructor not defined.
Here is my code
@isTest
public class myClass_Test
{
public static testMethod void testMethod() {
        account acc = new account();
        acc.Name = 'test account';
        acc.F1__c='test';
       
        insert acc ;
        contact con=new contact();
        con.LastName=acc.F1__c;
     
        Obj1__c o = new Obj1__c ();
        o.F1__c = acc.Id;
        o.F2__c= con.LastName;
        
        
        insert o;
        
        
    PageReference myPage = Page.myPage;
    myPage.getParameters().put('id', o.Id);  
    Test.setCurrentPage(myPage);    
    ApexPages.StandardController control = new ApexPages.Standardcontroller(o);
    myClass pageControl = new myClass(control); 
     pageControl.bumpCases();
     pageControl.updateCases();   
     
    }

}

Controller
public with sharing class myClass 
{
    private ApexPages.StandardSetController standardController;

    public myClass(ApexPages.StandardSetController standardController)
    {
        this.standardController = standardController;
    }

    public PageReference bumpCases()
    {       
        // Get the selected records (optional, you can use getSelected to obtain ID's and do your own SOQL)
        List<Obj1__c> selectedCases = (List<Obj1__c>) standardController.getSelected();

        // Update records       
        for(obj1__c selectedCase : selectedCases)
        {
            if(selectedCase.status__c == 'Saved') 
                selectedCase.status__c = 'Cancelled';
            
        }       

        return null;        
    }

    public PageReference updateCases()
    {       
        // Call StandardSetController 'save' method to update (optional, you can use your own DML)
        return standardController.save();   
    }
}

Visualforce Page
<apex:page standardController="obj1__c" extensions="myController" recordSetVar="Items" action="{!bumpCases}">
   <apex:form >
       <apex:pageBlock title="Bump Selected Items">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!updateCases}" value="Confirm"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!selected}" var="o">
                <apex:column value="{!o.status__c}"/>
               
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>   
</apex:page>

Please help me in this error
What change I need to do
Thanks in Advance
Hi All,
I am new to salesforce.
I have created a custom button in visualforce page to change status field.
I have written visualforce page and controller class for the same.
I want to write test class for the same class.

Here is my code
 
public with sharing class changeStstus {

    Public id lid;
     Public Order lRec;
     Public string strRs{get;set;}  
     public string strSt{get;set;}
    
    public changeStstus(ApexPages.StandardController controller) {
        
        if(ApexPages.currentPage().getParameters().get('id') != null) {      
              lid= ApexPages.currentPage().getParameters().get('id');
            getRecord(lid);     
        }
      }
    
    public void getRecord(ID lid){
       lRec = [select id,F1__c,status from Order where id =:lid];
       strRs = lRec.F1__c;
       strSt='Saved';
      }
    
    public PageReference  Save(){
        lRec.F1__c = strRs;
        lRec.status= strSt;
        lRec lRec;  
        PageReference ReturnPage = new PageReference('/' + lRec.id); 
        ReturnPage.setRedirect(true); 
        return ReturnPage;
    }
   
    public PageReference  Cancel(){
        PageReference ReturnPage = new PageReference('/' + lRec.id); 
        ReturnPage.setRedirect(true); 
        return ReturnPage;  
    }

}

Please help me
Thanks in Advance
Hi All,
I am new to salesforce.
I have custom button on account page that is get contact.
When I click on 'get contact', I want to get conatct record from contact object of the same account. (I have only one contact for each account).
How can I do this?

Please help me.

Thanks in Advance!
Hi All,
I am new to Salesforce.
I have written a contact trigger.
I have three pin codenumber fileds (P1__c,P2__c,P3__c) in Contact and I have three status pick list (St1__c,St2__c,St3__c) values for all three fields.
When ever user is updating new number in pin code numbers, I am updating all status values to none.
I want to write test class for the same. Here is my code
trigger statusChnageOnUpdate on Contact ( before update) {
    
    For (Contact c : Trigger.New) {
       for(Contact cOld :Trigger.old){
        if(c.P1__c != cOld.P1__c || c.P2__c != cOld.P2__c || c.P3__c != cOld.P3__c  ) { 
             c.St1__c = null;
             c.St2__c = null;
             c.St3__c = null;
            
          }
       }

    }
}

Please help me.
Thanks in Advance
Hi All,
I have three phone number fileds (P1__c,P2__c,P3__c) in Contact and I have three status pick list (St1__c,St2__c,St3__c) values for all three fields.
When ever user is updating new number in phone numbers, I want to update all three status pick list to None value.

How can I do this?
Please help me

Thanks in Advance
Hi All,
I have written a Trigger to update from Task to Contact,

This is my trigger
 
trigger updateTask on Task (after update) {
List<Id> tsIds = new List<Id>();

for(Task ts : trigger.new){
        tsIds.add(ts.WhoId);
     }
     
     
     Map<ID, Task> mapAccounts = new Map<ID, Task>([SELECT Id, F1__c from Task where Id IN :tsIds]);
     
     
     if(Trigger.isUpdate){

List<Contact>  lstCon = [SELECT Id, name, CF1__c,AccountId FROM Contact where AccountId IN :tsIds];

For(Contact con : lstCon)
  {
     Task ts = mapAccounts.get(con.AccountId);
          con.CF1__c= ts.F1__c;
          
     
  }
update lstCon;
}
}

When I am updating Task record I am getting System.NullPointerException: Attempt to de-reference a null object:​ error.
Please 
tell me what changes need to be don.

Thanks in Advance
Hi All,
I am new to Salesfroce.
I have written a batch apex to delete data from custom object.
Now, my requirement is to get that data from custom settings.

How to create that custom setting and what changes I have to do my below batch apex
global class batchDelete implements Database.Batchable<sobject>
{  
    
   
   global Database.QueryLocator start(Database.BatchableContext BC){
      
     return Database.getQueryLocator([SELECT Id,CreatedDate FROM Obj1__c WHERE createdDate = yesterday]);     
   }
   
global void execute(Database.BatchableContext BC,List<Obj1__c> rec){     
  //some code        
   
  delete rec;           

}  
   
global void finish(Database.BatchableContext BC){     
  
}

}

Please help me
Thanks in Advance!!
Hi All,
I have written batch apex to insert data in Task from two objects.
I am able to get data from Obj1__c. I am not able to get from Obj2__c
Here is my code.
 
global class batchTwo Implements Schedulable, Database.Batchable<sObject>{
global void execute(SchedulableContext sc) {
    Database.executeBatch(this);
}

global database.queryLocator start(Database.BatchableContext BC) {
    
    
        return database.getQueryLocator([SELECT Id,AccountId__c,F1__c,F2__c FROM Obj1__c]);
    
} 

global void execute(Database.BatchableContext BC, list <obj1__c> scope) {

    List <Task> taskList = new List<Task>();

   Map<Id, Obj2__c> mapObj2=new Map<Id, Obj2__c>([SELECT Account_Name__r.Id,Obj2_F2__c FROM Obj2__c]);
    
    for(Obj1__c c : scope) {
            Task tsk             = new Task();
            if(mapObj2.containsKey(c.AccountId__c)) {
             Obj2__c tmpSales = mapObj2.get(c.AccountId__c);
            
             tsk.F1__c=tmpSales.Obj2_F2__c;
             
            }
            
            tsk.WhatId           = c.AccountId__c;
            tsk.ActivityDate     = System.today();
            tsk.Status           = 'Open';
            tsk.Priority         = 'Normal';
            tsk.Subject          = 'call';
            tsk.P1__c=c.F1__c;
            tsk.P2__c=c.F2__c;
            
           taskList.add(tsk);
    } //close for-loop

   
        insert taskList;
    
       
    
} 

global void finish(Database.BatchableContext BC) {


} 
}

I am getting problem in Line no. 21 to 24.
Please suggest me what changes need to be done.
Please help me.
Thanks in Advance