function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SA.ax1574SA.ax1574 

Apex Trigger Issue.

Hi All, I am new to salesforce development . I have a requirement. I have a field like Opportunity currency(standard field) in Opportunity object. After created the opportunity nobody are able to edit the currency field. because that Opportunity have some products. So So we are try to add some code that does this for them - e.g. a visual force page where they choose the new currency, and the controller deletes the products, changes the currency and then adds the products back again. anybody please provide sample code to resolve the above issue. I am new to salesforce development . can you please provide the trigger logic if possible. Ex: trigger deleteandaddproducts on Opportunity (before update,after update) { // Need logic to delete the Opportunity products when before update // and add deleted opportunity records into opportunity after update } Anybody please help me out...... Thanks,
Jeff MayJeff May

You've picked a complicated area to work with as your first trigger.  When Products are added to Opportunities, several different objects are involved. You should read the Apex doc on each of these:  Opportunities, OpportunityLineItems, PriceBookEntries, PriceBooks, Products.  Here is a link to the OpportunityLineItem doc as a starting point:  http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_opportunitylineitem.htm

 

 

The relationship goes like this:  In your SFDC org, you define Products.  Each Product will belong to at least the Standard Price Book (you might have multiple price books).  The "Product in the PriceBook" is called a PriceBookEntry.  When a user adds a Product to an Opportunity, they are actually selecting "PriceBookEntries".  Each selected PriceBookEntry creates an OpportunityLineItem with the details of that Product for that Opportunity.

 

This can be very confusing but is important to clearly understand if you are going to be customizing the way Opportunities work.  

 

Whenever I think about changing standard SFDC functionality, I try to remember to ask myself if there is a better way to solve my problem using built-in features.  The resulting system is much more maintainable that way.   But sometimes, you just have to.

 

Success,

 

JeffM

SA.ax1574SA.ax1574

Thanks you for aware of this issue.

Any solution for this issue?