I have a Visualforce page for creating a new record (custom object) from account. I also have a controller extension to pass the URL parameters and other values to pre-populate values on the vf page. Finally a custom button to launch the vf page with the URL parameters.
I am an admin, and this is only my second coding project.
I have everything working except for passing the Account.NumberOfEmployees to the custom object. Both fields are Number (8,0). Not sure why it doesn't like the number for some reason and I am stuck.
Here is the code for my vf page:
<apex:page standardController="MyCustomObject__c" extensions="MyCustomObjectExt">
<apex:form >
<apex:pageBlock title="SST Project Detail" mode="edit">
<apex:pageBlockSection title="Information">
<apex:inputField value="{!MyCustomObject__c.Name}" required="true"/>
<apex:inputField value="{!MyCustomObject__c.SalesRep__c}"/>
<apex:inputField value="{!MyCustomObject__c.AccountName__c}"/>
<apex:inputField value="{!MyCustomObject__c.Field1__c}"/>
<apex:inputField value="{!MyCustomObject__c.Field2__c}"/>
<apex:inputField value="{!MyCustomObject__c.AccountType__c}"/>
<apex:inputField value="{!MyCustomObject__c.Employees__c}"/>
<apex:outputField value="{!MyCustomObject__c.OwnerId}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{! save}" value="Save"/>
<apex:commandButton action="{! cancel}" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
Here is the code for my controller extension (with my different attempts and notes with error details commented out):
public with sharing class MyCustomObjectExt {
MyCustomObject__c record {get;set;}
public MyCustomObjectExt(ApexPages.StandardController stdController) {
record = (MyCustomObject__c) stdController.getRecord();
record.AccountName__c = ApexPages.currentPage().getParameters().get('acctId');
record.AccountType__c = ApexPages.currentPage().getParameters().get('acctType');
// I started with the following, but cannot save as I get the following Error: Compile Error: Illegal assignment from String to Decimal at line 11 column 9
//record.Employees__c = ApexPages.currentPage().getParameters().get('acctEmp');
// I then tried this. I am able to save the extension. But when I click the button to go to the VF page, I get a Visualforce Error: System.TypeException: Invalid decimal: 1,000 Class.MyCustomObjectExt.<init>: line 14, column 1
//record.Employees__c = Decimal.valueOf(ApexPages.currentPage().getParameters().get('acctEmp'));
// I then tried this. I am able to save the extension. But when I click the button to go to the VF page, I get a Visualforce Error: System.TypeException: Invalid integer: 1,000 Class.MyCustomObjectExt.<init>: line 17, column 1
//record.Employees__c = Integer.valueOf(ApexPages.currentPage().getParameters().get('acctEmp'));
// I then tried this, but cannot save as I get the following Error: Compile Error: Illegal assignment from String to Decimal at line 21 column 9
//string acctEmp = ApexPages.currentPage().getParameters().get('acctEmp');
//record.Employees__c = String.valueOf(acctEmp);
// I am stumped everything else works.
record.SalesRep__c = UserInfo.getUserId();
record.OwnerId = Id.valueOf('enterstringforqueueidhere');
}
}
Here is my custom button:
/apex/TestSSTRichTextForm?retURL={!Account.Id}&acctId={!Account.Id}&acctType={!Account.Type}&acctEmp={!Account.NumberOfEmployees}
I am so close, yet so far. Any help would be greatly appreciated! Michele