You need to sign in to do that
Don't have an account?
moverdorf
Custom Settings Question
I have the following custom setting: Payout__AH_FromToDate__c
I created two values in the Custom Settings panel:
payout__AH_From_Date__c
payout__AH_To_Date__c
In my APEX Class code:
237 Date frmdte;
238 Date todte;
239 frmdte = payout__AH_FromToDate__c.getValues('payout__AH_From_Date__c');
240 todte = payout__AH_FromToDate__c.getValues('payout__AH_To_Date__c');
241 DateInput1.ActivityDate = frmdte;
242 DateInput2.ActivityDate = todte;
Error: Compile Error: Illegal assignment from SOBJECT:payout__AH_FromToDate__c to Date at line 239 column 9
Can someone help me out as to what I need to do so that I can assign frmdte and todte to my custom setting date values?
Thanks.
I created two values in the Custom Settings panel:
payout__AH_From_Date__c
payout__AH_To_Date__c
In my APEX Class code:
237 Date frmdte;
238 Date todte;
239 frmdte = payout__AH_FromToDate__c.getValues('payout__AH_From_Date__c');
240 todte = payout__AH_FromToDate__c.getValues('payout__AH_To_Date__c');
241 DateInput1.ActivityDate = frmdte;
242 DateInput2.ActivityDate = todte;
Error: Compile Error: Illegal assignment from SOBJECT:payout__AH_FromToDate__c to Date at line 239 column 9
Can someone help me out as to what I need to do so that I can assign frmdte and todte to my custom setting date values?
Thanks.
It seems that Apex Code doesn't gets the default values calculated. If it wasn't a formula you could get field's default value like this:
In your case it is a formula so I don't see how you can get the default value. However you can add an if/else condition to reproduce what the default values were supposed to do:
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
All Answers
Can you share your entire code so we can have a look? You can disguise names if needed.
Regards.
Try the below code
Date frmdte;
Date todte;
List<payout__AH_FromToDate__c> lstSettng = payout__AH_FromToDate__c.getAll().Values();
if(!lstSettng.isEmpty()){
frmdte = lstSettng[0].payout__AH_From_Date__c;
todte = lstSettng[0].payout__AH_To_Date__c;
}
DateInput1.ActivityDate = frmdte;
DateInput2.ActivityDate = todte;
Regards,
Bhanu Mahesh
I assume that your custom settings is of type LIST:
One way is to get Values is in list:
Another way is:
I tried the following:
Date frmdte;
Date todte;
List<payout__AH_FromToDate__c> lstSettng = payout__AH_FromToDate__c.getAll().Values();
if(!lstSettng.isEmpty()){
frmdte = lstSettng[0].payout__AH_From_Date__c;
todte = lstSettng[0].payout__AH_To_Date__c;
}
DateInput1.ActivityDate = frmdte;
DateInput2.ActivityDate = todte;
And lstSettng is empty (null) for some reason... I assumed that when I defined the values for the custom setting I made the default value Date()-10 and Date()+10. Does setting the default value automatically mean that lstSettng should now have values in the list when the object is created? Or do I need to populate it another way?
Thanks guys.
It seems that Apex Code doesn't gets the default values calculated. If it wasn't a formula you could get field's default value like this:
In your case it is a formula so I don't see how you can get the default value. However you can add an if/else condition to reproduce what the default values were supposed to do:
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
So it sounds like instead of using the formula to create the value, I need to hard code a value value like 7 or 9 and then use that value in the Apex
code where I can then use the System.today() + my custom value.
Appreciate the help.
Thanks.
I created instead of dates just Number fields:
1. To_Days (Number)
2.From_Days (Number)
Now I simply want to set my date input fields to the current date +/- the custome values...
If(payout__ AH_DAY_RANGES__c.From_Days__c.getDescribe().getDefaultValue() != null)
{
DateInput1.ActivityDate = System.Today() - payout__ AH_DAY_RANGES__c.From_Days__c.getDescribe().getDefaultValue();
}
If(payout__ AH_DAY_RANGES__c.To_Days__c.getDescribe().getDefaultValue() != null)
{
DateInput2.ActivityDate = System.Today() + payout__ AH_DAY_RANGES__c.To_Days__c.getDescribe().getDefaultValue();
}
But I am getting an error because the data type of payout__ AH_DAY_RANGES__c.To_Days__c.getDescribe().getDefaultValue() is OBJECT and not what I expected it to be (Number). How can I make the datatype of payout__ AH_DAY_RANGES__c.To_Days__c.getDescribe().getDefaultValue() a NUMBER so I can use it in the System.Today() formula?
Thanks.