You need to sign in to do that
Don't have an account?
suji srinivasan
how to update same recordtype records in trigger ?
I have two records in same recordtype =compensation .in salary_detail__c object.
1.first record record_status__c = Active
2.Second record record_status__c =Inprogress
by updating second record recordstatus as active .it should update first record record status as inactive
trigger salarycredit on Salary_Detail__c (before update) {
Set<id> revisedid = new Set<id>();
Id c= Schema.SObjectType.Salary_Detail__c.getRecordTypeInfosByName().get('Compensation').getRecordTypeId();
List<Salary_Detail__c>tobeinactive =[select id, name ,Employee_Id__c,Employee_Information__c, record_status__c from Salary_Detail__c where record_status__c ='Active' AND RecordTypeId =:c AND ID NOT IN: revisedid ];
if (Trigger.isbefore && Trigger.isupdate) {
for (Salary_Detail__c s :trigger.new){
Salary_Detail__c oldsalary= Trigger.oldMap.get(s.ID);
//Salary_Detail__c newsalary= Trigger.newMap.get(s.ID);
if(oldsalary.Record_Status__c =='Inprogress' && oldsalary.Record_Status__c!=s.Record_Status__c && s.RecordTypeId == c){
revisedid.add(s.id);
system.debug('revisedid.........>'+revisedid);
for (Salary_Detail__c si :tobeinactive){
si.Record_Status__c ='Inactive';
}
}
}
}
Thanks in Advance
1.first record record_status__c = Active
2.Second record record_status__c =Inprogress
by updating second record recordstatus as active .it should update first record record status as inactive
trigger salarycredit on Salary_Detail__c (before update) {
Set<id> revisedid = new Set<id>();
Id c= Schema.SObjectType.Salary_Detail__c.getRecordTypeInfosByName().get('Compensation').getRecordTypeId();
List<Salary_Detail__c>tobeinactive =[select id, name ,Employee_Id__c,Employee_Information__c, record_status__c from Salary_Detail__c where record_status__c ='Active' AND RecordTypeId =:c AND ID NOT IN: revisedid ];
if (Trigger.isbefore && Trigger.isupdate) {
for (Salary_Detail__c s :trigger.new){
Salary_Detail__c oldsalary= Trigger.oldMap.get(s.ID);
//Salary_Detail__c newsalary= Trigger.newMap.get(s.ID);
if(oldsalary.Record_Status__c =='Inprogress' && oldsalary.Record_Status__c!=s.Record_Status__c && s.RecordTypeId == c){
revisedid.add(s.id);
system.debug('revisedid.........>'+revisedid);
for (Salary_Detail__c si :tobeinactive){
si.Record_Status__c ='Inactive';
}
}
}
}
Thanks in Advance
Can you explain more about your requirement?
Is salary_detail__c object linked to anyother object?
Thanks!!