• David Silva
  • NEWBIE
  • 40 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 11
    Replies
Hi,
How to get the custom setting values in the apex code.
Hi,

I have to pass all the object in salesforce to the batch class for some activity.
How is it possible?
Regards,
 David.
 
global class DeleteJob implements Database.Batchable<sObject>{

   global final Integer noOfYears;
    sObject recordDeletionObject;

   global DeleteJob(sObject newobject,Integer noOfYears)
   {
      recordDeletionObject= newObject;
       this.noOfYears=noOfYears;
   }

   global Database.QueryLocator start(Database.BatchableContext BC)
   {
      return Database.getQueryLocator('hi');
   }

   global void execute(Database.BatchableContext BC, List<sObject> scope){
        Delete scope;
   }

   global void finish(Database.BatchableContext BC){
   }
}
Hi all,

How to pass an sObject and a criteria to the apex batch class ?
It is possible to do in the constructor of the class rt.
Hi,
I would like to know about the custom setting and is it possible to include the commom fields(CreatedByID
CreatedDate
LastModifiedbyID
Last ModifiedDate
) in all objects in the custom setting?
Is it possible to access the custom setting from the batch apex?
 
Hi

How to generate a batch class that is generic that
 can accept all the sObjects and some criteria?
Hi,

I have to delete records of all object (generic) in salesforce based on certain criteria.
I have to know the commom field in all the objects(Account,Contacts,lead etc and the Custom object)
 
Hi ,

Budget__c budg= new Budget__c(Name='Sales2',Initial_Amount__c = 50000,Valid_From__c='1/1/2016',Valid_To__c='12/1/2016',Description__c='Budget',
                                Type__c='Sales',Budget_Owner__c='David Silva',Total_Expenses__c= 0,Remaining_Amount__c=0);
   insert budg;
    
  Expense__c exp = new Expense__c(Name='Mar',Expense_id__c=257,Reason__c='Travel',Amount__c=200,Date__c='5/22/2016',
                                 Other_Expense__c='Certification',
                                  Status__c='Approved',Type__c='Sales',Budget.LookUP__c.Id=budg.Id);
        insert exp;


Error:

Invalid field initializer: Budget.LookUP__c.IdDisplay Error
Display Error

With Regards,
   Nisha
 
public class TotalExpenseComputation { 
   
   
 
    /*
     * The totalExpense method calculates the total of all the approved expenses as well as the amount left
     *
     * for both the marketing and sales budget.
     * */
public static void totalExpense(Expense__c[] expenses)
{
    //Query to get  Initial Amount,Total Expense and Remaining Amount field from respective budgets.
 
    List<Budget__c> typeList = new List<Budget__c>();
   
for(Budget__c[] b:[SELECT Name,Initial_Amount__c,Total_Expenses__c,Remaining_Amount__c,Type__c FROM Budget__c])
{
for(Expense__c exp:expenses)
    {
        if(exp.Type__c.equals('Marketing')&& exp.Budget_LookUp__c.equals(b.Name))
        {
             if(exp.Status__c.equals('Approved'))
             {
                
              b.Total_Expenses__c= exp.Amount__c+b.Total_Expenses__c;
               b.Remaining_Amount__c=b.Initial_Amount__c-b.Total_Expenses__c;
               typeList.add(b);
                
             }
              
        }
       
        if(exp.Type__c.equals('Sales')&& exp.Budget_LookUp__c.equals(b.Name))
        {
            if(exp.Status__c.equals('Approved'))
            {
              
                b.Total_Expenses__c  =exp.Amount__c+b.Total_Expenses__c;
                b.Remaining_Amount__c=b.Initial_Amount__c-b.Total_Expenses__c;
              typeList.add(b);
               
              }
        }
       
    }update typeList;}
   
 
Hi

How to generate a batch class that is generic that
 can accept all the sObjects and some criteria?
Hi,

I have to delete records of all object (generic) in salesforce based on certain criteria.
I have to know the commom field in all the objects(Account,Contacts,lead etc and the Custom object)
 
Hi ,

Budget__c budg= new Budget__c(Name='Sales2',Initial_Amount__c = 50000,Valid_From__c='1/1/2016',Valid_To__c='12/1/2016',Description__c='Budget',
                                Type__c='Sales',Budget_Owner__c='David Silva',Total_Expenses__c= 0,Remaining_Amount__c=0);
   insert budg;
    
  Expense__c exp = new Expense__c(Name='Mar',Expense_id__c=257,Reason__c='Travel',Amount__c=200,Date__c='5/22/2016',
                                 Other_Expense__c='Certification',
                                  Status__c='Approved',Type__c='Sales',Budget.LookUP__c.Id=budg.Id);
        insert exp;


Error:

Invalid field initializer: Budget.LookUP__c.IdDisplay Error
Display Error

With Regards,
   Nisha
 
public class TotalExpenseComputation { 
   
   
 
    /*
     * The totalExpense method calculates the total of all the approved expenses as well as the amount left
     *
     * for both the marketing and sales budget.
     * */
public static void totalExpense(Expense__c[] expenses)
{
    //Query to get  Initial Amount,Total Expense and Remaining Amount field from respective budgets.
 
    List<Budget__c> typeList = new List<Budget__c>();
   
for(Budget__c[] b:[SELECT Name,Initial_Amount__c,Total_Expenses__c,Remaining_Amount__c,Type__c FROM Budget__c])
{
for(Expense__c exp:expenses)
    {
        if(exp.Type__c.equals('Marketing')&& exp.Budget_LookUp__c.equals(b.Name))
        {
             if(exp.Status__c.equals('Approved'))
             {
                
              b.Total_Expenses__c= exp.Amount__c+b.Total_Expenses__c;
               b.Remaining_Amount__c=b.Initial_Amount__c-b.Total_Expenses__c;
               typeList.add(b);
                
             }
              
        }
       
        if(exp.Type__c.equals('Sales')&& exp.Budget_LookUp__c.equals(b.Name))
        {
            if(exp.Status__c.equals('Approved'))
            {
              
                b.Total_Expenses__c  =exp.Amount__c+b.Total_Expenses__c;
                b.Remaining_Amount__c=b.Initial_Amount__c-b.Total_Expenses__c;
              typeList.add(b);
               
              }
        }
       
    }update typeList;}