+ Start a Discussion
SFDC n12SFDC n12 

SOQL Query Help needed

Hi,

I need help on the following requirement to write a SOQL Query


1) I am having 4 picklist fields as follows

ADR MONTH, ADR MOVE FROM MONTH, ADR YEARS, ADR MOVE FROM YEARS


ADR MONTH and ADR MOVE FROM MONTH represents the month picklist values from 01 to12


ADR YEARS AND ADR MOVE FROM YEARS represents years from 2013 to 2020


My requirement is when i enter the value  for the above picklist fields 


eg: ADR MONTH i select todays month (10/2014) and ADR FROM MONTH i select (9/2013) exactly 13 months then i have another field called as


Executive Approval Reasons  which should be set as "Yes"


if i select ADR MONTH as todays month (10/2014) and ADR FROM MONTH as (8/2013) which is less than 13 months then the picklist field 


Executive Approval Reasons  which should be set as "No"


Help me how to achieve this


Thanks in Advance
Best Answer chosen by SFDC n12
Shashikant SharmaShashikant Sharma
for this sample code will be 
Say your fields are on Account object, if it is not then change the Object API name :

for(Account acc : [ Select Id, ADR_MONTH__c, ADR_FROM_MONTH__c From Account Where ADR_MONTH__c !=: NULL AND ADR_FROM_MONTH__c !=: NULL] ) {

// do calcualtions for month difference from acc instance and do your actions

}

All Answers

Shashikant SharmaShashikant Sharma
If you want to compare two field values in SOQL you can not do it. Field API names only come in left hand sid ein a SOQL. You have to fetch the recors and then do a for loop for comparision and based on camparison you could assign values.
SFDC n12SFDC n12
please help me with the sample code 
Shashikant SharmaShashikant Sharma
for this sample code will be 
Say your fields are on Account object, if it is not then change the Object API name :

for(Account acc : [ Select Id, ADR_MONTH__c, ADR_FROM_MONTH__c From Account Where ADR_MONTH__c !=: NULL AND ADR_FROM_MONTH__c !=: NULL] ) {

// do calcualtions for month difference from acc instance and do your actions

}
This was selected as the best answer
SFDC n12SFDC n12
Thanks dude , i will try that

I also have another query which i need ur help

I am having a approval process which is having 4 stages of approver

i want to capture the comments enterd by the 3 level of approver alone (not any other apperover) in a custom  field 

Help me how to achieve it

Thanks in Advance