• Meenakshi T R
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 7
    Replies
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?
I have a problem I am not able to display distance that is aliased int he soql query in VF page. Any help?

public with sharing class GetSupplierListController 
{
     Public List <SCMC__Requisition__c> cs {get; set;}
     Public List<SCMC__Supplier_Site__c> suplist {get; set;}
      String skillset='';
      String producttype='';
      String productbrand='';
      String complexityrating='';
     public GetSupplierListController(ApexPages.StandardController sc) 
    {
        Id idCS = sc.getId();
        cs= new List<SCMC__Requisition__c>();
        suplist = new List<SCMC__Supplier_Site__c>();
        if(idCS != NULL)
        {
            cs = [SELECT Id,Name,Location__c,Location__Latitude__s,Location__Longitude__s,CTC_Skill_Set__c,CTC_Product_Brand__c,CTC_Product_Type__c,CTC_Highlift_Requirement__c,CTC_Complexity_Rating_Stars__c FROM SCMC__Requisition__c WHERE Id =: idCS];
            skillset = cs[0].CTC_Skill_Set__c;
            producttype=cs[0].CTC_Product_Type__c;
            productbrand=cs[0].CTC_Product_Brand__c;
             //highlift==cs[0].CTC_Highlift_Requirement__c;
             complexityrating=cs[0].CTC_Complexity_Rating_Stars__c;
            Location loc = cs[0].Location__c;
            Double lat = loc.latitude;
            Double lon = loc.longitude;          
            if(skillset.contains('Breakdowns'))
            {
                  // fetch supplier with matching values
            suplist = [select id,Name,Location__c,Location__Latitude__s, Distance(Location__c, GEOLOCATION(:lat,:lon), 'km') dist,Location__Longitude__s, CTC_Skill_Set__c,CTC_Product_Type__c,CTC_Product_Brands__c,CTC_High_Lift_Available__c,CTC_Breakdowns_Rating__c,CTC_Maintenance_Rating__c,CTC_New_Constuction_Rating__c,CTC_Upgrades_Rating__c from SCMC__Supplier_Site__c 
                       where CTC_Skill_Set__c includes(:skillset) AND CTC_Product_Brands__c includes(:productbrand) AND CTC_Product_Type__c includes(:producttype) AND CTC_Breakdowns_Rating__c>= :complexityrating ORDER BY Distance(Location__c, GEOLOCATION(:lat,:lon), 'km')];                
            }
            else if(skillset.contains('Maintenance'))
            {
                  // fetch supplier with matching values
            suplist = [select id,Name,Location__c,Location__Latitude__s,Location__Longitude__s,Distance(Location__c, GEOLOCATION(:lat,:lon), 'km') dist, CTC_Skill_Set__c,CTC_Product_Type__c,CTC_Product_Brands__c,CTC_High_Lift_Available__c,CTC_Maintenance_Rating__c,CTC_Breakdowns_Rating__c,CTC_New_Constuction_Rating__c,CTC_Upgrades_Rating__c from SCMC__Supplier_Site__c 
                       where CTC_Skill_Set__c includes(:skillset) AND CTC_Product_Brands__c includes(:productbrand) AND CTC_Product_Type__c includes(:producttype) AND CTC_Maintenance_Rating__c>= :complexityrating ORDER BY Distance(Location__c, GEOLOCATION(:lat,:lon), 'km')];                
            }
            
            else if(skillset.contains('New Construction'))
            {
                  // fetch supplier with matching values
            suplist = [select id,Name,Location__c,Location__Latitude__s,Location__Longitude__s, Distance(Location__c, GEOLOCATION(:lat,:lon), 'km') dist,CTC_Skill_Set__c,CTC_Product_Type__c,CTC_Product_Brands__c,CTC_High_Lift_Available__c,CTC_New_Constuction_Rating__c,CTC_Maintenance_Rating__c,CTC_Breakdowns_Rating__c,CTC_Upgrades_Rating__c from SCMC__Supplier_Site__c 
                       where CTC_Skill_Set__c includes(:skillset) AND CTC_Product_Brands__c includes(:productbrand) AND CTC_Product_Type__c includes(:producttype) AND CTC_New_Constuction_Rating__c>= :complexityrating ORDER BY Distance(Location__c, GEOLOCATION(:lat,:lon), 'km')]; 
                
            }
            else if(skillset.contains('Upgrades'))
            {
                  // fetch supplier with matching values
            suplist = [select id,Name,Location__c,Location__Latitude__s,Location__Longitude__s,Distance(Location__c, GEOLOCATION(:lat,:lon), 'km') dist, CTC_Skill_Set__c,CTC_Product_Type__c,CTC_Product_Brands__c,CTC_High_Lift_Available__c,CTC_Upgrades_Rating__c,CTC_New_Constuction_Rating__c,CTC_Maintenance_Rating__c,CTC_Breakdowns_Rating__c from SCMC__Supplier_Site__c 
                       where CTC_Skill_Set__c includes(:skillset) AND CTC_Product_Brands__c includes(:productbrand) AND CTC_Product_Type__c includes(:producttype) AND CTC_Upgrades_Rating__c>= :complexityrating ORDER BY Distance(Location__c, GEOLOCATION(:lat,:lon), 'km')]; 
                
            }

        }
    }
}
I have a requirement where I have to copy the pdf in Notes and Attachments of Parent object to Files in Child object when it is created. It gets created when the status of the parent object changes to InApproval. My code is

trigger CopyAttachmentsToPIN on Attachment (after insert) {
      Set<Id> bcIds = new Set<Id>();
      for(Attachment file : Trigger.new) 
      {
            // only collect those that are for the InvoiceScan object (others can be ignored)
            if(file.ParentId.getSObjectType() == CTPISA__BookingCapture__c.getSObjectType()) 
            {
                bcIds.add(file.ParentId);
                system.debug(bcIds);
            }
       }
    
    if(!bcIds.isEmpty()) 
    {
                Map<Id,c2g__codaPurchaseInvoice__c> ruMap = new Map<Id,c2g__codaPurchaseInvoice__c>();
                List<Attachment> attachments = new List<Attachment>();
                for(c2g__codaPurchaseInvoice__c obj : [select Id, CTPISA__BookingCapture__c from c2g__codaPurchaseInvoice__c where CTPISA__BookingCapture__c in : bcIds])
                {
                    ruMap.put(obj.CTPISA__BookingCapture__c, obj);
                }
                for(Attachment file : Trigger.new)
                {
                        if(ruMap.containsKey(file.ParentId))
                        {
                            Attachment newFile = file.clone(false);
                            newFile.ParentId = ruMap.get(file.ParentId).Id;
                            attachments.add(newFile);
                        }
                }
        // finally, insert the cloned attachments
        insert attachments;   

    }


}

I need to insert the attachments as Files now it's getting attached as Attachments in Child Object. Any idea?
trigger

 
Hello all,

I have a requirement where Hi I am trying to induce a validation in custom object. The condition if InvoiceTotal">25000 then either second level approver field OR third level apporver field must have Specht or Waterweg. Looks like if I satisfy one condition the other is not getting satisfied. Any help?

IF( OR(NOT(OR(
AND( CTPISA__InvoiceTotalVATIncluded__c >= 25000, NOT(CONTAINS( Second_Level_Approver__r.LastName , "Specht")) , NOT(CONTAINS( Second_Level_Approver__r.LastName , "Waterweg"))),
AND( CTPISA__InvoiceTotalVATIncluded__c >= 25000, NOT(CONTAINS( Third_Level_Approver__r.LastName , "Specht")) , NOT(CONTAINS( Third_Level_Approver__r.LastName , "Waterweg"))))),AND(CTPISA__InvoiceTotalVATIncluded__c >= 25000,OR(NOT(CONTAINS( Second_Level_Approver__r.LastName , "Specht")),NOT(CONTAINS( Second_Level_Approver__r.LastName , "Waterweg"))),
OR(NOT(CONTAINS( Third_Level_Approver__r.LastName , "Specht")),NOT(CONTAINS( Third_Level_Approver__r.LastName , "Waterweg"))))), true, false)
I have a class on object project. It has two fields start date and end date. So when the start date and end date are entered then a new subproject (It is also the same project object) with the same start date and end date gets created. 
Now the logic in the class runs something like this
1. When the end date of the project(parent) is changed to next year then a new subproject needs to be created- This is working as expected.
2.The problem with this logic is when end date of the project is changed to a same year then also subproject is getting created taking the end date of the previous project as the start date and given a new end date.

So my query is it possible to change the end date of the first subproject according to our scenarios
1. When the new end date is in next year then the end date of the first subproject should become the last day of the year.
2. When the end date is in the same year then no creation of a new subproject just update the existing subproject's end date.

It is invoked by after update after insert trigger
I have the field Contract_Start date in Contract object and Monthlysalary__c in the same object. I have an Apex class where I calculate salary proposals based on fields in the Contract object. Everything works fine except when the start date is in the middle of the month I need to calculate the number of days remaining in the month and divide it with Monthly salary so that I get the correct value. Any ideas to do this?? I need to figure out the if the condition that if Contract_Startdate is not beginning of the month then calculate the number of days left in the month. I input only month and year in the VF page and retrieve all active contracts. Any Idea??

```java
public with sharing class Ct_SearchEmployeeContracts
{

    //Our collection of the class/wrapper objects cContact 
    public List<cContract> wcontracts {get; set;}
    public String month { get; set; }
    public String year { get; set; }
    List<Employee_Contract__c> sel_contracts = new List<Employee_Contract__c>();

    // Constructor
    public Ct_SearchEmployeeContracts(){  
        year      = String.valueOf(System.today().year());
        month     = String.valueOf(System.today().month());
      //  contracts = new List<Employee_Contract__c>();
        wcontracts= new List<cContract>();
    }
    public List<SelectOption> getyearList () 
    {
        Date today = System.today();
        String y0 = String.valueOf(today.year()), y1 = String.valueOf(today.year() -1), y2 = String.valueOf(today.year() -2), y3 = String.valueOf(today.year() -3) ,y4 = String.valueOf(today.year() +1),y5 = String.valueOf(today.year() +2),y6 = String.valueOf(today.year() +3);
        return new List<SelectOption>
        {
            new SelectOption(y0, y0),
            new SelectOption(y1, y1),
            new SelectOption(y2, y2),
            new SelectOption(y3, y3),
            new SelectOption(y4, y4),
            new SelectOption(y5, y5),
            new SelectOption(y6, y6)
        };
}
    
    public PageReference searchContracts()
    {     
       List<Employee_Contract__c> temp_contracts = new List<Employee_Contract__c>();
        
        if (month!=Null && year!=Null)
        {
           temp_contracts =[Select Id,(Select id,Name from Salary_Proposals__r), Name, First_Name__c, 
                            Last_Name__c, Employee_ID__c,Contract_End_Date__c ,Contract_End_Month__c,
                            Contract_End_Year__c,Contract_Start_Date__c,Contract_Start_Month__c, 
                            Contract_Start_Year__c,Active__c,MonthlySalary__c,Retirement_Contribution__c,
                            Voluntary_Retirement_Contribution__c,CurrencyIsoCode
                            from Employee_Contract__c 
                            where (Active__c = True AND
                            Contract_Start_Year__c <= :year AND Contract_End_Year__c >= :year)];
                            system.debug('Temp contracts size:' +temp_contracts);
        }
         System.debug('tEMP_cONTRACTS SIZE:' + temp_contracts); 
        if (temp_contracts.size() == 0)
        { 
        ApexPages.addMessage(new apexpages.message(ApexPages.Severity.WARNING, 'No Active contracts found in the given period'));
        }
        if (temp_contracts.size() > 0)
        {
            for (Employee_Contract__c tc : temp_contracts)
            {
                Integer given_year_month = (Integer.valueOf(year) * 100) + Integer.valueOf(month);
                Integer tc_contract_end = ((Integer.valueOf(tc.Contract_End_Year__c)) * 100) + Integer.valueOf(tc.Contract_End_Month__c);
                Integer tc_contract_start=((Integer.valueOf(tc.Contract_Start_Year__c)) * 100) + Integer.valueOf(tc.Contract_Start_Month__c);
                system.debug('given_year_month:' +given_year_month);
                  system.debug('tc_contract_end :' +tc_contract_end );
                if (tc_contract_end >= given_year_month && tc_contract_start<=given_year_month )
                {
                    wcontracts.add(new cContract(tc));
                }  
             }                                            
        }
  
        return null;         
    }

    public PageReference insertSalaryProposals() 
    {
     //We create a new list of Contracts that we be populated only with Contracts if they are selected
       List<Employee_Contract__c> sel_contracts = new List<Employee_Contract__c>();
        //We will cycle through our list of Contracts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
           system.debug(wcontracts); 
      for(cContract Ccon: wcontracts) 
      {
        if(Ccon.selected == true) 
        {
            sel_contracts.add(cCon.con);
        }  
        if(Ccon.selected == False) 
        {
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select a contract to generate salry proposals')); 
        }          
       system.debug(sel_contracts); 
      }
    try
    {
        if(sel_contracts.size()>0)
        { 
        List<Salary_Proposal__c> sals= new list<Salary_Proposal__c>();
        for(Employee_Contract__c con: sel_contracts)
        {
        system.debug(con);
         Salary_Proposal__c prop = new Salary_Proposal__c
         (Employee_Contract__c=con.id,
         Name= month+'/'+ year +'/'+ con.First_Name__c+' '+con.Last_Name__c+'/'+con.Employee_ID__c,
         Monthly_Salary__c= con.Annual_Salary__c, 
         Retirement_Contribution__c=con.Retirement_Contribution__c,
         Voluntary_Retirement_Contribution__c=con.Voluntary_Retirement_Contribution__c,
         CurrencyIsoCode=con.CurrencyIsoCode,
         Month__c= month,
         Year__c=  year
         );        
         sals.add(prop);
        }
    system.debug(sals);
    insert sals;
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Salary Proposal for the selected contracts has been generated')); 
       }
    }
    catch(DmlException e) 
    {
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Check the contract(s)')); 
     }
      return null;
   }
    
    public class cContract {
    public Employee_Contract__c con {get; set;}
    public Boolean selected {get; set;}

    //This is the contructor method. When we create a new cContract object we pass a Contract that is set to the con property. We also set the selected value to false
    public cContract(Employee_Contract__c c) {
        con = c;
        selected = false;
    }
}
public pageReference reset()    {
  //  inputId = false;
      this.wcontracts =new List<cContract>();
      return null;    }
}

```
I need an idea. I have VF page and controller. When I enter Year and Month in the VF page I get the all the records that are active from an object called contract. I have also included the checkbox script in my code and controller has a wrapper list that holds the id's of selected contracts.
My main concern is to to pass the selcted contracts id to a batch class where I should calculate the fields of another object that has master detail relation with contract object. Is it possible? Any ideas??

My Controller code is

Code on 17/08/2020--- Before batch class execution


public with sharing class Ct_SearchEmployeeContracts
{

    //Our collection of the class/wrapper objects cContract 
    public List<cContract> wcontracts {get; set;}
    public String month { get; set; }
    public String year { get; set; }

    // Constructor
    public Ct_SearchEmployeeContracts(){  
        year      = String.valueOf(System.today().year());
        month     = String.valueOf(System.today().month());
      //  contracts = new List<Employee_Contract__c>();
        wcontracts= new List<cContract>();
    }
    public List<SelectOption> getyearList () 
    {
        Date today = System.today();
        String y0 = String.valueOf(today.year()), y1 = String.valueOf(today.year() -1);
        return new List<SelectOption>
        {
            new SelectOption(y0, y0),
            new SelectOption(y1, y1)
        };
}    
    public PageReference searchContracts()
    {     
       List<Employee_Contract__c> temp_contracts = new List<Employee_Contract__c>();
        
        if (month!=Null && year!=Null)
        {
           temp_contracts =[Select Id, Name, First_Name__c, Last_Name__c, Employee_ID__c,Contract_End_Date__c,Contract_End_Month__c, Contract_End_Year__c,Contract_Start_Date__c,Contract_Start_Month__c, Contract_Start_Year__c,Active__c
                            from Employee_Contract__c 
                            where Active__c = True AND
                            Contract_Start_Year__c <= :year AND Contract_End_Year__c >= :year ];
                            system.debug('Temp contracts size:' +temp_contracts);
        }
         System.debug('tEMP_cONTRACTS SIZE:' + temp_contracts); 
        
        if (temp_contracts.size() > 0)
        {
            for (Employee_Contract__c tc : temp_contracts)
            {
                Integer given_year_month = (Integer.valueOf(year) * 100) + Integer.valueOf(month);
                Integer tc_contract_end = ((Integer.valueOf(tc.Contract_End_Year__c)) * 100) + Integer.valueOf(tc.Contract_End_Month__c);
                Integer tc_contract_start=((Integer.valueOf(tc.Contract_Start_Year__c)) * 100) + Integer.valueOf(tc.Contract_Start_Month__c);
                system.debug('given_year_month:' +given_year_month);
                  system.debug('tc_contract_end :' +tc_contract_end );
                if (tc_contract_end >= given_year_month && tc_contract_start<=given_year_month )
                {
                    wcontracts.add(new cContract(tc));
                }
                else{
                     ApexPages.addMessage(new apexpages.message(ApexPages.Severity.WARNING, 'No contracts found in the given period'));
                }    
             }                                            
        }
  
        return null;         
    }
    public PageReference generateSalaryProposals() 
    {
        //We create a new list of Contracts that we be populated only with Contracts if they are selected
         List<Employee_Contract__c> sel_contracts = new List<Employee_Contract__c>();
        //We will cycle through our list of Contracts and will check to see if the selected property is set to true, if it is we add the Contract to the selectedContracts list
       for(cContract Ccon: wcontracts) {
        if(Ccon.selected == true) {
            sel_contracts.add(cCon.con);
        }
    }
        for(Employee_Contract__c con: sel_contracts) {
        system.debug(con);
    }
        wcontracts=null;
        return null;
    }
    public class cContract {
    public Employee_Contract__c con {get; set;}
    public Boolean selected {get; set;}

    //This is the contructor method. When we create a new cContract object we pass a Contract that is set to the con property. We also set the selected value to false
    public cContract(Employee_Contract__c c) {
        con = c;
        selected = false;
    }
}
}
 
I have a requirement. I have a Contract object which Contract start date and end date created and Active checkbox for Employees(from Employee object). I have a Custom VF page where I need to select a month and year and based on my selection all the employee names with active contracts in the particular month should come up and I need to select to which all employees should I run a batch job which calculates the salary proposal and it attached to the related list of contract object dynamically. Any ideas??
I have a problem I am not able to display distance that is aliased int he soql query in VF page. Any help?

public with sharing class GetSupplierListController 
{
     Public List <SCMC__Requisition__c> cs {get; set;}
     Public List<SCMC__Supplier_Site__c> suplist {get; set;}
      String skillset='';
      String producttype='';
      String productbrand='';
      String complexityrating='';
     public GetSupplierListController(ApexPages.StandardController sc) 
    {
        Id idCS = sc.getId();
        cs= new List<SCMC__Requisition__c>();
        suplist = new List<SCMC__Supplier_Site__c>();
        if(idCS != NULL)
        {
            cs = [SELECT Id,Name,Location__c,Location__Latitude__s,Location__Longitude__s,CTC_Skill_Set__c,CTC_Product_Brand__c,CTC_Product_Type__c,CTC_Highlift_Requirement__c,CTC_Complexity_Rating_Stars__c FROM SCMC__Requisition__c WHERE Id =: idCS];
            skillset = cs[0].CTC_Skill_Set__c;
            producttype=cs[0].CTC_Product_Type__c;
            productbrand=cs[0].CTC_Product_Brand__c;
             //highlift==cs[0].CTC_Highlift_Requirement__c;
             complexityrating=cs[0].CTC_Complexity_Rating_Stars__c;
            Location loc = cs[0].Location__c;
            Double lat = loc.latitude;
            Double lon = loc.longitude;          
            if(skillset.contains('Breakdowns'))
            {
                  // fetch supplier with matching values
            suplist = [select id,Name,Location__c,Location__Latitude__s, Distance(Location__c, GEOLOCATION(:lat,:lon), 'km') dist,Location__Longitude__s, CTC_Skill_Set__c,CTC_Product_Type__c,CTC_Product_Brands__c,CTC_High_Lift_Available__c,CTC_Breakdowns_Rating__c,CTC_Maintenance_Rating__c,CTC_New_Constuction_Rating__c,CTC_Upgrades_Rating__c from SCMC__Supplier_Site__c 
                       where CTC_Skill_Set__c includes(:skillset) AND CTC_Product_Brands__c includes(:productbrand) AND CTC_Product_Type__c includes(:producttype) AND CTC_Breakdowns_Rating__c>= :complexityrating ORDER BY Distance(Location__c, GEOLOCATION(:lat,:lon), 'km')];                
            }
            else if(skillset.contains('Maintenance'))
            {
                  // fetch supplier with matching values
            suplist = [select id,Name,Location__c,Location__Latitude__s,Location__Longitude__s,Distance(Location__c, GEOLOCATION(:lat,:lon), 'km') dist, CTC_Skill_Set__c,CTC_Product_Type__c,CTC_Product_Brands__c,CTC_High_Lift_Available__c,CTC_Maintenance_Rating__c,CTC_Breakdowns_Rating__c,CTC_New_Constuction_Rating__c,CTC_Upgrades_Rating__c from SCMC__Supplier_Site__c 
                       where CTC_Skill_Set__c includes(:skillset) AND CTC_Product_Brands__c includes(:productbrand) AND CTC_Product_Type__c includes(:producttype) AND CTC_Maintenance_Rating__c>= :complexityrating ORDER BY Distance(Location__c, GEOLOCATION(:lat,:lon), 'km')];                
            }
            
            else if(skillset.contains('New Construction'))
            {
                  // fetch supplier with matching values
            suplist = [select id,Name,Location__c,Location__Latitude__s,Location__Longitude__s, Distance(Location__c, GEOLOCATION(:lat,:lon), 'km') dist,CTC_Skill_Set__c,CTC_Product_Type__c,CTC_Product_Brands__c,CTC_High_Lift_Available__c,CTC_New_Constuction_Rating__c,CTC_Maintenance_Rating__c,CTC_Breakdowns_Rating__c,CTC_Upgrades_Rating__c from SCMC__Supplier_Site__c 
                       where CTC_Skill_Set__c includes(:skillset) AND CTC_Product_Brands__c includes(:productbrand) AND CTC_Product_Type__c includes(:producttype) AND CTC_New_Constuction_Rating__c>= :complexityrating ORDER BY Distance(Location__c, GEOLOCATION(:lat,:lon), 'km')]; 
                
            }
            else if(skillset.contains('Upgrades'))
            {
                  // fetch supplier with matching values
            suplist = [select id,Name,Location__c,Location__Latitude__s,Location__Longitude__s,Distance(Location__c, GEOLOCATION(:lat,:lon), 'km') dist, CTC_Skill_Set__c,CTC_Product_Type__c,CTC_Product_Brands__c,CTC_High_Lift_Available__c,CTC_Upgrades_Rating__c,CTC_New_Constuction_Rating__c,CTC_Maintenance_Rating__c,CTC_Breakdowns_Rating__c from SCMC__Supplier_Site__c 
                       where CTC_Skill_Set__c includes(:skillset) AND CTC_Product_Brands__c includes(:productbrand) AND CTC_Product_Type__c includes(:producttype) AND CTC_Upgrades_Rating__c>= :complexityrating ORDER BY Distance(Location__c, GEOLOCATION(:lat,:lon), 'km')]; 
                
            }

        }
    }
}
I have a requirement where I have to copy the pdf in Notes and Attachments of Parent object to Files in Child object when it is created. It gets created when the status of the parent object changes to InApproval. My code is

trigger CopyAttachmentsToPIN on Attachment (after insert) {
      Set<Id> bcIds = new Set<Id>();
      for(Attachment file : Trigger.new) 
      {
            // only collect those that are for the InvoiceScan object (others can be ignored)
            if(file.ParentId.getSObjectType() == CTPISA__BookingCapture__c.getSObjectType()) 
            {
                bcIds.add(file.ParentId);
                system.debug(bcIds);
            }
       }
    
    if(!bcIds.isEmpty()) 
    {
                Map<Id,c2g__codaPurchaseInvoice__c> ruMap = new Map<Id,c2g__codaPurchaseInvoice__c>();
                List<Attachment> attachments = new List<Attachment>();
                for(c2g__codaPurchaseInvoice__c obj : [select Id, CTPISA__BookingCapture__c from c2g__codaPurchaseInvoice__c where CTPISA__BookingCapture__c in : bcIds])
                {
                    ruMap.put(obj.CTPISA__BookingCapture__c, obj);
                }
                for(Attachment file : Trigger.new)
                {
                        if(ruMap.containsKey(file.ParentId))
                        {
                            Attachment newFile = file.clone(false);
                            newFile.ParentId = ruMap.get(file.ParentId).Id;
                            attachments.add(newFile);
                        }
                }
        // finally, insert the cloned attachments
        insert attachments;   

    }


}

I need to insert the attachments as Files now it's getting attached as Attachments in Child Object. Any idea?
trigger

 
I have a class on object project. It has two fields start date and end date. So when the start date and end date are entered then a new subproject (It is also the same project object) with the same start date and end date gets created. 
Now the logic in the class runs something like this
1. When the end date of the project(parent) is changed to next year then a new subproject needs to be created- This is working as expected.
2.The problem with this logic is when end date of the project is changed to a same year then also subproject is getting created taking the end date of the previous project as the start date and given a new end date.

So my query is it possible to change the end date of the first subproject according to our scenarios
1. When the new end date is in next year then the end date of the first subproject should become the last day of the year.
2. When the end date is in the same year then no creation of a new subproject just update the existing subproject's end date.

It is invoked by after update after insert trigger
I have the field Contract_Start date in Contract object and Monthlysalary__c in the same object. I have an Apex class where I calculate salary proposals based on fields in the Contract object. Everything works fine except when the start date is in the middle of the month I need to calculate the number of days remaining in the month and divide it with Monthly salary so that I get the correct value. Any ideas to do this?? I need to figure out the if the condition that if Contract_Startdate is not beginning of the month then calculate the number of days left in the month. I input only month and year in the VF page and retrieve all active contracts. Any Idea??

```java
public with sharing class Ct_SearchEmployeeContracts
{

    //Our collection of the class/wrapper objects cContact 
    public List<cContract> wcontracts {get; set;}
    public String month { get; set; }
    public String year { get; set; }
    List<Employee_Contract__c> sel_contracts = new List<Employee_Contract__c>();

    // Constructor
    public Ct_SearchEmployeeContracts(){  
        year      = String.valueOf(System.today().year());
        month     = String.valueOf(System.today().month());
      //  contracts = new List<Employee_Contract__c>();
        wcontracts= new List<cContract>();
    }
    public List<SelectOption> getyearList () 
    {
        Date today = System.today();
        String y0 = String.valueOf(today.year()), y1 = String.valueOf(today.year() -1), y2 = String.valueOf(today.year() -2), y3 = String.valueOf(today.year() -3) ,y4 = String.valueOf(today.year() +1),y5 = String.valueOf(today.year() +2),y6 = String.valueOf(today.year() +3);
        return new List<SelectOption>
        {
            new SelectOption(y0, y0),
            new SelectOption(y1, y1),
            new SelectOption(y2, y2),
            new SelectOption(y3, y3),
            new SelectOption(y4, y4),
            new SelectOption(y5, y5),
            new SelectOption(y6, y6)
        };
}
    
    public PageReference searchContracts()
    {     
       List<Employee_Contract__c> temp_contracts = new List<Employee_Contract__c>();
        
        if (month!=Null && year!=Null)
        {
           temp_contracts =[Select Id,(Select id,Name from Salary_Proposals__r), Name, First_Name__c, 
                            Last_Name__c, Employee_ID__c,Contract_End_Date__c ,Contract_End_Month__c,
                            Contract_End_Year__c,Contract_Start_Date__c,Contract_Start_Month__c, 
                            Contract_Start_Year__c,Active__c,MonthlySalary__c,Retirement_Contribution__c,
                            Voluntary_Retirement_Contribution__c,CurrencyIsoCode
                            from Employee_Contract__c 
                            where (Active__c = True AND
                            Contract_Start_Year__c <= :year AND Contract_End_Year__c >= :year)];
                            system.debug('Temp contracts size:' +temp_contracts);
        }
         System.debug('tEMP_cONTRACTS SIZE:' + temp_contracts); 
        if (temp_contracts.size() == 0)
        { 
        ApexPages.addMessage(new apexpages.message(ApexPages.Severity.WARNING, 'No Active contracts found in the given period'));
        }
        if (temp_contracts.size() > 0)
        {
            for (Employee_Contract__c tc : temp_contracts)
            {
                Integer given_year_month = (Integer.valueOf(year) * 100) + Integer.valueOf(month);
                Integer tc_contract_end = ((Integer.valueOf(tc.Contract_End_Year__c)) * 100) + Integer.valueOf(tc.Contract_End_Month__c);
                Integer tc_contract_start=((Integer.valueOf(tc.Contract_Start_Year__c)) * 100) + Integer.valueOf(tc.Contract_Start_Month__c);
                system.debug('given_year_month:' +given_year_month);
                  system.debug('tc_contract_end :' +tc_contract_end );
                if (tc_contract_end >= given_year_month && tc_contract_start<=given_year_month )
                {
                    wcontracts.add(new cContract(tc));
                }  
             }                                            
        }
  
        return null;         
    }

    public PageReference insertSalaryProposals() 
    {
     //We create a new list of Contracts that we be populated only with Contracts if they are selected
       List<Employee_Contract__c> sel_contracts = new List<Employee_Contract__c>();
        //We will cycle through our list of Contracts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
           system.debug(wcontracts); 
      for(cContract Ccon: wcontracts) 
      {
        if(Ccon.selected == true) 
        {
            sel_contracts.add(cCon.con);
        }  
        if(Ccon.selected == False) 
        {
           ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select a contract to generate salry proposals')); 
        }          
       system.debug(sel_contracts); 
      }
    try
    {
        if(sel_contracts.size()>0)
        { 
        List<Salary_Proposal__c> sals= new list<Salary_Proposal__c>();
        for(Employee_Contract__c con: sel_contracts)
        {
        system.debug(con);
         Salary_Proposal__c prop = new Salary_Proposal__c
         (Employee_Contract__c=con.id,
         Name= month+'/'+ year +'/'+ con.First_Name__c+' '+con.Last_Name__c+'/'+con.Employee_ID__c,
         Monthly_Salary__c= con.Annual_Salary__c, 
         Retirement_Contribution__c=con.Retirement_Contribution__c,
         Voluntary_Retirement_Contribution__c=con.Voluntary_Retirement_Contribution__c,
         CurrencyIsoCode=con.CurrencyIsoCode,
         Month__c= month,
         Year__c=  year
         );        
         sals.add(prop);
        }
    system.debug(sals);
    insert sals;
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Salary Proposal for the selected contracts has been generated')); 
       }
    }
    catch(DmlException e) 
    {
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Check the contract(s)')); 
     }
      return null;
   }
    
    public class cContract {
    public Employee_Contract__c con {get; set;}
    public Boolean selected {get; set;}

    //This is the contructor method. When we create a new cContract object we pass a Contract that is set to the con property. We also set the selected value to false
    public cContract(Employee_Contract__c c) {
        con = c;
        selected = false;
    }
}
public pageReference reset()    {
  //  inputId = false;
      this.wcontracts =new List<cContract>();
      return null;    }
}

```
I have a requirement. I have a Contract object which Contract start date and end date created and Active checkbox for Employees(from Employee object). I have a Custom VF page where I need to select a month and year and based on my selection all the employee names with active contracts in the particular month should come up and I need to select to which all employees should I run a batch job which calculates the salary proposal and it attached to the related list of contract object dynamically. Any ideas??