• KelseyB
  • NEWBIE
  • 15 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 6
    Replies
I created a Visualforce page and Apex controller to clone a record. What I need now is to have the Save and Cancel button redirect back to the originating record. I have no experience with Apex or VF and was able to create this with the help of this developer forum. Can anyone help me with what code to add and where to put it, to get the Save Button and Cancel Button to redirect back to the original record? 

Here's the vf page code: 

<apex:page standardController="OpportunityLineItem" extensions="customcloneOpportunityLineItem">
<apex:form >
<apex:pageBlock title="Opportunity Product details">
<apex:pageBlockSection title="Opportunity Prodcut Edit" columns="1">
<apex:inputfield value="{!OpportunityLineItem.OpportunityId}"/>
<apex:inputField value="{!OpportunityLineItem.Product2Id}" />
<apex:inputField value="{!OpportunityLineItem.Quantity}" />
<apex:inputField value="{!OpportunityLineItem.Unit_List_Price__c}" />
<apex:inputfield value="{!OpportunityLineItem.Unit_Sales_Price__c}"/>
<apex:inputfield value="{!OpportunityLineItem.Unit_Cost__c}"/>
<apex:inputfield value="{!OpportunityLineItem.ProductCode}"/>
<apex:inputfield value="{!OpportunityLineItem.Product_Family__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!cloneopportunitylineitem}" value="Save" />
<apex:commandButton action="{!cloneopportunitylineitem}" value="Cancel" />
</apex:pageBlockButtons>
        </apex:pageBlock>
</apex:form>
</apex:page>

Here's the Apex Class: 

public class customcloneOpportunityLineItem
{private opportunitylineitem l;
public customcloneOpportunityLineItem(apexpages.standardcontroller std){
this.l = (opportunitylineitem)std.getrecord();
}

public void cloneOpportunityLineItem(){
opportunitylineitem l1 = new OpportunityLineItem();
l1 =l.clone();
insert l1; 
}
}
 
I ran the Lightning Experience Configuration Converter for JavaScript buttons and I only have one button. However, it's on the Opportunity Line Item object, and I'm getting an error that says "OpportunityLineItem object isn't supported". How do I deal with this button conversion?
I thought I could create a Quick Action on the Opportunity Product object, but it's not even an option. Any ideas on another route I could go? The button sits on the Opportunity Product record and clones the existing record with pre-populated pricing and cost fields on an edit screen.
It was suggested in the Lightning Now trailblazer community that I would need to write custom code. However, that's way out of my wheelhouse. I was hoping someone could help provide me some direction. 
I created a Visualforce page and Apex controller to clone a record. What I need now is to have the Save and Cancel button redirect back to the originating record. I have no experience with Apex or VF and was able to create this with the help of this developer forum. Can anyone help me with what code to add and where to put it, to get the Save Button and Cancel Button to redirect back to the original record? 

Here's the vf page code: 

<apex:page standardController="OpportunityLineItem" extensions="customcloneOpportunityLineItem">
<apex:form >
<apex:pageBlock title="Opportunity Product details">
<apex:pageBlockSection title="Opportunity Prodcut Edit" columns="1">
<apex:inputfield value="{!OpportunityLineItem.OpportunityId}"/>
<apex:inputField value="{!OpportunityLineItem.Product2Id}" />
<apex:inputField value="{!OpportunityLineItem.Quantity}" />
<apex:inputField value="{!OpportunityLineItem.Unit_List_Price__c}" />
<apex:inputfield value="{!OpportunityLineItem.Unit_Sales_Price__c}"/>
<apex:inputfield value="{!OpportunityLineItem.Unit_Cost__c}"/>
<apex:inputfield value="{!OpportunityLineItem.ProductCode}"/>
<apex:inputfield value="{!OpportunityLineItem.Product_Family__c}"/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!cloneopportunitylineitem}" value="Save" />
<apex:commandButton action="{!cloneopportunitylineitem}" value="Cancel" />
</apex:pageBlockButtons>
        </apex:pageBlock>
</apex:form>
</apex:page>

Here's the Apex Class: 

public class customcloneOpportunityLineItem
{private opportunitylineitem l;
public customcloneOpportunityLineItem(apexpages.standardcontroller std){
this.l = (opportunitylineitem)std.getrecord();
}

public void cloneOpportunityLineItem(){
opportunitylineitem l1 = new OpportunityLineItem();
l1 =l.clone();
insert l1; 
}
}
 
I ran the Lightning Experience Configuration Converter for JavaScript buttons and I only have one button. However, it's on the Opportunity Line Item object, and I'm getting an error that says "OpportunityLineItem object isn't supported". How do I deal with this button conversion?
I thought I could create a Quick Action on the Opportunity Product object, but it's not even an option. Any ideas on another route I could go? The button sits on the Opportunity Product record and clones the existing record with pre-populated pricing and cost fields on an edit screen.
It was suggested in the Lightning Now trailblazer community that I would need to write custom code. However, that's way out of my wheelhouse. I was hoping someone could help provide me some direction.