You need to sign in to do that
Don't have an account?
James Kinsey
Controller Extension to create SObject from custom object
Is this the correct extension to get the custom object "equipment__c" data and create a new opportunity with fields already populated with equipment__c values? Either this isn't right or I'm referencing it wrong from the visualforce page.
public without sharing class OppClass2 { private final equipment__c equipment; public OppClass2(ApexPages.StandardController opportunity) { } public oppclass2() { equipment = [select id, name from Equipment__c where id = :ApexPages.currentPage().getParameters().get('id')]; } public Equipment__c getequipment() { return equipment; } public PageReference NewOpp(){ Opportunity o = new Opportunity(name = equipment.name,StageName='New Opportunity',CloseDate=system.today()); Database.SaveResult[] lsr = Database.insert(new Opportunity[]{o, new Opportunity(name = equipment.name,StageName='New Opportunity',CloseDate=system.today())},false); for(Database.SaveResult sr: lsr){ if(!sr.isSuccess()) Database.Error err = sr.getErrors()[0]; } return (new ApexPages.StandardController(o)).edit(); } }
looks to me like you're using it as a standalone app and not an extension. An extenion would typically have a different constructor:
public ApexPages.StandardController con { get; set;}
public Milestone1_TimelineCon ( ApexPages.StandardController stc){
con = stc;
}
And rather than querying for your Equipment__c using SOQL you would simply get it from the standard controller.
Likewise in your VF page you would have something like
<apex:page sidebar="false" showheader="true" standardController="Milestone1_Milestone__c" extensions="Milestone1_TimelineCon" >
Note the "extensions" property.
HTH
Hi,
normally you should be able to get the info from the extended object with standardcontroller's method getRecord like as shown here:
http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
Here is the sanitized code:
can you share your visualforce markup or part of it? It might be easier to see what is wrong with it.
Ok, I removed and some others:
And now my extension looks like:
My VF page looks like this but I am not able to insert this page as a button on the Equipment__c custom object.
I thank you for your inputs
Hi,
the problem is that the visualforce page is using an opportunity standard controller while it should be using the equipment__c standarcontroller.
Here is the revised code:
I would recommend going through the visualforce workbook which will give you the basics to understand Controllers and Visualforce pages:
http://www.salesforce.com/us/developer/docs/workbook_vf/index.htm