You need to sign in to do that
Don't have an account?
Create two records when one records created
Hi All,
I have three object Publication_Mention__c , Opportunity, Product. They all have lookup relationship between each other. The requirement is when a new Publication_Mention__c object is inserted into database with its tickbox field referall__c being ticked. A new Opportunity and the related Product record will be both created. I have tested the code I wrote. The Opportunity object inserting works fine(If I Comment out "insert newProduct;" in my code) . But when I try to insert a Product, error occurred. Here is my code
Ps. 1.The "Product" renamed "Product2" in our data Schema
2. I am using a trigger to call createNewOpportunity on Publicatiopn_Mention__c object
Flowing is the error message: System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Product Name]: [Product Name]:
I'd appreciate it very much for any help. Thanks
The error message states that the Product Name (which is a mandatory field) is not being passed while inserting the Product record. While you set the values for the different Product fields before inserting, you will need to set a value for the Name field also.
You will need to add the following line before inserting newProduct:
newProduct.Name = 'Test Product'; // You will need to decide on what value you would like to use as the Product Name
All Answers
The error message states that the Product Name (which is a mandatory field) is not being passed while inserting the Product record. While you set the values for the different Product fields before inserting, you will need to set a value for the Name field also.
You will need to add the following line before inserting newProduct:
newProduct.Name = 'Test Product'; // You will need to decide on what value you would like to use as the Product Name
It seems to me that you are missing required field of product, that is product name. You just need to give product name and then insert product :
//a new Product object will be created
Product2 newProduct = new Product2(Publication_Mention__c = PM.Id);
//fields of the new Product object
newProduct.Name= ’testName’;
newProduct.Quantity_in_Stock__c = 1;
newProduct.Price__c = 0.00;
newProduct.First_Publication_Date__c = Date.today();
insert newProduct;
Thanks a lot