You need to sign in to do that
Don't have an account?
Visualforce Error: MISSING ARGUMENT, Id not specified in an update call: []
I am trying to create a Save Method on a Visual Force Page that uses a custom controller. I am able to create the input text field on the Visualforce page that accepts the value of the Date field I am trying to populate. However, when I try to save the page (committ the value to the salesforce.com database), I receive the following error:
"Visualforce Error
System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Class.ProductsController.save: line 47, column 1"
Can someone please help me with this.
Here is the ProductsController class:
public class ProductsController {
public List <Opportunity>getProducts(){
List<Opportunity>opp;
opp = [Select Name, Product_Family__c, StageName, Probability, AUM_Total__c, Product_Client_Demand_Summary__c, Competing_Product_pl__c, Idea_Origination__c, Inception_Date__c, Product_Client_Demand__c, Advisor_Team__c, IOI__c, Target_Launch_Date__c
From Opportunity
Where Product_Family__c != null
Order by Product_Family__c desc, Probability desc
];
return opp;
}
public Date targetlaunch {get; set;}
public void save(){
Opportunity o = new Opportunity(
Target_Launch_Date__c = targetlaunch
);
update o;
}
@istest
static void ProductTest()
{
ProductsController opp = new ProductsController();
opp.getProducts();
}
}
Here is the VisualForce Page:
<apex:page controller="ProductsController" sidebar="true" showheader="true">
<h1>Products Page</h1>
<apex:form >
<apex:pageBlock title="Products Onboarding">
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!save}" value="Save"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Sorted by Product Family & Opportunity Stage" >
</apex:pageBlockSection>
<!-- Printout Today's Date -->
<apex:outputText value="Displayed as of -">
</apex:outputText>
{! MONTH(Today())}
<apex:outputText value=" /">
</apex:outputText>
{! DAY(Today())}
<apex:outputText value=" /">
</apex:outputText>
{! YEAR(Today())}
</apex:pageBlock>
<apex:dataTable value="{!products}" var="prod"
cellspacing="0"
cellpadding="3"
columnswidth="100px"
border="3"
style="color:#151B8D; align:right"
styleClass="TableClass"
align="center" >
<apex:column style="font-weight:bold">
<apex:facet name="caption">Product Name</apex:facet>
<apex:facet name="header">Product Name</apex:facet>
<apex:outputField value="{!prod.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="caption">Stage</apex:facet>
<apex:facet name="header">Stage</apex:facet>
<apex:outputField value="{!prod.StageName}"/>
</apex:column>
<apex:column >
<apex:facet name="caption">Probablity</apex:facet>
<apex:facet name="header">Probability</apex:facet>
<apex:outputField value="{!prod.Probability}"/>
</apex:column>
<apex:column >
<apex:facet name="caption">Target Launch Date</apex:facet>
<apex:facet name="header">Target Launch Date</apex:facet>
<apex:inputField value="{!prod.Target_Launch_Date__c}"/>
</apex:column>
<apex:column >
<apex:facet name="caption">Product Family</apex:facet>
<apex:facet name="header">Product Family</apex:facet>
<apex:outputField value="{!prod.Product_Family__c}"/>
</apex:column>
<apex:column >
<apex:facet name="caption">Idea Orgination</apex:facet>
<apex:facet name="header">Idea Origination</apex:facet>
<apex:outputField value="{!prod.Idea_Origination__c}"/>
</apex:column>
<apex:column >
<apex:facet name="caption">Product Client Demand</apex:facet>
<apex:facet name="header">Product Client Demand</apex:facet>
<apex:outputField value="{!prod.Product_Client_Demand_Summary__c}"/>
</apex:column>
<apex:column >
<apex:facet name="caption">Advisor Team</apex:facet>
<apex:facet name="header">Advisor Team</apex:facet>
<apex:outputField value="{!prod.Advisor_Team__c}"/>
</apex:column>
<apex:column >
<apex:facet name="caption">Indication of Interest</apex:facet>
<apex:facet name="header">Indication of Interest</apex:facet>
<apex:outputField value="{!prod.IOI__c}"/>
</apex:column>
</apex:dataTable>
</apex:form>
<apex:outputlink value="{! URLFOR($Action.Opportunity.New) }">Create New Product Opportunity</apex:outputlink>
</apex:page>
Any help given on the Save Method for the Custom Controller would be appreciated.
You need to modify something like following:
public class ProductsController {
List<Opportunity>opp;
public List <Opportunity>getProducts(){
if(opp == null)
{
opp = [Select Name, Product_Family__c, StageName, Probability, AUM_Total__c, Product_Client_Demand_Summary__c, Competing_Product_pl__c, Idea_Origination__c, Inception_Date__c, Product_Client_Demand__c, Advisor_Team__c, IOI__c, Target_Launch_Date__c
From Opportunity
Where Product_Family__c != null
Order by Product_Family__c desc, Probability desc
];
}
return opp;
public void save()
{
list<Opportunity> opper=getProducts();
if(opper.size()>0)
update opper;
}
All Answers
Just update the following:
opp = [Select Id,Name, Product_Family__c, StageName, Probability, AUM_Total__c, Product_Client_Demand_Summary__c, Competing_Product_pl__c, Idea_Origination__c, Inception_Date__c, Product_Client_Demand__c, Advisor_Team__c, IOI__c, Target_Launch_Date__c
From Opportunity
Where Product_Family__c != null
Order by Product_Family__c desc, Probability desc
];
Another thing:
Opportunity o = new Opportunity(
Target_Launch_Date__c = targetlaunch
);
You are creating new instance of Opportunity and updating it, update needs Id specified in the instance. like O.id= '213231443434' some valid opportunity id to be updated.
Hi,
Try the below save method
public void save()
{
list<Opportunity> opper=getProducts();
if(opper.size()>0)
{
Opportunity o = new Opportunity(id=opper[0].id);
o.Target_Launch_Date__c = targetlaunch;
update o;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi Navatar
I appreciate your response, Unfortunately that did not commit the change to the Target Launch Date field in the data table grid.
There is no longer an error in the ProductsController, but when I enter a date into the Target Launch Date field in the grid, it does not commit the value to the record in the salesforce.com database.
Any other suggestions?
Hi Prasanna
Thanks for the response as always.
Can you please explain how I should go about instantiating the Opportunity with this line of code:
"You are creating new instance of Opportunity and updating it, update needs Id specified in the instance. like O.id= '213231443434' some valid opportunity id to be updated."
thanks for your help
Is it possible that I am doing something wrong with this accessor method:
public Date targetlaunch {get; set;}
is the Date return type correct?
Hi Prasanna
Is there anything you see I can improve in these lines of code:
public Date targetlaunch {get; set;}
public void save() { list<Opportunity> opper=getProducts();
if(opper.size()>0)
{ Opportunity o = new Opportunity(id=opper[0].id);
o.Target_Launch_Date__c = targetlaunch;
update o;
}
}
You need to modify something like following:
public class ProductsController {
List<Opportunity>opp;
public List <Opportunity>getProducts(){
if(opp == null)
{
opp = [Select Name, Product_Family__c, StageName, Probability, AUM_Total__c, Product_Client_Demand_Summary__c, Competing_Product_pl__c, Idea_Origination__c, Inception_Date__c, Product_Client_Demand__c, Advisor_Team__c, IOI__c, Target_Launch_Date__c
From Opportunity
Where Product_Family__c != null
Order by Product_Family__c desc, Probability desc
];
}
return opp;
public void save()
{
list<Opportunity> opper=getProducts();
if(opper.size()>0)
update opper;
}
Thanks Prasanna, after trying that I get a compile error:
That fixed it Prasanna; you're a superstar!