I'm new to Apex and need a help regarding Triggers. I need to update a field(field__c) in custom object (obj1__c) (field of type checkbox) whenever a new record is created in case using email-to-case functionality. Please help me with the trigger Here is the trigger I have written. I didn't get any errors but the code is not working.
trigger CaseAfterInsert on Case (after insert) {
String contactID;
set<ID> obj1Id = new set<ID>();
list<obj1__c> test = new list<obj1__c>();
for(Case newCases : Trigger.new)
{
if(newCases.Subject.equalsIgnorecase('example'))
{
test.add(obj1__c);
}
}
test = [Select field__c from obj1__c where Contact__c =: contactID];
for(obj1__c test1 : test)
{
test1.field__c = false;
System.debug('list test --------------------'+test);
try {
update test1;
}
catch (Exception e)
{
System.debug('Exception occurred--------------'+e);
}
}
}