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

Date change to current year

Hello 

 

I am trying to populate rates (custom table) based on product code into Account.  Rate have begin and end dates. I am writting a trigger to update rates. To get correct rates I need to covert contract_Start__c to current year like change 4/1/2008 ro 4/1/2011

 

How can I change any date mm/dd/yyyy to mm/dd/2011 ( current year)

 

Rate Table

Begin date - 1/1/2010       End date 12/31/2011     Rate: $114.56

 

Account field Contact start date sample data

4/1/2008

1/1/2009

5/1/2010

 

Here is my query so far

 

public static void UpdateProductRates(Account [] accs){
  SELECT E_Rate__c, E2_Rate__c Rate_Table_ID__c, Id, Start_Date__c   FROM Product_Rate__c where Rate_Table_Id__c IN : accs.product_code__c) AND .... this where I am stuck

 

 

How can I change date in the list accs?  

My filter should look like       accs.contract_start__c > product_rate__c.start_date__c  and Contract_start__c < product_rate__c.end_date__c

Any pointers on how this can be done.  the tough part is to make my SOQL bulk 

Thanks for your time.

 

FromCRMWonderlandFromCRMWonderland
As you correctly pointed out ... most difficult part is "BULK" in query. Here is my thought....... get " Lowest_Acct_Contract_start_date" among all accounts you have Then get " Highest_Acct_Contract_start_date" among all accounts you have Get all "Product_Rate__c" records which lie in between these two dates. After fetching all records from Query, identify appropriate corresponding "Product_Rate__c" records for each account using some loop. So, Last part (wher u stuck up) will look like -------- Lowest_Acct_Contract_start_date > product_rate__c.start_date__c and Highest_Acct_Contract_start_date < product_rate__c.end_date__c --- alok