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
SivaGSivaG 

Dynamic Apex using Schema.getdescribe()

Hi,

Requirement - 

Custom object A has three fields Field1(picklist),Field2(Created date),Field3(Final date)
Field1 has picklist values pickX,pickY,pickZ
I have another Custom object B with each field label matching with custom object's Field1 picklist values i.e. pickX,pickY,pickZ fields with values 10,20,30. There will be only 1 record in object B which is maintained by the end-user.
Everytime user selects Field1 picklist value then the end date should be calculated based on the value in the corresponding field in object B
i.e. if user selects Field1 pick list value pickY, then the Final Date should be calculated as Final date = Created date + 20.

There is no relation between objects A & B.
How can we achieve this using Dynamic Apex i.e. Schema.getdescribe()?

Thanks
Kumar
 
Best Answer chosen by SivaG
James LoghryJames Loghry
Kumar,

If I'm understanding your question correctly, Schema.describe calls are rather useless here.

Instead, set Object B as a custom setting (sounds like a perfect candidate for a hierarchy custom setting).

Then, you have a few options:
  1. ​Modify Final Date to be a formula field that is Created Date + {!$Setup.ObjectB__c.Number_Of_Days_To_Add__c}
  2. Add a trigger to calculate final date based on the custom setting
  3. Add a process (and likely a flow) to calculate the final date based on the custom setting
For more info on custom settings in formula fields, see this link: http://blog.jeffdouglas.com/2010/02/08/using-hierarchy-custom-settings-in-salesforce-com/

All Answers

James LoghryJames Loghry
Kumar,

If I'm understanding your question correctly, Schema.describe calls are rather useless here.

Instead, set Object B as a custom setting (sounds like a perfect candidate for a hierarchy custom setting).

Then, you have a few options:
  1. ​Modify Final Date to be a formula field that is Created Date + {!$Setup.ObjectB__c.Number_Of_Days_To_Add__c}
  2. Add a trigger to calculate final date based on the custom setting
  3. Add a process (and likely a flow) to calculate the final date based on the custom setting
For more info on custom settings in formula fields, see this link: http://blog.jeffdouglas.com/2010/02/08/using-hierarchy-custom-settings-in-salesforce-com/
This was selected as the best answer
SivaGSivaG
Hi James,

Even I agree with you on going with the custom settings part. But business users wanted to maintain it from the user interface on their own. We found a workaround for this. 

Thanks
Kumar.