• Aneske
  • 0 Points
  • Member since 2011

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 5

I have written a simple Opportunity trigger to update a field in Opportunity Line Item records when an Opportunity is moved to certain stages.  I am now trying to write a test class so I can deploy it to my production server.  When I run the test (code is listed below),  I get the error:


15:15:27.915 (915680000)|EXCEPTION_THROWN|[17]|System.DmlException: Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []


My test data includes creating test records for Pricebook2, Product2 and PricebookEntry, but none of these objects have a field for the Standard Price and I can't find it in any other object.


Does anyone know where the Standard Price is stored?    Below is my test class code - I am just trying to get this simple test to run then I'll be adding more test cases.




private class TestUpdateClosedListPrice {

static testMethod void TestUpdateClosedListPrice() {

Opportunity opp1 = new Opportunity (Name='Opp1',StageName='Stage 0 - Lead Handed Off',CloseDate=Date.today());
insert opp1;

Pricebook2 pbk1 = new Pricebook2 (Name='Test Pricebook Entry 1',Description='Test Pricebook Entry 1');
insert pbk1;

Product2 prd1 = new Product2 (Name='Test Product Entry 1',Description='Test Product Entry 1');
insert prd1;

PricebookEntry pbe1 = new PricebookEntry (Product2ID=prd1.id,Pricebook2ID=pbk1.id,UnitPrice=50);
insert pbe1;

OpportunityLineItem lineItem1 = new OpportunityLineItem (OpportunityID=opp1.id,PriceBookEntryID=pbe1.id,Closed_List_Price__c=0);
insert lineItem1;


opp1.StageName='Stage 8 - Shipped';
update opp1;
System.assertNotEquals(0, lineItem1.Closed_List_Price__c);



As of today, I cannot deploy change sets from my sandbox to the production site. I get emails that the upload worked but it just doesnt apper in the list of inbound change sets.  Any Infos about this issue? 

I must be overlooking something very basic, but I don't understand why this code is throwing a DmlException error when I evoke the update.


I've stripped the code down to bare basics, hoping the problem would jump out at me - but it isn't.


public class FacultyApprovalWizard { private final Account thisStudent; public FacultyApprovalWizard() { thisStudent = [select Id, Name, Department_Notified_GPA__c, X2TOR_Recommendation__c, UNIV_Response_Due__c from Account where id = :System.currentPageReference().getParameters().get('id')]; } public Account getThisStudent() { return thisStudent; } public Attachment attachment { get { if (attachment == null) attachment = new Attachment(); return attachment; } set; } public PageReference saveAttachments() { // Add the attachment to our Person-Account(Student) record attachment.parentid = thisStudent.id; insert attachment; // redraw the page, so user can see their Attachment has been added to Student record PageReference page = ApexPages.currentPage(); page.setRedirect(true); return page; } public PageReference step1() { return Page.RequestFacultyApproval1; } public PageReference step2() { update thisStudent; return null; // return Page.RequestFacultyApproval2; } public PageReference cancel() { PageReference accountPage = new PageReference('/' + thisStudent.id); accountPage.setRedirect(true); return accountPage; } }



As soon as I hit the Update highlighted, I get this error.



System.DmlException: Update failed. First exception on row 0 with id 001Q0000002NXtJIAW;

first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on

insert/update call: Name: [Name]


Class.FacultyApprovalWizard.step2: line 39, column 7
External entry point



If it's releveant, these are Person-Account fields (not regular Account fields). Here's the VF page (though I think the problem is in my Apex class):



<apex:page controller="FacultyApprovalWizard" tabStyle="Account"> <!-- ABSTRACT: Evoked from button on Applied Student Person-Account record type --> <!-- Navigates user through the step of sending Faculty Approval Request and Attachments. --> <!-- TEMP SID: 001Q0000002IwlC --> <apex:sectionHeader title="Submit for Faculty Approval Wizard" subtitle="Step 1: Select Attachments" /> <apex:form > <apex:pageBlock title="Student Information" mode="edit"> <apex:pageBlockButtons location="top"> <apex:commandButton action="{!step2}" value="Step 2: Select Faculty Reviewers" /> <apex:commandButton action="{!cancel}" value="Cancel" /> </apex:pageBlockButtons> <apex:pageBlockSection columns="1"> <apex:outputField value="{!thisStudent.Name}"/> <apex:inputField value="{!thisStudent.Department_Notified_GPA__c}" required="TRUE"/> <apex:inputField value="{!thisStudent.X2TOR_Recommendation__c}" required="TRUE"/> <br/> </apex:pageBlockSection> </apex:pageBlock> <apex:pageBlock title="Select Attachments"> <apex:pageBlockSection > <apex:inputFile value="{!attachment.body}" filename="{!attachment.name}"/> <apex:commandButton value="save" action="{!saveAttachments}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> <apex:relatedList list="NotesAndAttachments" subject="{!thisStudent}"/> </apex:page>


I did some stare and compare at this document article, but it looks like we're largely doing similar things.

Message Edited by JPSeabury on 04-21-2009 07:10 PM
please help...I'm trying to write unit test code for a class file I've created, but I'm getting the following error:
Invalid initial expression type for field Opportunity.CloseDate, expecting: Date
Here is my class file and unit test code:
public class OpportunityOwnerRole {

 public static void UpdateOwnerRole(Opportunity[] opps) {
  Opportunity opp = [select ownerid from Opportunity where id in :opps];
  Id oid = opp.ownerid;
  User role = [select userroleid from User where id = :oid];
  Id urid = role.userroleid;
  UserRole userrole = [select name from UserRole where id = :urid];
  String strownerrole = userrole.name;
  for (Opportunity op: opps) {
   op.owner_role__c = strownerrole;
 public static void InsertOwnerRole(Opportunity[] opps) {
  List<Opportunity> OpptoUpdate= new List<Opportunity>();
  Opportunity opp = [select ownerid from Opportunity where id in :opps];
  Id oid = opp.ownerid;
  User role = [select userroleid from User where id = :oid];
  Id urid = role.userroleid;
  UserRole userrole = [select name from UserRole where id = :urid];
  String strownerrole = userrole.name;
  for (Opportunity op : opps) {
   Opportunity o = new Opportunity( Id = op.Id );
   o.owner_role__c = strownerrole;
  update OpptoUpdate;
 public static testMethod void testOpportunityOwnerRoleClass() {
  // Create a new opportunity to test
  Opportunity o = new Opportunity(Ownerid='00540000000o1y6AAA',Name='Test Opportunity Owner Role Trigger',CloseDate='2008-12-31',StageName='Prospecting');
  insert o;
  // Check if owner role field has been set to updated with owner role
  System.assert('VP, North American Sales', [Select Owner_Role__c from Opportunity WHERE ownerid = '00540000000o1y6AAA']);

Thanks for any help.
Illegal assignment from a Contact List to a contact list.....hmmmmm. Seems the compiler is having issues with case sensitivity.

This only happens in Summer08. Here is the code to reproduce:

List<Contact> cons = new List<Contact>();
cons = [select Id, Name from Contact limit 10];