I am having 2 objects case and object2. From case i am having lookup to object2. Both objects are having a common field picklist__C field
picklist__C field --> is having 3 values value1, value2 and value3.
If picklist__C field is updated then it must reflected on object2 also.
If picklist field in case is having value1 and now i changed to value2 it must reflect on object2 picklist__c field too.
trigger casetoupdate on Case (before update,after update) {
for(Case cs : Trigger.New) {
Case beforeUpdate = System.Trigger.oldMap.get(cs.Id);
System.Debug('previous invoice number is: ' + beforeUpdate.picklist__C);
List<object2__c> voc = [select id,name,picklist__c from object2__c where object2.Id =: cs.id ];
System.debug('@@@@voc '+voc );
// comparing new and previous values
if(cs.picklist__c != beforeUpdate.picklist__c) {
System.Debug('previous Apero Type is: ' + beforeUpdate.picklist__c);
System.Debug('current Apero Type is: ' + cs.picklist__c);
for(List<object2__c> listvouc : [Select id,picklist__c from object2__c where object2__c.Id =: cs.id ]){
}
}
}
I am new in writing triggers i in process to writing code as shown above but i am unable to write exact code to update records. please help me out.
DML
statement inside thefor loop
no no never!!!