You need to sign in to do that
Don't have an account?
Kevin Kim 9
How to copy over opportunity products to a custom object
I am trying to copy over my opportunity products to a custom object (projects) by clicking a button. What does the code look like for that? I am very new to salesforce apex coding.
Kevin,
You will find it difficult to copy all Opportunity Product records into a single Project. I believe the data model must be a little different
Project
-> Project Products
Assuming this updated model please try the following code
Custom button code
Thanks
Vivian
All Answers
Hi Kevin,
Do you wish to have the button on the OpportunityProduct so that clicking it copies the details to create a single Project record?
OR
Do you wish to have the button on Opportunity so that clicking it copies all related products and create a project record for every product?
Thanks
Vivian
Kevin,
You will find it difficult to copy all Opportunity Product records into a single Project. I believe the data model must be a little different
Project
-> Project Products
Assuming this updated model please try the following code
Custom button code
Thanks
Vivian
Kevin,
The above code is not an actual code, it is a pseudo code. Change the custom object to include __c in the api name
Thanks
Vivian
Kevin,
Project__c : Parent object
ProjectProduct__c : Child object // relation can be Lookup or Master Detail
Thanks
Vivian
I am now getting an error that says "entity is not api accessible entity name: Project"
I double checked to make sure all my api names were correct and they seem to be so I dont know why im getting this error
Seriously thank you for helping me through this
Kevin,
Have you created Project__c object and ProjectProduct__c object in your salesforce environment? Did you establish a relationship between the 2 objects?
Thanks
Vivian
Line 13 Invalid field Project__c for sObject ProjectProduct__c
Kevin,
Replace objProd.Project__c with the objProd.YourMasterDetail__c field name
Thanks
Vivian
Kevin,
Use the button as an onClick javascript. Replace {!Quote.Id} with {!OpportunityId} from the Opportunity object.
Thanks
Vivian
A problem with the Onclick Javascript button was encountered:
{faultcode:'soapenv:Client; faultstring:'No such parameter id defined for operation. please check the WSDL for the service.'}
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
sforce.apex.execute("buttonHandler","copyOLItoPP",{id:"{!Opportunity.Id}"});
location.reload();
Kevin,
In case you have a developer environment would you be able to share the developer environment credentials so that I can investigate why you are facing this issue.
You can send the credentials at vivian.charlie1208@gmail.com
Thanks
Vivian
Kevin,
Following is the updated button code
In case your issue has been resolved please feel free to mark this as closed.
Thanks
Vivian
Can you also explain how to do the testing and deploy the changes to production?
Rizki