• Deepak Sharma 184
  • NEWBIE
  • 95 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 26
    Questions
  • 38
    Replies
Hi,

I have stored the html page in static resource and showing it via lightning component. how to cover the static resource test class?

Apex code - 
@auraEnabled
public static string getFooterContent(String staticResourceName) {
   
    Blob bodydata =  [SELECT Body FROM  StaticResource  WHERE Name = :staticResourceName].Body;
    String s = bodydata.toString();
    
    return s;
}
Hi Devs,
 I have a scnerio in which i have to give "edit" access to the Account team member. If they are converting a lead into an existing account then for that existing account's team member should have a 'Edit' access so that they can convert a lead. So how can i achieve this through trigger. Any Help with the Sample code would be appreciated. 

Thanks.
 
HI Devs,

In opportunity, if i want to create a task on opportunity then it will ask for the Record types in classic which is as per the business process. Currenty i have seven Record types. But when i switching to lightning, it does not ask for the record types. Hence as per the businness, it should ask for which Record Types we can create a task. Anybody can help me on this. 

Thanks & Regards,
​Deepak
Hi Expert,

I have a VF page in which there is a block 'Project Team', in this block we are displaying the record 'resourse full name',when there is no record there, table gets shrinked, hence i want to put N/A there when there is no record. but 'resource full name' is a formula field. How to put N/A there. 

VF Page - 

     <div class="main_container" style="margin-top:10px">
            <div class="animated flipInY col-lg-5 col-md-80 col-sm-80 col-xs-80">
                <div class="tile-stats">
                    <apex:outputLabel value="Deliverables/Objectives" style="color:#0A31FB;" />
                    <apex:panelGrid columns="1" border="0" style="border:hidden">

                        <!--apex:outputLabel value="Project:" style="border-hidden" />-->
                        <apex:outputText value="{!CloudbyzITPM__Project__c.CloudbyzITPM__Project_Goal__c}"
                            style="border-hidden"/>
                    
                    <!--apex:panelGrid columns="1" columnClasses="col1,col2" border="1" style="border:solid"
                        cellpadding="3">-->
                        <!--apex:outputLabel value="Description:" style="text-align:left;border-hidden" />-->
                        <apex:outputText value="{!CloudbyzITPM__Project__c.CloudbyzITPM__Description__c}"
                            style="white-space:pre-wrap;border-hidden"/>
                    </apex:panelGrid>
                </div>
            </div>
        </div>

Controller:- 
    
   
 List< CloudbyzITPM__Team_Member__c> tempTMlist =[select Id,CloudbyzITPM__Resource_Full_Name__c from CloudbyzITPM__Team_Member__c where CloudbyzITPM__Project__r.Id =: recordId];
    
     public List<CloudbyzITPM__Team_Member__c> gettempTMlist()
     
     {
     if(tempTMlist.size() < 3 ){
     for(integer i = 0; i <= (3 - tempTMlist.size());){
         
          tempTMlist.add(new CloudbyzITPM__Team_Member__c(CloudbyzITPM__Resource_Full_Name__c = null));
     }
     }    
         return tempTMlist;
    }








 
Hi,

I have a visual force page as shown below in which 'more' is redirect the user to details page of records. but for the block 'Task completed last week' more button is not working, for others it is working fine. any body can help

below is my vf page and controller:-


        <div class="main_container" style="margin-top:10px">
            <div class = "height:50%">
                <div class="animated flipInY col-lg-4 col-md-80 col-sm-80 col-xs-80">
                    <div class="tile-stats">
                        <div style="text-align:center">
                            <apex:outputLabel value="Task Completed Last Week" style="color:#0A31FB;" />
                        </div>
                        <apex:pageBlock >
                         
                            <apex:pageBlockTable value="{!rows}" var="tc" rows="3" rendered="{!rows.size>0}">
                                  
                                <apex:column >

                                    <a href= "/{!tc.id}">
                                    <!--apex:outputLink value="{!URLFOR($Action.CloudbyzITPM__Task__c.View, tc.id)}" styleClass="leftAlign" >-->{!tc.Name}</a>
                                    <!--/apex:outputLink>-->
                            
                                </apex:column>
                              
                            </apex:pageBlockTable>
                            <!-- <apex:repeat>
                                 dsd
                            <apex:outputText value="There are no tasks to display." style="white-space:pre-wrap;border-hidden" />
                            </apex:repeat>-->

                        </apex:pageBlock>
                        <apex:commandButton styleClass="div5" value="more" action="{!redirecttoprjtskcom}"
                        />
                    </div>
            </div>
            </div>
            </div>
   




        <div class="main_container" style="margin-top:10px">
                <div class="animated flipInY col-lg-4 col-md-2 col-sm-6 col-xs-12">
                    <div class="tile-stats">
                        <div style="text-align:center">
                            <apex:outputLabel value="Task In Progress" style="color:#0A31FB;" />
                        </div>
                        <apex:pageBlock >
                            <apex:pageBlockTable value="{!taskname}" var="t" rows="3" rendered="{!taskname.size>0}">
                                <apex:column >
                                    <a href= "/{!t.id}">
                                   <!-- <apex:param name="tcIP" value="{!t.Id}" />
                                    <apex:outputLink value="{!URLFOR($Action.CloudbyzITPM__Task__c.View, t.id)}" styleClass="leftAlign" >-->{!t.Name}</a>
                                    <!--</apex:outputLink>-->
                                </apex:column>
                            </apex:pageBlockTable>
                        </apex:pageBlock>
                        <apex:commandButton styleClass="div5" value="more" action="{!redirecttoprjtskprj}"
                        />
                    </div>
                </div>
            </div>

        <div class="main_container" style="margin-top:10px">
              <div class="row top_tiles" style="text-align:center;">
            <div class="animated flipInY col-lg-4 col-md-2 col-sm-6 col-xs-12">
                <div class="tile-stats">
                    <div style="text-align:center">
                        <apex:outputLabel value="Tasks starting next week" style="color:#0A31FB;" />
                    </div>
                    <apex:pageBlock >
                         <apex:outputPanel layout="block" styleclass="container">

                        <apex:pageBlockTable value="{!taskPlan}" var="tp" rows="3" rendered="{!taskPlan.size>0}">
                            <apex:column >
                                
                                <a href= "/{!tp.id}">
                                <!--<apex:param name="tpId" value="{!tp.Id}" />
                                <apex:outputLink value="{!URLFOR($Action.CloudbyzITPM__Task__c.View, tp.id)}" styleClass="leftAlign" >-->{!tp.Name}</a>
                                <!--</apex:outputLink>-->
                            
                            </apex:column>
                        </apex:pageBlockTable>
                        </apex:outputPanel>
                    </apex:pageBlock>
                    <apex:commandButton styleClass="div5" value="more" action="{!redirecttoprjtskpln}"
                    />
                </div>
            </div>
        </div>
        </div>

Controller:-  

List<CloudbyzITPM__Task__c> taskname =  [SELECT Id,Name, CloudbyzITPM__Status__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'In Progress' and CloudbyzITPM__Project__r.Id =: recordId];
    
   public List<CloudbyzITPM__Task__c> gettaskname(){

if(taskname.size() < 3 ){
     for(integer i = 0; i <= (3 - taskname.size());){
         
          taskname.add(new CloudbyzITPM__Task__c(Name = 'N/A'));
     }
     
 }
   return taskname;
 }  

 public void gettaskinprogress(){
        if (!Schema.sObjectType.CloudbyzITPM__Task__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.id.isAccessible()
               ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.name.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Milestone__c.isAccessible()
               ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Planned_Start_Date__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Planned_End_Date__c.isAccessible()
                ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Actual_End_Date__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Actual_Start_date__c.isAccessible())
                 {
                  ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,
                                      'Insufficient access'));
                 return;
                 }
       if(currentProjectId!=null)
       currentProjectId=string.escapeSingleQuotes(currentProjectId);
       lstoftasksPrg =  [SELECT Id,Name, CloudbyzITPM__Status__c,CloudbyzITPM__Milestone__c,CloudbyzITPM__Planned_Start_Date__c,CloudbyzITPM__Planned_End_Date__c,CloudbyzITPM__Actual_Start_date__c,CloudbyzITPM__Actual_End_Date__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'In Progress' and CloudbyzITPM__Project__r.Id =: recordId];   

    } 
public List<CloudbyzITPM__Task__c> getlstoftasksPrg(){
    
    return lstoftasksPrg;
}   

  public pagereference redirecttoprjtskprj(){
        return new pagereference('/apex/projecttaskprogress?id='+currentProjectId);
    }




/* task in completed 
  List<CloudbyzITPM__Task__c> taskComp =  [SELECT Id,Name, CloudbyzITPM__Actual_End_Date__c, CloudbyzITPM__Status__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'Completed' and CloudbyzITPM__Actual_End_Date__c >=:system.today().toStartOfWeek().addDays(-7)
 and CloudbyzITPM__Actual_End_Date__c <=:system.today().toStartOfWeek().addDays(-1) and CloudbyzITPM__Project__r.Id =: recordId];
 
 public list<CloudbyzITPM__Task__c> getRows()
 {   
 List<CloudbyzITPM__Task__c> rows =  [SELECT Id,Name, CloudbyzITPM__Actual_End_Date__c, CloudbyzITPM__Status__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'Completed' and CloudbyzITPM__Actual_End_Date__c >=:system.today().toStartOfWeek().addDays(-7)
 and CloudbyzITPM__Actual_End_Date__c <=:system.today().toStartOfWeek().addDays(-1) and CloudbyzITPM__Project__r.Id =: recordId ];
 
 system.debug('@@ rows of task' + rows);
 List<CloudbyzITPM__Task__c> rows_temp = new List<CloudbyzITPM__Task__c>(rows);
 rows.clear();
 for(CloudbyzITPM__Task__c irrTask : rows_temp)
 {
     
 if(irrTask.Name.length()>10) 
 { 
     system.debug('@@ rows of task' + rows);
      irrTask.Name = irrTask.Name.substring(0,10) + '...' ; 
 } 
 rows.add(irrTask);       
 
 } 
(rows.size() < 3 ){
     for(integer i = 0; i <= (3 - rows.size());){
         rows.add(new CloudbyzITPM__Task__c(Name = 'N/A'));
     }
 }
    return rows;  
 }
public void gettaskcompleted(){
    System.debug('@@lstoftaskscmp@@');
        if (!Schema.sObjectType.CloudbyzITPM__Task__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.id.isAccessible()
               ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.name.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Milestone__c.isAccessible()
               ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Planned_Start_Date__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Planned_End_Date__c.isAccessible()
                ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Actual_End_Date__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Actual_Start_date__c.isAccessible())
              {
                 
                 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,
                                      'Insufficient access'));
                 return;
                 }
                 System.debug('@@currentProjectId@@'+currentProjectId);
    
       if(currentProjectId!=null)
       currentProjectId=string.escapeSingleQuotes(currentProjectId);
       lstoftaskscmp =   [SELECT Id,Name, CloudbyzITPM__Actual_End_Date__c,CloudbyzITPM__Milestone__c,CloudbyzITPM__Planned_Start_Date__c,CloudbyzITPM__Planned_End_Date__c ,CloudbyzITPM__Actual_Start_date__c,CloudbyzITPM__Status__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'Completed' and CloudbyzITPM__Actual_End_Date__c >=:system.today().toStartOfWeek().addDays(-7)
 and CloudbyzITPM__Actual_End_Date__c <=:system.today().toStartOfWeek().addDays(-1) and CloudbyzITPM__Project__r.Id =: recordId];
    
    } 
public List<CloudbyzITPM__Task__c> getlstoftaskscmp()
{
    System.debug('@@lstoftaskscmp@@'+lstoftaskscmp);
    return lstoftaskscmp;
}   

  public pagereference redirecttoprjtskcom()
  {
        return new pagereference('/apex/projecttaskcomplete?id='+currentProjectId);
    }


   
Hi Expert,

Iam getting error "System.LimitException: Too many SOQL queries: 101" when i write test class for "update Estimated Cost", iam not able to run it,
and getting error too many soql queries, from other apex class-  "updatePortfolioActualCost", and i have also writen in my test class- seeAllData = false, but it is checking for the other class too. can anybody help me on this.

test class- 

@isTest(seeAllData = false)
private class UpdateEstimatedCostTest
{
    static testMethod void verifyEstimatedCost()
 {      
      CloudbyzITPM__Project_Portfolio__c portfolio1 = new CloudbyzITPM__Project_Portfolio__c(Name = 'Porfolio 1', CloudbyzITPM__Estimated_Costs__c=13.00);
      CloudbyzITPM__Project_Portfolio__c portfolio2 = new CloudbyzITPM__Project_Portfolio__c(Name = 'portfolio 1.1',CloudbyzITPM__Estimated_Costs__c=17.00);
     
     Test.startTest();
     
     
     
     insert portfolio1;
     
     insert portfolio2;
        
     CloudbyzITPM__Project_Portfolio__c portfolio1_1 = [Select id,name,CloudbyzITPM__Estimated_Costs__c from CloudbyzITPM__Project_Portfolio__c where id = :portfolio1.id];
     CloudbyzITPM__Project_Portfolio__c portfolio2_2 = [Select id,name,CloudbyzITPM__Estimated_Costs__c from CloudbyzITPM__Project_Portfolio__c where id = :portfolio2.id];
    
     
     
     CloudbyzITPM__Project__c affectedPro = new CloudbyzITPM__Project__c(Name = 'Project 1');
    
    // creating project without portfoilio and planned estimated cost
    
     insert affectedPro;
    
     CloudbyzITPM__Project__c affectedPro1 = new CloudbyzITPM__Project__c(Name = 'Project 2', CloudbyzITPM__Project_Portfolio__c= portfolio1_1.id );
   
     insert affectedPro1;
     
     
     CloudbyzITPM__Project__c affectedPro1_1 = [Select id,name,CloudbyzITPM__Planned_Estimated_Costs__c,CloudbyzITPM__Project_Portfolio__c from CloudbyzITPM__Project__c where id = :affectedPro1.id limit 1]; 
 
  // change the portfolio value of a project
 
     affectedPro1_1.CloudbyzITPM__Project_Portfolio__c = portfolio2_2.id;
  
     
     update affectedPro1_1;
    
     
     // remove planned estimated cost of project mapped to a portfoilo
     
     affectedPro1_1.CloudbyzITPM__Planned_Estimated_Costs__c = null;
     
     update affectedPro1_1;
    
   // change the portfolio and update the estimated cost
     
     affectedPro1_1.CloudbyzITPM__Planned_Estimated_Costs__c = 450;
     
     update affectedPro1_1;
     
   //remove portfoilio with actual hours
   
    
    affectedPro1_1.CloudbyzITPM__Project_Portfolio__c = null;
    
    update affectedPro1_1;
    
    
     CloudbyzITPM__Project__c affectedPro2 = new CloudbyzITPM__Project__c(Name = 'Project 3', CloudbyzITPM__Planned_Estimated_Costs__c =200.00);
    
    // creating project without portfolio and with estimated cost
    
     insert affectedPro2;
     
     
     portfolio1_1.CloudbyzITPM__Estimated_Costs__c=affectedPro2.CloudbyzITPM__Planned_Estimated_Costs__c;
     
     update portfolio1;
     
     portfolio2_2.CloudbyzITPM__Estimated_Costs__c=affectedPro2.CloudbyzITPM__Planned_Estimated_Costs__c;
     
     update portfolio2;
     
     portfolio1_1.CloudbyzITPM__Estimated_Costs__c=affectedPro1.CloudbyzITPM__Planned_Estimated_Costs__c;
     
     
     update portfolio1;
     
     portfolio2_2.CloudbyzITPM__Estimated_Costs__c=affectedPro1.CloudbyzITPM__Planned_Estimated_Costs__c;
     
     update portfolio2_2;
     
     
    CloudbyzITPM__Project__c affectedPro2_1 = [Select id,name,CloudbyzITPM__Planned_Estimated_Costs__c,CloudbyzITPM__Project_Portfolio__c from CloudbyzITPM__Project__c where id = :affectedPro2.id limit 1]; 
    affectedPro2_1.CloudbyzITPM__Planned_Estimated_Costs__c=300.00;
    
    // change the value of estimated cost of project which is mapped to a portfolio
    
    update affectedPro2_1;
    
    affectedPro2.CloudbyzITPM__Planned_Estimated_Costs__c=100.00;
    update affectedPro2;
     
     
    delete affectedPro2_1;
    
    delete affectedPro;
     Test.stopTest();  
 } 
}


Different class where iam getting error- on line no.100 

public class updatePortfolioActualCosts 

{
    public static List<CloudbyzITPM__Project__c> affectedActualCosts = new List<CloudbyzITPM__Project__c>();
    public static List<CloudbyzITPM__Project__c> oldaffectedActualCosts = new List<CloudbyzITPM__Project__c>();
    public static set<ID> affc = new set<ID>();
    public static set<ID> affcold = new set<ID>();
    
    
    public static void processAfterUpdateActualCosts()
  {
      // inserting old and new values
  
       affectedActualCosts = (List<CloudbyzITPM__Project__c>)Trigger.New;
       oldaffectedActualCosts = (List<CloudbyzITPM__Project__c>)Trigger.Old;
       
      // process after deleting the project 
       
       if(Trigger.isDelete)
       {
         for(CloudbyzITPM__Project__c  affc1 : oldaffectedActualCosts)
       {
       
      // check whether the portfolio is selescted for the project
       
       if(affc1.CloudbyzITPM__Project_Portfolio__c != null)
       {
         system.debug('value of affc1'+ affc1);
         affc.add(affc1.CloudbyzITPM__Project_Portfolio__c);
       }
       }
         system.debug('this is the value'+ affc);
       
       // process after selecting the portfolio
       
       if(affc.size()>0)
       {
         CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Total_Actual_Cost__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
         list<CloudbyzITPM__Project__c> affectedActualCosts1 = [select id, name,CloudbyzITPM__Total_Actual_Cost__c, CloudbyzITPM__Project_Portfolio__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
          
         Decimal j=0;
         System.debug('@@affectedActualCosts1@@'+affectedActualCosts1+'@@affectedActualCosts1.size'+affectedActualCosts1.size());  
       if(affectedActualCosts1.size()>0)
       {
         for(CloudbyzITPM__Project__C afc1 : affectedActualCosts1)
       {
         System.debug('@@afc1.CloudbyzITPM__Total_Actual_Cost__c@@'+afc1.CloudbyzITPM__Total_Actual_Cost__c);
       if(afc1.CloudbyzITPM__Total_Actual_Cost__c !=0 && afc1.CloudbyzITPM__Total_Actual_Cost__c!=null)
         
         // add all the actual cost of the associated project
            
          j = j + afc1.CloudbyzITPM__Total_Actual_Cost__c;
       }
    }
    
        // put all the roll ups of actual cost to portfolio
    
       if(j>0)
       {
         System.debug('@@pBUFinal@@');
         fn.CloudbyzITPM__Total_Actual_Cost__c = j;
       }
          
       else
       {
         fn.CloudbyzITPM__Total_Actual_Cost__c = 0;
       }
         update fn; 
         System.debug('@@fn4@@'+fn);
       }
    }
       else
       {
       if(affectedActualCosts.size()>0)
       {
         system.debug('@@@value of affc1'+ affectedActualCosts);
         for(integer i = 0; i<affectedActualCosts.size(); ++i)
       {
       if(affectedActualCosts[i]!= null && affectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c != null && oldaffectedActualCosts!= null && oldaffectedActualCosts[i]!= null && oldaffectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c != null && oldaffectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c != affectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c)
       {
         system.debug('value of affc1'+ affectedActualCosts[i]);
         affc.add(affectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c);
         affcold.add(oldaffectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c);
       }
       if(affectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c != null)
       {
         system.debug('value of affc1'+ affectedActualCosts[i]);
         affc.add(affectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c);
       } 
       else if(oldaffectedActualCosts!= null && oldaffectedActualCosts[i]!= null && oldaffectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c != null)
       {
         affc.add(oldaffectedActualCosts[i].CloudbyzITPM__Project_Portfolio__c); 
       }
             
     }
       if(affcold.size()>0)
       {
         system.debug('this is the value'+ affc);
         CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Total_Actual_Cost__c from CloudbyzITPM__Project_Portfolio__c where id in: affcold limit 1];
         list<CloudbyzITPM__Project__c> affectedActualCosts1 = [select id, name,CloudbyzITPM__Total_Actual_Cost__c, CloudbyzITPM__Project_Portfolio__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
      
         Decimal j=0;
         System.debug('@@affectedActualCosts1@@'+affectedActualCosts1+'@@affectedActualCosts1.size'+affectedActualCosts1.size());  
     
      if(affectedActualCosts1.size()>0)
       {
         for(CloudbyzITPM__Project__C afc1 : affectedActualCosts1)
       {
         System.debug('@@afc1.CloudbyzITPM__Total_Actual_Cost__c@@'+afc1.CloudbyzITPM__Total_Actual_Cost__c);
     
      if(afc1.CloudbyzITPM__Total_Actual_Cost__c !=0 && afc1.CloudbyzITPM__Total_Actual_Cost__c!=null)
            j = j + afc1.CloudbyzITPM__Total_Actual_Cost__c;
       }
      }
    
      if(j>0)
      {
         System.debug('@@pBUFinal@@');
         fn.CloudbyzITPM__Total_Actual_Cost__c = j;
      }
      else
      {
         fn.CloudbyzITPM__Total_Actual_Cost__c = 0;
      }
      update fn; 
         System.debug('@@fn4@@'+fn);
      }
      if(affc.size()>0)
      {
         system.debug('this is the value'+ affc);
         CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Total_Actual_Cost__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
         list<CloudbyzITPM__Project__c> affectedActualCosts1 = [select id, name,CloudbyzITPM__Total_Actual_Cost__c, CloudbyzITPM__Project_Portfolio__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
      
         Decimal j=0;
         System.debug('@@affectedActualCosts1@@'+affectedActualCosts1+'@@affectedActualCosts1.size'+affectedActualCosts1.size());  
      if(affectedActualCosts1.size()>0)
       {
         for(CloudbyzITPM__Project__C afc1 : affectedActualCosts1)
       {
         System.debug('@@afc1.CloudbyzITPM__Total_Actual_Cost__c@@'+afc1.CloudbyzITPM__Total_Actual_Cost__c);
      if(afc1.CloudbyzITPM__Total_Actual_Cost__c !=0 && afc1.CloudbyzITPM__Total_Actual_Cost__c!=null)
            j = j + afc1.CloudbyzITPM__Total_Actual_Cost__c;
       }
    }
    
      if(j>0)
       {
         System.debug('@@pBUFinal@@');
         fn.CloudbyzITPM__Total_Actual_Cost__c = j;
       }
      else
      {
         fn.CloudbyzITPM__Total_Actual_Cost__c = 0;
      }
         update fn; 
         System.debug('@@fn4@@'+fn);
    }
    }
    }
}
}

Regards,

Deepak
Hi expert,

i have a scenerio, in which update the field on unrelated objects which are on different apps, 

Apps- Remedyforce and ITPM
Objects- Incident(Remedyforce) and ITPM(Work Request)

when the 'Incident type' picklist field is equals to 'project'  in 'Incident' object then it should create the 'work request' object record and update the below field and if there already work request has been created then no need to create.

Work Request Name = Request Definition (BMCServiceDesk__FKRequestDefinition__c)
Incident (Incident__c) = Incident (BMCServiceDesk__FKIncident__c)
Date requested (Date_Requested__c) = system date
work request status (CloudbyzITPM__Work_Request_Status__c) value as “Draft”
Owner from Owner in Incident object

Anybody can help on this- 




 
Hi Expert,

Have to update the field 'actual hours' of "project Portfolio" object through all the roll up of the 'actual hours' of "project" object. 

iam getting an error- System.NullPointerException: Attempt to de-reference a null object: Class.updatedActualHours.processAfterUpdateActualHours: line 61, column 1

here is the code-

public class updatedActualHours 

{
  public static List<CloudbyzITPM__Project__c> affectedActualHours = new List<CloudbyzITPM__Project__c>();
    public static List<CloudbyzITPM__Project__c> oldaffectedActualHours = new List<CloudbyzITPM__Project__c>();
  public static set<ID> affc = new set<ID>();
    public static set<ID> affcold = new set<ID>();
  public static void processAfterUpdateActualHours()
 {
     affectedActualHours = (List<CloudbyzITPM__Project__c>)Trigger.New;
     oldaffectedActualHours = (List<CloudbyzITPM__Project__c>)Trigger.Old;
     if(Trigger.isDelete){
        for(CloudbyzITPM__Project__c  affc1 : oldaffectedActualHours)
     {
         if(affc1.CloudbyzITPM__Project_Portfolio__c != null)
         {
         system.debug('value of affc1'+ affc1);
        affc.add(affc1.CloudbyzITPM__Project_Portfolio__c);
     }
     }
      system.debug('this is the value'+ affc);
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Actual_Hours__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
    list<CloudbyzITPM__Project__c> affectedActualHours1 = [select id, name,CloudbyzITPM__Actual_Hours__c, CloudbyzITPM__Project_Portfolio__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
          
      Decimal j=0;
     System.debug('@@affectedActualHours1@@'+affectedActualHours1+'@@affectedActualHours1.size'+affectedActualHours1.size());  
    if(affectedActualHours1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedActualHours1)
        {
            System.debug('@@afc1.CloudbyzITPM__Actual_Hours__c@@'+afc1.CloudbyzITPM__Actual_Hours__c);
          if(afc1.CloudbyzITPM__Actual_Hours__c !=0 && afc1.CloudbyzITPM__Actual_Hours__c!=null)
            j = j + afc1.CloudbyzITPM__Actual_Hours__c;
        }
    }
    
 if(j>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Actual_Hours__c = j;
    }
          else{
              fn.CloudbyzITPM__Actual_Hours__c = 0;
          }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
    else{
     if(affectedActualHours.size()>0)
     {/*
     for(CloudbyzITPM__Project__c  affc1 : affectedActualHours)
     {
         if(affc1.CloudbyzITPM__Project_Portfolio__c != null)
         {
         system.debug('value of affc1'+ affc1);
        affc.add(affc1.CloudbyzITPM__Project_Portfolio__c);
     }
     }*/
         system.debug('@@@value of affc1'+ affectedActualHours);
         for(integer i = 0; i<affectedActualHours.size(); ++i){
         if(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null && oldaffectedActualHours[i]!= null && oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null && oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c)
         {
         system.debug('value of affc1'+ affectedActualHours[i]);
        affc.add(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c);
             affcold.add(oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c);
         }
             if(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null)
         {
         system.debug('value of affc1'+ affectedActualHours[i]);
        affc.add(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c);
         } 
             else if(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null && oldaffectedActualHours[i]!= null && oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null){
                affc.add(oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c); 
             }
             
         }
          if(affcold.size()>0)
      {
     system.debug('this is the value'+ affc);
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Actual_Hours__c from CloudbyzITPM__Project_Portfolio__c where id in: affcold limit 1];
    list<CloudbyzITPM__Project__c> affectedActualHours1 = [select id, name,CloudbyzITPM__Actual_Hours__c, CloudbyzITPM__Project_Portfolio__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
      
      Decimal j=0;
     System.debug('@@affectedActualHours1@@'+affectedActualHours1+'@@affectedActualHours1.size'+affectedActualHours1.size());  
    if(affectedActualHours1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedActualHours1)
        {
            System.debug('@@afc1.CloudbyzITPM__Actual_Hours__c@@'+afc1.CloudbyzITPM__Actual_Hours__c);
          if(afc1.CloudbyzITPM__Actual_Hours__c !=0 && afc1.CloudbyzITPM__Actual_Hours__c!=null)
            j = j + afc1.CloudbyzITPM__Actual_Hours__c;
        }
    }
    
 if(j>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Actual_Hours__c = j;
    }
          else{
              fn.CloudbyzITPM__Actual_Hours__c = 0;
          }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
      if(affc.size()>0)
      {
     system.debug('this is the value'+ affc);
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Actual_Hours__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
    list<CloudbyzITPM__Project__c> affectedActualHours1 = [select id, name,CloudbyzITPM__Actual_Hours__c, CloudbyzITPM__Project_Portfolio__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
      
      Decimal j=0;
     System.debug('@@affectedActualHours1@@'+affectedActualHours1+'@@affectedActualHours1.size'+affectedActualHours1.size());  
    if(affectedActualHours1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedActualHours1)
        {
            System.debug('@@afc1.CloudbyzITPM__Actual_Hours__c@@'+afc1.CloudbyzITPM__Actual_Hours__c);
          if(afc1.CloudbyzITPM__Actual_Hours__c !=0 && afc1.CloudbyzITPM__Actual_Hours__c!=null)
            j = j + afc1.CloudbyzITPM__Actual_Hours__c;
        }
    }
    
 if(j>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Actual_Hours__c = j;
    }
          else{
              fn.CloudbyzITPM__Actual_Hours__c = 0;
          }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
    }
    }
}
}User-added image


Hi Expert,

I have a scenerio in which i have to update the field "budget hours" of "project portfolio" object with the "budget hour" field of "project" object, hence 1 "project portfolio" have multiple "project", it should have all the sum of "budget hour" field into that "budget hours" of "project portfolio" object. 

But when we cange the "project portfolio" in "project" object. so in the "budget hours" field of "project portfolio" should deacreases, coz we have change the "project portfolio" of that partcular "project" and add the "budget hours" of another "project portfolio" which we have added. but it is not hapenning in my org. 

Code is here- 

public class updateBudgetedHours 
{

  public static List<CloudbyzITPM__Project__c> affectedBudgetedHours = new List<CloudbyzITPM__Project__c>();
 public static set<ID> affc = new set<ID>();
 public static void processAfterUpdateBudgetedHours()
 {
     affectedBudgetedHours = (List<CloudbyzITPM__Project__c>)Trigger.New;
     if(affectedBudgetedHours.size()>0){
     for(CloudbyzITPM__Project__c  affc1 : affectedBudgetedHours)
     {
         if(affc1.CloudbyzITPM__Project_Portfolio__c != null)
         {
      affc.add(affc1.CloudbyzITPM__Project_Portfolio__c);
     }
     }
     
    if(affc.size()>0)
    {
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name, CloudbyzITPM__Budgeted_Hours__c from CloudbyzITPM__Project_Portfolio__c where id IN :affc limit 1];
    list<CloudbyzITPM__Project__c> affectedBudgetedHours1 = [select id,name,CloudbyzITPM__Project_Portfolio__c,CloudbyzITPM__Budgeted_Hours__c from CloudbyzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
    Decimal i=0;
       
    if(affectedBudgetedHours1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedBudgetedHours1)
        {
            i = i + afc1.CloudbyzITPM__Budgeted_Hours__c;
        }
    }
    
 if(i>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Budgeted_Hours__c = i;
    }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
    
    }
 }
}

Trigger- 

Trigger UpdateBH on CloudbyzITPM__Project__c (before insert, before update, before delete,after insert, after update, after delete) 

{
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter )   
{
updateBudgetedHours.processAfterUpdateBudgetedHours();
}

if((Trigger.isDelete || Trigger.isUpdate) && Trigger.isBefore)
{
updateBudgetedHours.processAfterUpdateBudgetedHours();
}
}


what to change in the code?

Thanks & Regards,

Deepak
Hi Expert,

iam getting error when executing the trigger.

scenerio-  update the field " project risk count" of child object "Project Portfolio" with the field "risk count" of parent object "Project".

Class-

public class updateProjectRiskCount 
{
  
  public static List<CloudbyzITPM__Project__c> affectedRiskCount = new List<CloudbyzITPM__Project__c>();
  public static set<ID> affc = new set<ID>();
    

  public static void processAfterUpdateRiskCount()
 {
     affectedRiskCount = (List<CloudbyzITPM__Project__c>)Trigger.New;
     if(affectedRiskCount.size()>0){
     for(CloudbyzITPM__Project__c  affc1 : affectedRiskCount)
     {
      affc.add(affc1.id);
     }
     }
      
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Project_Risk_Count__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
    list<CloudbyzITPM__Project__c> affectedRiskCount1 = [select id, name,CloudbyzITPM__Project_Portfolio__c,CloudbyzITPM__Risk_Count__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
      
      Decimal i=0;
       
    if(affectedRiskCount1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedRiskCount1)
        {
            i = i + afc1.CloudbyzITPM__Risk_Count__c;
        }
    }
    
 if(i>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Project_Risk_Count__c = i;
    }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
  
  }


Trigger- 

Trigger UpdateRC2 on CloudbyzITPM__Project__c (before insert, before update, before delete, after insert, after update, after delete)
{
  if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter)
      
  {
      updateProjectRiskCount.processAfterUpdateRiskCount();
  }
}

Note- i have written 4 triggers on the same object "project". 

Screenshot attached.

User-added image

 
Hi,

I have a requirnment in which "hour rate" field should be updated with the "hour cost" of differrent object and we can also able to update the "hour rate" field manually and save it.

I have written the trigger for this. in which it always updating the field "hour rate" with the "hour cost". i can't able to update the "hour rate" field manually.

anybody can help with the logic.

public class updateHourlyRate
{
 public static List<CloudbyzITPM__Team_Member__c> affectedProd= new
List<CloudbyzITPM__Team_Member__c>();
 public static List<CloudbyzITPM__Team_Member__c> affectedProd_final=
new List<CloudbyzITPM__Team_Member__c>();
public static set<id> afc_test = new Set<id>();
 public static set<ID> afc2 = new set<ID>();
 public static void processAfterUpdateOrInsertHourlyCost(){
 affectedProd_final.clear();
      affectedProd = (List<CloudbyzITPM__Team_Member__c>)Trigger.New;
      System.debug('This is IT @@'+affectedProd);
     if(affectedProd.size()>0){
     for(CloudbyzITPM__Team_Member__c  affc : affectedProd){
      afc2.add(affc.CloudbyzITPM__Resource__c);
      afc_test.add(affc.id);
     }
     }
     CloudbyzITPM__Resource__c fn = [Select id,
CloudbyzITPM__Hourly_Cost__c from CloudbyzITPM__Resource__c where id
IN :afc2 limit 1];
     List<CloudbyzITPM__Team_Member__c> affectedProd1 = [Select
id,name,CloudbyzITPM__Hourly_Rate__c from CloudbyzITPM__Team_Member__c
where id IN :afc_test limit 1];
    // Decimal i =0 ;
     if(affectedProd1.size()>0){
     for(CloudbyzITPM__Team_Member__c  affc : affectedProd1){
     //i = i+ affc.CloudbyzITPM__Total_Actual_Cost__c;
    if(fn.CloudbyzITPM__Hourly_Cost__c != 0){
     affc.CloudbyzITPM__Hourly_Rate__c = fn.CloudbyzITPM__Hourly_Cost__c;
    affectedProd_final.add(affc);
    }
    }
     }
      System.debug('This is IT @@'+affectedProd);
     
if(affectedProd_final.size()>0)
     update affectedProd_final;
 }
  public static void processbeforeUpdateHourlyCost(){
 affectedProd_final.clear();
      affectedProd = (List<CloudbyzITPM__Team_Member__c>)Trigger.New;
      System.debug('This is IT @@'+affectedProd);
     if(affectedProd.size()>0){
     for(CloudbyzITPM__Team_Member__c  affc : affectedProd){
      afc2.add(affc.CloudbyzITPM__Resource__c);
      afc_test.add(affc.id);
     }
     }
     CloudbyzITPM__Resource__c fn = [Select id,
CloudbyzITPM__Hourly_Cost__c from CloudbyzITPM__Resource__c where id
IN :afc2 limit 1];
    /* List<CloudbyzITPM__Team_Member__c> affectedProd1 = [Select
id,name,CloudbyzITPM__Hourly_Rate__c from CloudbyzITPM__Team_Member__c
where id IN :afc_test limit 1];
    // Decimal i =0 ;
     if(affectedProd1.size()>0){*/
     for(CloudbyzITPM__Team_Member__c  affc : affectedProd){
     //i = i+ affc.CloudbyzITPM__Total_Actual_Cost__c;
    if(fn.CloudbyzITPM__Hourly_Cost__c != 0){
     affc.CloudbyzITPM__Hourly_Rate__c = fn.CloudbyzITPM__Hourly_Cost__c;
   // affectedProd_final.add(affc);
    }
    }
    // }
  //    System.debug('This is IT @@'+affectedProd);
     
//if(affectedProd_final.size()>0)
  //   update affectedProd_final;
 }
}

Trigger is- trigger hrtest on CloudbyzITPM__Team_Member__c (after insert,before update) {
if(Trigger.isInsert && Trigger.isAfter)   
{
System.debug('Trigger');
updateHourlyRate.processAfterUpdateOrInsertHourlyCost();
}
if(Trigger.isUpdate && Trigger.isBefore)   
{
System.debug('Trigger');
updateHourlyRate.processbeforeUpdateHourlyCost();

}
Hi Expert,

There r two objects "project member" and "resource" in which under "project member" object i have to update the field "hour rate" with "resource" object field "hour cost", when something is written in "hour cost" field, otherwise "hour rate" field not update and able to enter something and save it.

my code is- 

public class updateHourlyRate
{
 public static List<CloudbyzITPM__Team_Member__c> affectedProd= new
List<CloudbyzITPM__Team_Member__c>();
 public static List<CloudbyzITPM__Team_Member__c> affectedProd_final=
new List<CloudbyzITPM__Team_Member__c>();

 public static set<ID> afc2 = new set<ID>();
 public static void processAfterUpdateOrInsertHourlyCost(){
      affectedProd = (List<CloudbyzITPM__Team_Member__c>)Trigger.New;
     if(affectedProd.size()>0){
     for(CloudbyzITPM__Team_Member__c  affc : affectedProd){
      afc2.add(affc.CloudbyzITPM__Team_Member__c);
     }
     }
     CloudbyzITPM__Resource__c fn = [Select id,
CloudbyzITPM__Hourly_Cost__c from CloudbyzITPM__Resource__c where id
IN :afc2 limit 1];
     List<CloudbyzITPM__Team_Member__c> affectedProd1 = [Select
id,name,CloudbyzITPM__Hourly_Rate__c from CloudbyzITPM__Team_Member__c
where CloudbyzITPM__Resource__c = :fn.id];
    // Decimal i =0 ;
     if(affectedProd1.size()>0){
     for(CloudbyzITPM__Team_Member__c  affc : affectedProd1){

     affc.CloudbyzITPM__Hourly_Rate__c = fn.CloudbyzITPM__Hourly_Cost__c;
    affectedProd_final.add(affc);
    }
     }

     update affectedProd_final;
 }
}

trigger- trigger HourRate on CloudbyzITPM__Resource__c (before insert, before update, before delete, after insert, after update, after delete) 
{
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter)   
{
updateHourlyRate.processAfterUpdateOrInsertHourlyCost();

}

when i change the field "hourly cost" , it gives an error.
"Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger HourRate caused an unexpected exception, contact your administrator: HourRate: execution of AfterUpdate caused by: System.TypeException: Invalid conversion from runtime type List to List: Class.updateHourlyRate.processAfterUpdateOrInsertHourlyCost: line 10, column 1"
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);
    }
    
    }
    

 
Have to update the "total actual cost field" in custom object called "project portfolio" from its associated custom object called "projects"'s fields total actual cost. means all the "total actual cost" fields of different projects associated with the "project portfolio" should come into "total actual cost" field of "project portfolio" object.

Both the objects have same fields.

API Names- 

Project- CloudbyzITPM__Project__c
Project Portfolio- CloudbyzITPM__Project_Portfolio__c
Field name- CloudbyzITPM__Total_Actual_Cost__c

below is my code and iam getting error- "Didn't understand relationship 'Projects__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names".


trigger UpdateTotalActualCosts on CloudbyzITPM__Project__c (after insert,after update, after delete,after undelete) {

  List<id> QuotationsIds = new List<id>();

    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){

        For(CloudbyzITPM__Project__c con1 : Trigger.new){

            QuotationsIds.add(con1.CloudbyzITPM__Project_Portfolio__c);

        }

    }

    if(Trigger.isDelete){

        For(CloudbyzITPM__Project__c con1 : Trigger.old){

            QuotationsIds.add(con1.CloudbyzITPM__Project_Portfolio__c);

        }

    }

    List<CloudbyzITPM__Project_Portfolio__c> QuotationsToUpdate = new List<CloudbyzITPM__Project_Portfolio__c>();

    decimal sum = 0;

    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){

        For(CloudbyzITPM__Project_Portfolio__c q : [select CloudbyzITPM__Total_Actual_Cost__c,(SELECT id,CloudbyzITPM__Total_Actual_Cost__c  FROM Projects__r) FROM CloudbyzITPM__Project_Portfolio__c WHERE id =: QuotationsIds]){

            sum = 0;

            for(CloudbyzITPM__Project__c p : q.Projects__r)
                sum = sum + p.CloudbyzITPM__Total_Actual_Cost__c ;

            q.CloudbyzITPM__Total_Actual_Cost__c = sum;

            QuotationsToUpdate.add(q);

        }

        try{

            update QuotationsToUpdate ;

        }Catch(Exception e){

            System.debug('Exception :'+e.getMessage());

        }

    }

}
have to update the "total actual cost field" in custom object called "project portfolio" from its associated custom object called "projects"'s fiels total actual cost. means all the "total actual cost" fields of different projects associated with the "project portfolio" should come into "total actual cost" field of "project portfolio" 

Both have total actual cost field.

code-

trigger UpdateTotalActualCost on CloudbyzITPM__Project_Portfolio__c (after insert, after update) 
{
    
          List<CloudbyzITPM__Project_Portfolio__c> Portfoliorecords =
         (List<CloudbyzITPM__Project_Portfolio__c>)Trigger.New;
     Set<id> recordId = new Set<id>();
     for(CloudbyzITPM__Project_Portfolio__c  port : Portfoliorecords)
     {
     recordId.add(port.id);
     }

     List<CloudbyzITPM__Project__c> fn = [Select id,
CloudbyzITPM__Total_Costs__c from CloudbyzITPM__Project__c where id IN
:recordId];
     if(fn.size()>0)
     {
     for(CloudbyzITPM__Project__c  affc : fn)
     {
     Portfoliorecords.CloudbyzITPM__Total_Actual_Cost__c =
Portfoliorecords.CloudbyzITPM__Total_Actual_Cost__c +
affc.CloudbyzITPM__Total_Costs__c;
     }
     }
    update Portfoliorecords ;
}




error - "Initial term of field expression must be a concrete SObject: List<CloudbyzITPM__Project_Portfolio__c>"
have to update the "total actual cost field" in custom object called "project portfolio" from its associated custom object called "projects"'s fiels total actual cost. means all the "total actual cost" fields of different projects associated with the "project portfolio" should come into "total actual cost" field of "project portfolio" 

Both have total actual cost field.

 
I should be able to copy the entire set of project, work type, activity type, task, remarks, note and time combinations from previous week to the current week for which I want to enter time by clicking a button “Copy from Previous week”.

User-added image
means everything should come exactly which i have saved previously.
previously it was- 

User-added image

i have to make it like this-

User-added image

-> Previously all the projects, application, tasks are used be in the same row. but now i have to make into different sections.
    like the second image.
-> have to include the date field also above mon --sat. which date should be there along with the week days, when we select the date from calender.
-> make the grand total also with row wise and coloumn wise.
-> there would be "add row" button below every block in which it should include rows.like if we click "add row", row should be added.
 

 
global class UpdateContactAdresses implements Database.Batchable<sObject>, Database.stateful

{
    global Integer recordsProcessed = 0;
    
    global Database.QueryLocator start(Database.BatchableContext bc)
        
    {
        return.Database.getQueryLocator('select id, BillingStreet, BillingCity, BillingState, '+'BillingPostalCode, (select id, MailingStreet, MailingCity,'+' MailingState, MailingPostalCode from contacts) from Account'+'where BillingCountry=\'USA\'');
        
    }
    
    global void execute(Database.BatchableContext bc, list<Account> scope)
    {
        list<contact> contacts= new list<contact>();
        for(Account account: scope)
        {
            for(Contact contact:account.contacts)
            {
                contact.MailingStreet = account.BillingStreet;
                contact.MailingState = account.BillingState;
                contact.MailingCity = account.BillingCity;
                contact.MailingPostalCode = account.BillingPostalCode;
        
                contacts.add(contact);
                recordsProcessed = recordsProcessed + 1;
            } 
                
                
        }
        
        update contacts;
        
    }        
        global void finish(Database.BatchableContext bc)
        {       
         system.debug(recordProcessed +' record is processed');
         AsyncApexJob job = [select id, status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email from AsyncApexJob where id=: bc.getJobId()];
         EmailUtils.SendMessage(a, recordsProcessed);
        }
        }
    
        
<apex:page sidebar="false" standardController="Account">
<apex:pageBlock title="Account Summary">
<apex:pageBlockSection >
Name: {!Account.Name}<br/>
Phone: {!Account.Phone}<br/>
Industry: {!Account.Industry}<br/>
Revenue: {!Account.AnnualRevenue}<br/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
global class UpdateContactAdresses implements Database.Batchable<sObject>, Database.stateful

{
    global Integer recordsProcessed = 0;
    
    global Database.QueryLocator start(Database.BatchableContext bc)
        
    {
        return.Database.getQueryLocator('select id, BillingStreet, BillingCity, BillingState, '+'BillingPostalCode, (select id, MailingStreet, MailingCity,'+' MailingState, MailingPostalCode from contacts) from Account'+'where BillingCountry=\'USA\'');
        
    }
    
    global void execute(Database.BatchableContext bc, list<Account> scope)
    {
        list<contact> contacts= new list<contact>();
        for(Account account: scope)
        {
            for(Contact contact:account.contacts)
            {
                contact.MailingStreet = account.BillingStreet;
                contact.MailingState = account.BillingState;
                contact.MailingCity = account.BillingCity;
                contact.MailingPostalCode = account.BillingPostalCode;
        
                contacts.add(contact);
                recordsProcessed = recordsProcessed + 1;
            } 
                
                
        }
        
        update contacts;
        
    }        
        global void finish(Database.BatchableContext bc)
        {       
         system.debug(recordProcessed +' record is processed');
         AsyncApexJob job = [select id, status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email from AsyncApexJob where id=: bc.getJobId()];
         EmailUtils.SendMessage(a, recordsProcessed);
        }
        }
    
        
trigger AddRelatedRecord on Account (after insert, after update) 
{
  list<opportunity> opplst = new list<opportunity>();
    Map<ID,Account> acctsWithOpps = new Map<ID,Account>([select id,(select id from opportunities) from Account where id IN: Trigger.New]);
    
    for(Account a: Trigger.New)
    {
        if(acctsWithOpps.get(a.Id).Opportunities.Size()==0)
        {
            opplst.add(new opportunity(Name=a.Name + 'opportunity',StageName='Prospecting',CloseDate=System.today().addMonths(1),AccountId=a.Id));
        }
    }
    if(opplst.size()>0)
    {
        insert opplst;
    }
}


User-added image
Hi,

I have stored the html page in static resource and showing it via lightning component. how to cover the static resource test class?

Apex code - 
@auraEnabled
public static string getFooterContent(String staticResourceName) {
   
    Blob bodydata =  [SELECT Body FROM  StaticResource  WHERE Name = :staticResourceName].Body;
    String s = bodydata.toString();
    
    return s;
}
Hi Expert,

I have a VF page in which there is a block 'Project Team', in this block we are displaying the record 'resourse full name',when there is no record there, table gets shrinked, hence i want to put N/A there when there is no record. but 'resource full name' is a formula field. How to put N/A there. 

VF Page - 

     <div class="main_container" style="margin-top:10px">
            <div class="animated flipInY col-lg-5 col-md-80 col-sm-80 col-xs-80">
                <div class="tile-stats">
                    <apex:outputLabel value="Deliverables/Objectives" style="color:#0A31FB;" />
                    <apex:panelGrid columns="1" border="0" style="border:hidden">

                        <!--apex:outputLabel value="Project:" style="border-hidden" />-->
                        <apex:outputText value="{!CloudbyzITPM__Project__c.CloudbyzITPM__Project_Goal__c}"
                            style="border-hidden"/>
                    
                    <!--apex:panelGrid columns="1" columnClasses="col1,col2" border="1" style="border:solid"
                        cellpadding="3">-->
                        <!--apex:outputLabel value="Description:" style="text-align:left;border-hidden" />-->
                        <apex:outputText value="{!CloudbyzITPM__Project__c.CloudbyzITPM__Description__c}"
                            style="white-space:pre-wrap;border-hidden"/>
                    </apex:panelGrid>
                </div>
            </div>
        </div>

Controller:- 
    
   
 List< CloudbyzITPM__Team_Member__c> tempTMlist =[select Id,CloudbyzITPM__Resource_Full_Name__c from CloudbyzITPM__Team_Member__c where CloudbyzITPM__Project__r.Id =: recordId];
    
     public List<CloudbyzITPM__Team_Member__c> gettempTMlist()
     
     {
     if(tempTMlist.size() < 3 ){
     for(integer i = 0; i <= (3 - tempTMlist.size());){
         
          tempTMlist.add(new CloudbyzITPM__Team_Member__c(CloudbyzITPM__Resource_Full_Name__c = null));
     }
     }    
         return tempTMlist;
    }








 
Hi,

I have a visual force page as shown below in which 'more' is redirect the user to details page of records. but for the block 'Task completed last week' more button is not working, for others it is working fine. any body can help

below is my vf page and controller:-


        <div class="main_container" style="margin-top:10px">
            <div class = "height:50%">
                <div class="animated flipInY col-lg-4 col-md-80 col-sm-80 col-xs-80">
                    <div class="tile-stats">
                        <div style="text-align:center">
                            <apex:outputLabel value="Task Completed Last Week" style="color:#0A31FB;" />
                        </div>
                        <apex:pageBlock >
                         
                            <apex:pageBlockTable value="{!rows}" var="tc" rows="3" rendered="{!rows.size>0}">
                                  
                                <apex:column >

                                    <a href= "/{!tc.id}">
                                    <!--apex:outputLink value="{!URLFOR($Action.CloudbyzITPM__Task__c.View, tc.id)}" styleClass="leftAlign" >-->{!tc.Name}</a>
                                    <!--/apex:outputLink>-->
                            
                                </apex:column>
                              
                            </apex:pageBlockTable>
                            <!-- <apex:repeat>
                                 dsd
                            <apex:outputText value="There are no tasks to display." style="white-space:pre-wrap;border-hidden" />
                            </apex:repeat>-->

                        </apex:pageBlock>
                        <apex:commandButton styleClass="div5" value="more" action="{!redirecttoprjtskcom}"
                        />
                    </div>
            </div>
            </div>
            </div>
   




        <div class="main_container" style="margin-top:10px">
                <div class="animated flipInY col-lg-4 col-md-2 col-sm-6 col-xs-12">
                    <div class="tile-stats">
                        <div style="text-align:center">
                            <apex:outputLabel value="Task In Progress" style="color:#0A31FB;" />
                        </div>
                        <apex:pageBlock >
                            <apex:pageBlockTable value="{!taskname}" var="t" rows="3" rendered="{!taskname.size>0}">
                                <apex:column >
                                    <a href= "/{!t.id}">
                                   <!-- <apex:param name="tcIP" value="{!t.Id}" />
                                    <apex:outputLink value="{!URLFOR($Action.CloudbyzITPM__Task__c.View, t.id)}" styleClass="leftAlign" >-->{!t.Name}</a>
                                    <!--</apex:outputLink>-->
                                </apex:column>
                            </apex:pageBlockTable>
                        </apex:pageBlock>
                        <apex:commandButton styleClass="div5" value="more" action="{!redirecttoprjtskprj}"
                        />
                    </div>
                </div>
            </div>

        <div class="main_container" style="margin-top:10px">
              <div class="row top_tiles" style="text-align:center;">
            <div class="animated flipInY col-lg-4 col-md-2 col-sm-6 col-xs-12">
                <div class="tile-stats">
                    <div style="text-align:center">
                        <apex:outputLabel value="Tasks starting next week" style="color:#0A31FB;" />
                    </div>
                    <apex:pageBlock >
                         <apex:outputPanel layout="block" styleclass="container">

                        <apex:pageBlockTable value="{!taskPlan}" var="tp" rows="3" rendered="{!taskPlan.size>0}">
                            <apex:column >
                                
                                <a href= "/{!tp.id}">
                                <!--<apex:param name="tpId" value="{!tp.Id}" />
                                <apex:outputLink value="{!URLFOR($Action.CloudbyzITPM__Task__c.View, tp.id)}" styleClass="leftAlign" >-->{!tp.Name}</a>
                                <!--</apex:outputLink>-->
                            
                            </apex:column>
                        </apex:pageBlockTable>
                        </apex:outputPanel>
                    </apex:pageBlock>
                    <apex:commandButton styleClass="div5" value="more" action="{!redirecttoprjtskpln}"
                    />
                </div>
            </div>
        </div>
        </div>

Controller:-  

List<CloudbyzITPM__Task__c> taskname =  [SELECT Id,Name, CloudbyzITPM__Status__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'In Progress' and CloudbyzITPM__Project__r.Id =: recordId];
    
   public List<CloudbyzITPM__Task__c> gettaskname(){

if(taskname.size() < 3 ){
     for(integer i = 0; i <= (3 - taskname.size());){
         
          taskname.add(new CloudbyzITPM__Task__c(Name = 'N/A'));
     }
     
 }
   return taskname;
 }  

 public void gettaskinprogress(){
        if (!Schema.sObjectType.CloudbyzITPM__Task__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.id.isAccessible()
               ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.name.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Milestone__c.isAccessible()
               ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Planned_Start_Date__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Planned_End_Date__c.isAccessible()
                ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Actual_End_Date__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Actual_Start_date__c.isAccessible())
                 {
                  ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,
                                      'Insufficient access'));
                 return;
                 }
       if(currentProjectId!=null)
       currentProjectId=string.escapeSingleQuotes(currentProjectId);
       lstoftasksPrg =  [SELECT Id,Name, CloudbyzITPM__Status__c,CloudbyzITPM__Milestone__c,CloudbyzITPM__Planned_Start_Date__c,CloudbyzITPM__Planned_End_Date__c,CloudbyzITPM__Actual_Start_date__c,CloudbyzITPM__Actual_End_Date__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'In Progress' and CloudbyzITPM__Project__r.Id =: recordId];   

    } 
public List<CloudbyzITPM__Task__c> getlstoftasksPrg(){
    
    return lstoftasksPrg;
}   

  public pagereference redirecttoprjtskprj(){
        return new pagereference('/apex/projecttaskprogress?id='+currentProjectId);
    }




/* task in completed 
  List<CloudbyzITPM__Task__c> taskComp =  [SELECT Id,Name, CloudbyzITPM__Actual_End_Date__c, CloudbyzITPM__Status__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'Completed' and CloudbyzITPM__Actual_End_Date__c >=:system.today().toStartOfWeek().addDays(-7)
 and CloudbyzITPM__Actual_End_Date__c <=:system.today().toStartOfWeek().addDays(-1) and CloudbyzITPM__Project__r.Id =: recordId];
 
 public list<CloudbyzITPM__Task__c> getRows()
 {   
 List<CloudbyzITPM__Task__c> rows =  [SELECT Id,Name, CloudbyzITPM__Actual_End_Date__c, CloudbyzITPM__Status__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'Completed' and CloudbyzITPM__Actual_End_Date__c >=:system.today().toStartOfWeek().addDays(-7)
 and CloudbyzITPM__Actual_End_Date__c <=:system.today().toStartOfWeek().addDays(-1) and CloudbyzITPM__Project__r.Id =: recordId ];
 
 system.debug('@@ rows of task' + rows);
 List<CloudbyzITPM__Task__c> rows_temp = new List<CloudbyzITPM__Task__c>(rows);
 rows.clear();
 for(CloudbyzITPM__Task__c irrTask : rows_temp)
 {
     
 if(irrTask.Name.length()>10) 
 { 
     system.debug('@@ rows of task' + rows);
      irrTask.Name = irrTask.Name.substring(0,10) + '...' ; 
 } 
 rows.add(irrTask);       
 
 } 
(rows.size() < 3 ){
     for(integer i = 0; i <= (3 - rows.size());){
         rows.add(new CloudbyzITPM__Task__c(Name = 'N/A'));
     }
 }
    return rows;  
 }
public void gettaskcompleted(){
    System.debug('@@lstoftaskscmp@@');
        if (!Schema.sObjectType.CloudbyzITPM__Task__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.id.isAccessible()
               ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.name.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Milestone__c.isAccessible()
               ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Planned_Start_Date__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Planned_End_Date__c.isAccessible()
                ||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Actual_End_Date__c.isAccessible()||!Schema.sObjectType.CloudbyzITPM__Task__c.fields.CloudbyzITPM__Actual_Start_date__c.isAccessible())
              {
                 
                 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,
                                      'Insufficient access'));
                 return;
                 }
                 System.debug('@@currentProjectId@@'+currentProjectId);
    
       if(currentProjectId!=null)
       currentProjectId=string.escapeSingleQuotes(currentProjectId);
       lstoftaskscmp =   [SELECT Id,Name, CloudbyzITPM__Actual_End_Date__c,CloudbyzITPM__Milestone__c,CloudbyzITPM__Planned_Start_Date__c,CloudbyzITPM__Planned_End_Date__c ,CloudbyzITPM__Actual_Start_date__c,CloudbyzITPM__Status__c FROM  CloudbyzITPM__Task__c WHERE CloudbyzITPM__Status__c = : 'Completed' and CloudbyzITPM__Actual_End_Date__c >=:system.today().toStartOfWeek().addDays(-7)
 and CloudbyzITPM__Actual_End_Date__c <=:system.today().toStartOfWeek().addDays(-1) and CloudbyzITPM__Project__r.Id =: recordId];
    
    } 
public List<CloudbyzITPM__Task__c> getlstoftaskscmp()
{
    System.debug('@@lstoftaskscmp@@'+lstoftaskscmp);
    return lstoftaskscmp;
}   

  public pagereference redirecttoprjtskcom()
  {
        return new pagereference('/apex/projecttaskcomplete?id='+currentProjectId);
    }


   
Hi Expert,

Have to update the field 'actual hours' of "project Portfolio" object through all the roll up of the 'actual hours' of "project" object. 

iam getting an error- System.NullPointerException: Attempt to de-reference a null object: Class.updatedActualHours.processAfterUpdateActualHours: line 61, column 1

here is the code-

public class updatedActualHours 

{
  public static List<CloudbyzITPM__Project__c> affectedActualHours = new List<CloudbyzITPM__Project__c>();
    public static List<CloudbyzITPM__Project__c> oldaffectedActualHours = new List<CloudbyzITPM__Project__c>();
  public static set<ID> affc = new set<ID>();
    public static set<ID> affcold = new set<ID>();
  public static void processAfterUpdateActualHours()
 {
     affectedActualHours = (List<CloudbyzITPM__Project__c>)Trigger.New;
     oldaffectedActualHours = (List<CloudbyzITPM__Project__c>)Trigger.Old;
     if(Trigger.isDelete){
        for(CloudbyzITPM__Project__c  affc1 : oldaffectedActualHours)
     {
         if(affc1.CloudbyzITPM__Project_Portfolio__c != null)
         {
         system.debug('value of affc1'+ affc1);
        affc.add(affc1.CloudbyzITPM__Project_Portfolio__c);
     }
     }
      system.debug('this is the value'+ affc);
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Actual_Hours__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
    list<CloudbyzITPM__Project__c> affectedActualHours1 = [select id, name,CloudbyzITPM__Actual_Hours__c, CloudbyzITPM__Project_Portfolio__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
          
      Decimal j=0;
     System.debug('@@affectedActualHours1@@'+affectedActualHours1+'@@affectedActualHours1.size'+affectedActualHours1.size());  
    if(affectedActualHours1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedActualHours1)
        {
            System.debug('@@afc1.CloudbyzITPM__Actual_Hours__c@@'+afc1.CloudbyzITPM__Actual_Hours__c);
          if(afc1.CloudbyzITPM__Actual_Hours__c !=0 && afc1.CloudbyzITPM__Actual_Hours__c!=null)
            j = j + afc1.CloudbyzITPM__Actual_Hours__c;
        }
    }
    
 if(j>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Actual_Hours__c = j;
    }
          else{
              fn.CloudbyzITPM__Actual_Hours__c = 0;
          }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
    else{
     if(affectedActualHours.size()>0)
     {/*
     for(CloudbyzITPM__Project__c  affc1 : affectedActualHours)
     {
         if(affc1.CloudbyzITPM__Project_Portfolio__c != null)
         {
         system.debug('value of affc1'+ affc1);
        affc.add(affc1.CloudbyzITPM__Project_Portfolio__c);
     }
     }*/
         system.debug('@@@value of affc1'+ affectedActualHours);
         for(integer i = 0; i<affectedActualHours.size(); ++i){
         if(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null && oldaffectedActualHours[i]!= null && oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null && oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c)
         {
         system.debug('value of affc1'+ affectedActualHours[i]);
        affc.add(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c);
             affcold.add(oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c);
         }
             if(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null)
         {
         system.debug('value of affc1'+ affectedActualHours[i]);
        affc.add(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c);
         } 
             else if(affectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null && oldaffectedActualHours[i]!= null && oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c != null){
                affc.add(oldaffectedActualHours[i].CloudbyzITPM__Project_Portfolio__c); 
             }
             
         }
          if(affcold.size()>0)
      {
     system.debug('this is the value'+ affc);
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Actual_Hours__c from CloudbyzITPM__Project_Portfolio__c where id in: affcold limit 1];
    list<CloudbyzITPM__Project__c> affectedActualHours1 = [select id, name,CloudbyzITPM__Actual_Hours__c, CloudbyzITPM__Project_Portfolio__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
      
      Decimal j=0;
     System.debug('@@affectedActualHours1@@'+affectedActualHours1+'@@affectedActualHours1.size'+affectedActualHours1.size());  
    if(affectedActualHours1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedActualHours1)
        {
            System.debug('@@afc1.CloudbyzITPM__Actual_Hours__c@@'+afc1.CloudbyzITPM__Actual_Hours__c);
          if(afc1.CloudbyzITPM__Actual_Hours__c !=0 && afc1.CloudbyzITPM__Actual_Hours__c!=null)
            j = j + afc1.CloudbyzITPM__Actual_Hours__c;
        }
    }
    
 if(j>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Actual_Hours__c = j;
    }
          else{
              fn.CloudbyzITPM__Actual_Hours__c = 0;
          }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
      if(affc.size()>0)
      {
     system.debug('this is the value'+ affc);
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Actual_Hours__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
    list<CloudbyzITPM__Project__c> affectedActualHours1 = [select id, name,CloudbyzITPM__Actual_Hours__c, CloudbyzITPM__Project_Portfolio__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
      
      Decimal j=0;
     System.debug('@@affectedActualHours1@@'+affectedActualHours1+'@@affectedActualHours1.size'+affectedActualHours1.size());  
    if(affectedActualHours1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedActualHours1)
        {
            System.debug('@@afc1.CloudbyzITPM__Actual_Hours__c@@'+afc1.CloudbyzITPM__Actual_Hours__c);
          if(afc1.CloudbyzITPM__Actual_Hours__c !=0 && afc1.CloudbyzITPM__Actual_Hours__c!=null)
            j = j + afc1.CloudbyzITPM__Actual_Hours__c;
        }
    }
    
 if(j>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Actual_Hours__c = j;
    }
          else{
              fn.CloudbyzITPM__Actual_Hours__c = 0;
          }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
    }
    }
}
}User-added image


Hi Expert,

I have a scenerio in which i have to update the field "budget hours" of "project portfolio" object with the "budget hour" field of "project" object, hence 1 "project portfolio" have multiple "project", it should have all the sum of "budget hour" field into that "budget hours" of "project portfolio" object. 

But when we cange the "project portfolio" in "project" object. so in the "budget hours" field of "project portfolio" should deacreases, coz we have change the "project portfolio" of that partcular "project" and add the "budget hours" of another "project portfolio" which we have added. but it is not hapenning in my org. 

Code is here- 

public class updateBudgetedHours 
{

  public static List<CloudbyzITPM__Project__c> affectedBudgetedHours = new List<CloudbyzITPM__Project__c>();
 public static set<ID> affc = new set<ID>();
 public static void processAfterUpdateBudgetedHours()
 {
     affectedBudgetedHours = (List<CloudbyzITPM__Project__c>)Trigger.New;
     if(affectedBudgetedHours.size()>0){
     for(CloudbyzITPM__Project__c  affc1 : affectedBudgetedHours)
     {
         if(affc1.CloudbyzITPM__Project_Portfolio__c != null)
         {
      affc.add(affc1.CloudbyzITPM__Project_Portfolio__c);
     }
     }
     
    if(affc.size()>0)
    {
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name, CloudbyzITPM__Budgeted_Hours__c from CloudbyzITPM__Project_Portfolio__c where id IN :affc limit 1];
    list<CloudbyzITPM__Project__c> affectedBudgetedHours1 = [select id,name,CloudbyzITPM__Project_Portfolio__c,CloudbyzITPM__Budgeted_Hours__c from CloudbyzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
    Decimal i=0;
       
    if(affectedBudgetedHours1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedBudgetedHours1)
        {
            i = i + afc1.CloudbyzITPM__Budgeted_Hours__c;
        }
    }
    
 if(i>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Budgeted_Hours__c = i;
    }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
    
    }
 }
}

Trigger- 

Trigger UpdateBH on CloudbyzITPM__Project__c (before insert, before update, before delete,after insert, after update, after delete) 

{
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter )   
{
updateBudgetedHours.processAfterUpdateBudgetedHours();
}

if((Trigger.isDelete || Trigger.isUpdate) && Trigger.isBefore)
{
updateBudgetedHours.processAfterUpdateBudgetedHours();
}
}


what to change in the code?

Thanks & Regards,

Deepak
Hi Expert,

iam getting error when executing the trigger.

scenerio-  update the field " project risk count" of child object "Project Portfolio" with the field "risk count" of parent object "Project".

Class-

public class updateProjectRiskCount 
{
  
  public static List<CloudbyzITPM__Project__c> affectedRiskCount = new List<CloudbyzITPM__Project__c>();
  public static set<ID> affc = new set<ID>();
    

  public static void processAfterUpdateRiskCount()
 {
     affectedRiskCount = (List<CloudbyzITPM__Project__c>)Trigger.New;
     if(affectedRiskCount.size()>0){
     for(CloudbyzITPM__Project__c  affc1 : affectedRiskCount)
     {
      affc.add(affc1.id);
     }
     }
      
    CloudbyzITPM__Project_Portfolio__c fn = [select id,name,CloudbyzITPM__Project_Risk_Count__c from CloudbyzITPM__Project_Portfolio__c where id in: affc limit 1];
    list<CloudbyzITPM__Project__c> affectedRiskCount1 = [select id, name,CloudbyzITPM__Project_Portfolio__c,CloudbyzITPM__Risk_Count__c from CloudByzITPM__Project__c where CloudbyzITPM__Project_Portfolio__c = :fn.id];
      
      Decimal i=0;
       
    if(affectedRiskCount1.size()>0)
       {
           for(CloudbyzITPM__Project__C afc1 : affectedRiskCount1)
        {
            i = i + afc1.CloudbyzITPM__Risk_Count__c;
        }
    }
    
 if(i>0)
 {
     System.debug('@@pBUFinal@@');
    fn.CloudbyzITPM__Project_Risk_Count__c = i;
    }
     update fn; 
      System.debug('@@fn4@@'+fn);
    }
  
  }


Trigger- 

Trigger UpdateRC2 on CloudbyzITPM__Project__c (before insert, before update, before delete, after insert, after update, after delete)
{
  if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter)
      
  {
      updateProjectRiskCount.processAfterUpdateRiskCount();
  }
}

Note- i have written 4 triggers on the same object "project". 

Screenshot attached.

User-added image

 
Hi Expert,

There r two objects "project member" and "resource" in which under "project member" object i have to update the field "hour rate" with "resource" object field "hour cost", when something is written in "hour cost" field, otherwise "hour rate" field not update and able to enter something and save it.

my code is- 

public class updateHourlyRate
{
 public static List<CloudbyzITPM__Team_Member__c> affectedProd= new
List<CloudbyzITPM__Team_Member__c>();
 public static List<CloudbyzITPM__Team_Member__c> affectedProd_final=
new List<CloudbyzITPM__Team_Member__c>();

 public static set<ID> afc2 = new set<ID>();
 public static void processAfterUpdateOrInsertHourlyCost(){
      affectedProd = (List<CloudbyzITPM__Team_Member__c>)Trigger.New;
     if(affectedProd.size()>0){
     for(CloudbyzITPM__Team_Member__c  affc : affectedProd){
      afc2.add(affc.CloudbyzITPM__Team_Member__c);
     }
     }
     CloudbyzITPM__Resource__c fn = [Select id,
CloudbyzITPM__Hourly_Cost__c from CloudbyzITPM__Resource__c where id
IN :afc2 limit 1];
     List<CloudbyzITPM__Team_Member__c> affectedProd1 = [Select
id,name,CloudbyzITPM__Hourly_Rate__c from CloudbyzITPM__Team_Member__c
where CloudbyzITPM__Resource__c = :fn.id];
    // Decimal i =0 ;
     if(affectedProd1.size()>0){
     for(CloudbyzITPM__Team_Member__c  affc : affectedProd1){

     affc.CloudbyzITPM__Hourly_Rate__c = fn.CloudbyzITPM__Hourly_Cost__c;
    affectedProd_final.add(affc);
    }
     }

     update affectedProd_final;
 }
}

trigger- trigger HourRate on CloudbyzITPM__Resource__c (before insert, before update, before delete, after insert, after update, after delete) 
{
if((Trigger.isInsert || Trigger.isUpdate) && Trigger.isAfter)   
{
updateHourlyRate.processAfterUpdateOrInsertHourlyCost();

}

when i change the field "hourly cost" , it gives an error.
"Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger HourRate caused an unexpected exception, contact your administrator: HourRate: execution of AfterUpdate caused by: System.TypeException: Invalid conversion from runtime type List to List: Class.updateHourlyRate.processAfterUpdateOrInsertHourlyCost: line 10, column 1"
Have to update the "total actual cost field" in custom object called "project portfolio" from its associated custom object called "projects"'s fields total actual cost. means all the "total actual cost" fields of different projects associated with the "project portfolio" should come into "total actual cost" field of "project portfolio" object.

Both the objects have same fields.

API Names- 

Project- CloudbyzITPM__Project__c
Project Portfolio- CloudbyzITPM__Project_Portfolio__c
Field name- CloudbyzITPM__Total_Actual_Cost__c

below is my code and iam getting error- "Didn't understand relationship 'Projects__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names".


trigger UpdateTotalActualCosts on CloudbyzITPM__Project__c (after insert,after update, after delete,after undelete) {

  List<id> QuotationsIds = new List<id>();

    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){

        For(CloudbyzITPM__Project__c con1 : Trigger.new){

            QuotationsIds.add(con1.CloudbyzITPM__Project_Portfolio__c);

        }

    }

    if(Trigger.isDelete){

        For(CloudbyzITPM__Project__c con1 : Trigger.old){

            QuotationsIds.add(con1.CloudbyzITPM__Project_Portfolio__c);

        }

    }

    List<CloudbyzITPM__Project_Portfolio__c> QuotationsToUpdate = new List<CloudbyzITPM__Project_Portfolio__c>();

    decimal sum = 0;

    if(Trigger.isInsert || Trigger.isUndelete || Trigger.isupdate){

        For(CloudbyzITPM__Project_Portfolio__c q : [select CloudbyzITPM__Total_Actual_Cost__c,(SELECT id,CloudbyzITPM__Total_Actual_Cost__c  FROM Projects__r) FROM CloudbyzITPM__Project_Portfolio__c WHERE id =: QuotationsIds]){

            sum = 0;

            for(CloudbyzITPM__Project__c p : q.Projects__r)
                sum = sum + p.CloudbyzITPM__Total_Actual_Cost__c ;

            q.CloudbyzITPM__Total_Actual_Cost__c = sum;

            QuotationsToUpdate.add(q);

        }

        try{

            update QuotationsToUpdate ;

        }Catch(Exception e){

            System.debug('Exception :'+e.getMessage());

        }

    }

}