when Opportunint changing stage 5 to 6 it is check the status records if status is not have the record send error message to create a status record if record is available check the status1 is completed,if status is not completed give error message
trigger Checkingfulfillmentobjectstatus on Opportunity (after update) {
system.debug('9999999999999999999999999999999999999999999999999');
List<Opportunity> Oppfulfillment= new List<Opportunity>();
system.debug('9999999999999999999999999999999999999999999999999');
List<Opportunity> Oppfulfillment= new List<Opportunity>();
List<status__c> fulfillmentRecords=new List<status__c>();
if(Trigger.Isupdate){
for(opportunity newRecords:Trigger.new){
for(Opportunity oldRecords:Trigger.old){
system.debug('###################################'+oldRecords);
fulfillmentRecords=[select id,name,Status1__c from status__c where Opportunity__r.id =:oldRecords.id];
system.debug('List of Records in fulfillment object associated with opportunity @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+fulfillmentRecords);
if(fulfillmentRecords.size()>0){
if(oldRecords.stagename=='5' && newRecords.stagename=='6'){
for(status__c ffm:fulfillmentRecords){
if(ffm.Status1__c=='Completed'){
} else if(ffm.Status1__c=='In Progress'){
trigger.new.addError('status in Progress');
}
}// end of for loop checking the fulfilment object
}
} else{
Trigger.new.addError('Create New Record for status object');
}
}// End of Trigger.old
} //End of Trigger.new for loop
}// End of If IsUpdate
}
for(opportunity newRecords:Trigger.new){
for(Opportunity oldRecords:Trigger.old){
system.debug('###################################'+oldRecords);
fulfillmentRecords=[select id,name,Status1__c from status__c where Opportunity__r.id =:oldRecords.id];
system.debug('List of Records in fulfillment object associated with opportunity @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+fulfillmentRecords);
if(fulfillmentRecords.size()>0){
if(oldRecords.stagename=='5' && newRecords.stagename=='6'){
for(status__c ffm:fulfillmentRecords){
if(ffm.Status1__c=='Completed'){
} else if(ffm.Status1__c=='In Progress'){
trigger.new.addError('status in Progress');
}
}// end of for loop checking the fulfilment object
}
} else{
Trigger.new.addError('Create New Record for status object');
}
}// End of Trigger.old
} //End of Trigger.new for loop
}// End of If IsUpdate
}
No comments:
Post a Comment