+ Start a Discussion
Deepak Sharma 184Deepak Sharma 184 

trigger scenario- any help would be deeply appreciated.

I have a trigger scenerio- "hour rate" field in "project member" object should be updated as "hour cost" field in resource object only if there is some value in "hour cost" field otherwise if "hour cost" field is empty. then user would able to enter some value in "hour rate" field.

There are two objects called "Project Member" and "Resource"
In project member there is a look up field of currency data type " Resource", hence in which i can select resource for the "project member" object.

I have written the apex class for that, but dont know on which object have to write the trigger

public class updateHourlyRate {
    
    public static list<CloudbyzITPM__Team_Member__c> affectedRes = new list<CloudbyzITPM__Team_Member__c>();
    public static set<id> afc1 = new set<id>();
    public static void processAfterUpdateOrInsertHourlyRate()
    {
        affectedRes = (list<CloudbyzITPM__Team_Member__c>)Trigger.New;
        if(affectedRes.size()>0)
        {
            for(CloudbyzITPM__Team_Member__c aff1: affectedRes)
                afc1.add(aff1.CloudbyzITPM__Resource__c);
        }
    }
    
    CloudbyzITPM__Resource__c fn1 = [select id, CloudbyzITPM__Hourly_Cost__c from CloudbyzITPM__Resource__c where id in:afc1 limit 1];
    list<CloudbyzITPM__Team_Member__c> affectedRes1 = [select id, name,CloudbyzITPM__Resource__C,CloudbyzITPM__Hourly_Rate__c from CloudbyzITPM__Team_Member__c where CloudbyzITPM__Resource__c = :fn.Id];
    Decimal i=0;
    
    if(affectedRes1.size()>0)
    {
        for(CloudbyzITPM__Team_Member__c aff1: affectedRes1)
        {
            i = i + aff1.CloudbyzITPM__Hourly_Cost__c;
        }
    }
    
    if(i>0){
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Hourly_Rate__c = i;
    }
     update fn1; 
      System.debug('@@fn4@@'+fn);
    }
    
    }