You need to sign in to do that
Don't have an account?
Mohit Kashyap 14
Suppose in Opportunity we have related list of custom objects and if I clone the opportunity the related list should also be cloned. I had figured out that we can do this with VF. But dont know how to do it. Can someone plzz help?
Suppose in Opportunity we have related list of custom objects and if I clone the opportunity the related list should also be cloned. I had figured out that we can do this with VF. But dont know how to do it. Can someone plzz help?
By using VF page we can close as below.
vf page
Controller:
We an also achieve it clicking on a link on the record page by using the below link.
https://developer.salesforce.com/forums/?id=906F0000000BTJ8IAO
If this solution helps, Please mark it as best answer.
Thanks,
All Answers
By using VF page we can close as below.
vf page
Controller:
We an also achieve it clicking on a link on the record page by using the below link.
https://developer.salesforce.com/forums/?id=906F0000000BTJ8IAO
If this solution helps, Please mark it as best answer.
Thanks,
Sample Compile Error: SELECT Id, Name FROM car__c WHERE Opportunity__c = : acc.Id ^ ERROR at Row:1:Column:35 No such column 'Opportunity__c' on entity 'car__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names. at line 15 column 31
I am getting this error. Instead of Quote__c I am using a custom object car__c. What all fields should I include in the custom object?
Do we have opportinuty field on Car__c object. If yes, Just replace the API name of it.
Thanks,
If we dont have relation between opportunity and car how is cars related list available in opportunity. There may be some change in the name . If not please create a relation between opportunity and car then only cars related list will be available in opportunity record.
Thanks,
Can you please post your code here once.
Thanks,
<apex:page controller="Sample" sidebar="false">
<apex:form >
<apex:pageblock >
<apex:pageblockSection >
<apex:pageblockSectionItem >Enter the Opportunity Id:</apex:pageblockSectionItem>
<apex:pageblockSectionItem ><apex:inputtext value="{!idOfRec}" /></apex:pageblockSectionItem>
</apex:pageblockSection>
<apex:pageblockButtons >
<apex:commandButton value="Clone" action="{!cloneRec}"/>
</apex:pageblockButtons>
</apex:pageblock>
</apex:form>
</apex:page>
Controller class
public class Sample
{
public String idOfRec {get;set;}
public Sample()
{
}
public void cloneRec()
{
List<Car__c> cons = new List<Car__c>();
Opportunity acc = [SELECT ID, Name,StageName, CloseDate FROM Opportunity WHERE Id = : idOfRec];
Opportunity accCopy = acc.clone(false,true);
insert accCopy;
List<car__c > quote = [SELECT Id, Name FROM car__c WHERE Opportunity__c = : acc.Id];
for(car__c c : quote)
{
car__c conCopy = c.clone(false,true);
conCopy.Opportunity__c = accCopy.Id;
cons.add(conCopy);
}
insert cons;
}
}
Do you have cars related list and any cars associated to the opportunity. I used the same code and able to clone the cars records as well.
Thanks
Example: when I clone a Opportunity, and lets say there are five custom object (realted List) that should also be cloned.
I am attaching the sample code which I had written:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
sforce.apex.execute("Sample","cloneRec",{{!Opportunity.Id}:{!Opportunity.Id}}"});
Controller:
public class Sample
{
public String idOfRec {get;set;}
public Sample()
{
}
public void cloneRec()
{
List<Car__c> cons = new List<Car__c>();
Opportunity acc = [SELECT ID, Name,StageName, CloseDate FROM Opportunity WHERE Id = : idOfRec];
Opportunity accCopy = acc.clone(false,true);
insert accCopy;
List<car__c > quote = [SELECT Id, Name FROM car__c WHERE Opportunity__c = : acc.Id];
for(car__c c : quote)
{
car__c conCopy = c.clone(false,true);
conCopy.Opportunity__c = accCopy.Id;
cons.add(conCopy);
}
insert cons;
}
}
Can you please help me with this