You need to sign in to do that
Don't have an account?
Rajan
Hi friends,I am getting an error for a trigger.
Hi friends,I am getting an error for a trigger. Condition is: I want to create an product whenever I am creating any opportunity. In opportunity, product is on the based of dependent picklist. Error is - Error Error: Compile Error: Entity is not api accessible at line 1 column 1
Code is as below:
trigger CreateProduct on Opportunity (after insert) {
for(Opportunity opp: trigger.new){
Product pod = new Product();
pod.Name = opp.Select_Product__c;
pod.Opportunityid = opp.id;
insert pod;
}
}
Code is as below:
trigger CreateProduct on Opportunity (after insert) {
for(Opportunity opp: trigger.new){
Product pod = new Product();
pod.Name = opp.Select_Product__c;
pod.Opportunityid = opp.id;
insert pod;
}
}
Acutally there is no standard object
Productthat is Product2.That is why it raise error.
Thanks.
You are getting that error because the API name of Product is "Product2" in Salesforce. Please find below link for reference:
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_product2.htm
Let me know if that helps you.
Best Regards,
BALAJI
To add any product to opportunity,you must use OpportunityLineItem object.
please follow the below steps.
1)Create your product(API name of product is Product2)
2)Create your pricebook entry(API name of Pricebook Entry is PricebookEntry)
3)Create your opportunity line item(API name of Opportunity LineItem is OpportunityLineItem)
Your code look like below
Please reference below code.
This is a rough estimate of the code you'll want to use. We need to set the price book before adding the product, so we do this in "before insert", then we add the product in the event "after insert". You may need to adjust the fields to suit your needs as well.
Thanks,
Swaraj