You can't have two classes in the same file. Instead, you can write it like this:
global class batchELQA_Delete implements Database.Batchable<SObject>, Schedulable {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'Select Id FROM ELQA_Marketing_Activity__c WHERE CreatedDate < LAST_N_DAYS:180';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<SObject> scope) {
delete scope;
DataBase.emptyRecycleBin(scope);
}
global void finish(Database.BatchableContext BC){
}
global void execute(SchedulableContext sc) {
ID BatchId = Database.executeBatch(new batchELQA_Delete(), 2000);
}
Public static void SchedulerMethod() {
string con_exp= '0 0 1 * * ?';
System.schedule('batchELQA_Delete', con_exp, new batchELQA_Delete());
}
}
I am not sure if you know much about SQL, but triggers in SQL and Salesforce work similarly. As the name suggest, a trigger happens when it is "triggered" by something.
If you look in the trigger introductions for Salesforce (link here: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers.htm )
Quote from the page
"Apex triggers can be invoked through the use of triggers. A trigger is Apex code that executes before or after the following types of operations:
insert
update
delete
merge
upsert
undelete"
So then a basic trigger should firstly give the instruction of on what object this trigger respond from, and before or after what kind of event.
EG:
below is a trigger I wrote to update a Monthly Target custom field when a Target Value custom object has a new record created/inserted or updated.
The first line, as you can see, starts with trigger, which states that this is a trigger, and then the name of the trigger (I call it UpdateAccountMonthlyTarget - you name yours whatever you like).
Then I state on which object will trigger the trigger. In this case, the two relevant objects are Account and the custom object Target Value. As I stated before, I wanted the trigger to occur when the target value is inserted or updated, so I say on "Target_value__c", using the API name of the custom object. Lastly, as you can see, I state "After insert, After update" because I am stating WHEN I want the trigger to happen.
trigger UpdateAccountMonthlyTarget on Target_Value__c (after insert, after update) {
// create a collection of accounts for saving new Monthly Targets
List accountlist = new List();
//create month and year variables
Date thisDay = Date.today();
Integer Month = thisDay.month();
Integer Year = thisDay.year();
// iterate through new Target_Value record created
for (Target_Value__c tv : trigger.new) {
if ((tv.Year__c==thisDay.year()) && (tv.Month__c==thisDay.month())) {
Account acc = new Account (id = tv.Related_Account__c, Monthly_Target__c =
tv.Current_Month_Target__c);
accountlist.add(acc);
}
}
update accountlist;
}
There is a lot more to triggers, but this, and the link above, hopefully will give you a start to think about how to do this. Another website I recommend, and this guy has done some excellent job on teaching people about triggers, is http://www.sfdc99.com
One other place to start is Salesforce's own tutorial:
https://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_qs_trigger.htm|StartTopic=Content%2Fapex_qs_trigger.htm|SkinName=webhelp
I hope these will start you off on the right track.
i am a beginner as well, still learning Apex myself
Best Answer
"List" is a reserved keyword and hence it cant be used as a variable name .You can change the name and should work