You need to sign in to do that
Don't have an account?
Input values of a custom setting and use it in a trigger
Hi everyone,
It's the first time that I use custom setting and I would be so greatful if you help me with this issues.
What I did is that I created a list custom setting param__c with two number fields: num1__c and num2__c.
So I want to insert there values from a Visualforce page:
<apex:page controller="CustomController"> <apex:form > <apex:inputField value="{!myValueFromPage}"/> <apex:inputField value="{!secondValueFromPage}"/> <apex:commandButton action="{!saveValues}" value="Save Input"/> </apex:form> </apex:page>
Its apex code:
public with sharing class CustomController { public String myValueFromPage {get; set;} public String secondValueFromPage {get; set;} public CustomController() { } public void saveValues() { param__c settings = param__c.getInstance(); myValueFromPage= settings.num__c ; secondValueFromPage= settings.num2__c; upsert settings; } }
I still don't know how to insert values of the list custom setting from vf page .....!
The second issue is that in the Account standard object I created two number custom fields: field1__c and field2__c.
the field2__c is calculated by num1__c (of the custom setting) divided by field1__c.
The trigger that I made is:
trigger Conversion on Account (before insert) { for (Account acc: Trigger.new){ acc.field2__c= (param__c.num__c)/ (acc.field1__c); } }
I have this error : Error: Compile Error: Arithmetic expressions must use numeric arguments at line 4 column 29
I really need your help.
Thanks.
I have updated your controller's code. Can you try with this one:
All Answers
I just done the trigger and it worked, if anyone search for it, here is the answer:
I really need your help for inpiyt values of the custom settings from a Visualforce page, thanks again!
I have updated your controller's code. Can you try with this one:
Hi Pankaj, thank you for your reply, I tried your code and had this error:
Error: Could not resolve the entity from <apex:inputField> value binding '{!myValueFromPage}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.
<apex:inputField> can only be used with Sobjects such as Account, Contact, Opportunity, Custom objects etc. I made following some minor tweaks in your Page code. Please refer the same: