You need to sign in to do that
Don't have an account?
Clone Opportunity w/wo related objects
I'm developing new buttons at the Opportunity Level that will clone the Opportunity with or without some related objects !
The clone works fine (at least I think this is the best way to do it )
As you see I need to put in there all the fields to be cloned.
The problem is : if in the future I create a new field, this one will not be transmitted with the clone ! (unless I edit the query here and add this new field) !!!!!! Is there any solution for this ?
Tkx a lot to you all for your answers and support !
Message Edited by Mig on 01-19-2009 06:49 PM
The clone works fine (at least I think this is the best way to do it )
Opportunity opp=[Select o.qtyProductGroups__c, o.Won_Lost_Comment__c, o.State__c, o.StageName, o.Selected_Contact_Id__c, o.Remarks__c, o.RecordTypeId, o.Reason_Won__c, o.Reason_Lost__c, o.Probability, o.Primary_Opportunity__c, o.Pricebook2Id, o.Personal_Chance_of_Success__c, o.OwnerId, o.Opportunity_Type__c, o.Opportunity_Description__c, o.One_Shot_Order__c, o.IsWon, o.IsDeleted, o.IsClosed,
o.I_Internal_Status__c, o.I_Account_manager__c, o.HasOpportunityLineItem, o.ForecastCategoryName, o.ForecastCategory, o.FiscalYear,
o.FiscalQuarter, o.Fiscal, o.FAS__c, o.Expire_Date__c, o.Do_not_Show_Total__c, o.Description, o.Delivery_specifications__c, o.Customer_Reference__c, o.CurrencyIsoCode, o.Contractual_Agreement__c, o.Competitor__c, o.Competitor_Products_involved__c, o.Competitor_Pricing__c, o.Competition__c, o.CloseDate, o.Categorisation__c, o.Budget__c, o.Amount, o.AccountId From Opportunity o where id=:getOpportunityId()];
if (opp.Id != null){
Opportunity newOpp = opp.clone(false,true);
newOpp.Name=opp.Name + ' CLONE';
insert newOpp;
}
As you see I need to put in there all the fields to be cloned.
The problem is : if in the future I create a new field, this one will not be transmitted with the clone ! (unless I edit the query here and add this new field) !!!!!! Is there any solution for this ?
Tkx a lot to you all for your answers and support !
Message Edited by Mig on 01-19-2009 06:49 PM
All Answers
You can perform the DescribeSObject for the set of Objects you need to generate the list of fields for. Then construct your SOQL string and execute the Query. For example:
I can be able to loop into the Opportunity, pick all the field and copy the value ...
gonna try that and let you know if it works ... I suppose there are no samples of that ...
Thankx a lot aalbert ! =)
I've just follow your example and it works nice =)
I'll pay you a beer next time =)
And to share it, here is the code :
Mig
hi - any chance you would be willing to share the code to copy the product line items as well? i am just starting on a project where i need to do just this (clone the oppty AND the line items). Any help would be so welcome!
Hello... I found your post and it's exactly what I'm trying too do..... I want to copy an opportunity if the stage = posted and copy the products, too. However, when I copy your code, I get an error "expected ';'"..... which I could say I knew what I was doing...but... we are just now reviewing the software and thinking of switching... anyway, any help would be greatly appreciated.
Thanks
I would recommend doing this cloning in a trigger on the Opportunity. If the Stage changes to "Posted" then have the trigger clone the Opportunity, clone any Products and save the whole thing.
Before you switch to another software, let me know if I can help! SF.com can do this type of functionality with a little coding help.
I'm attempting to do the same; have you been successful in doing this? It would be great if you could share. Cheers
Hi, I'm new to SF and not a coder at all - but wondered if you may be able to help please.
I want to Clone a Custom Object w/wo a related object. Is this possible? If so, please can you advise on how?