function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Meenakshi T RMeenakshi T R 

Apex class Idea

I have an object Contract that has a look-up to another object Indexationtype. I have another object IndexationEntry that has master-detail to Indexationtype. Now I would like to get the value of the percentage field in the IndexationEntry onto Contract based on the yer fields. The year in the IndexationEntry matches Year in Contract. How should I achieve this?
CharuDuttCharuDutt
Hii Meenakshi
Try Below Code
trigger ContractTrigger on Contract (before Update) {
    Set<Id> setPAss = new set<Id>();
    for(Contract Cont :  trigger.new){
        if(Cont.Indexationtype__c != trigger.oldMap.get(Cont.Id).Indexationtype__c){
        setPAss.Add(Cont.Indexationtype__c);
        }
    }
	list<IndexationEntry__c>lstPass = [select Id,Indexationtype__c,CreatedDate 
                                       from IndexationEntry__c where Indexationtype__c In :setPAss];
    for(Contract Cont :  trigger.new){
        for(IndexationEntry__c oPass : lstPass){
            if(Cont.CreatedDate.Year() == oPass.CreatedDate.Year()){
                Cont.Description = 'Test'; 
            }
        }
    }
}
Please Mark It As Best Answer If It Helps
Thank You!