Activity Forums Salesforce® Discussions How to create custom clone button with product for Salesforce opportunity sobject?

  • saloni gupta

    Member
    July 19, 2017 at 1:43 pm

    VF Page:

    <apex:page standardController="Opportunity" extensions="oppExtension" tabStyle="opportunity">
    <apex:form>
    <apex:pageBlock title="Opportunity Edit">
    <apex:pageBlockButtons >
    <apex:commandButton action="{!save}" value="Save"/>
    <apex:commandButton action="{!cancel}" value="Cancel" immediate="true"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection title="Opportunity Information">

    <apex:inputField value="{!OpportunityCloned.owner.name}" label = "Opportunity Owner"/>
    <apex:inputField value="{!OpportunityCloned.amount}"/>
    <apex:inputField value="{!OpportunityCloned.isPrivate}"/>
    <apex:inputField value="{!OpportunityCloned.CloseDate}"/>
    <apex:inputField value="{!OpportunityCloned.name}"/>
    <apex:inputField value="{!OpportunityCloned.NextStep}"/>
    <apex:inputField value="{!OpportunityCloned.Accountid}"/>
    <apex:inputField value="{!OpportunityCloned.StageName}"/>
    <apex:inputField value="{!OpportunityCloned.Type}"/>
    <apex:inputField value="{!OpportunityCloned.Probability}"/>
    <apex:inputField value="{!OpportunityCloned.LeadSource}"/>
    <apex:inputField value="{!OpportunityCloned.Campaignid}"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Additional Information">
    <apex:inputField value="{!OpportunityCloned.OrderNumber__c}"/>
    <apex:inputField value="{!OpportunityCloned.MainCompetitors__c}"/>
    <apex:inputField value="{!OpportunityCloned.CurrentGenerators__c}"/>
    <apex:inputField value="{!OpportunityCloned.TrackingNumber__c}"/>
    <apex:inputField value="{!OpportunityCloned.DeliveryInstallationStatus__c}"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Description Information">
    <apex:inputField value="{!OpportunityCloned.Description}"/>
    </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
    <apex:relatedList list="OpportunityLineItems" />
    <apex:relatedList list="OpenActivities" />
    <apex:relatedList list="ActivityHistories" />
    <apex:relatedList list="CombinedAttachments" />
    <apex:relatedList list="OpportunityContactRoles" />
    <apex:relatedList list="OpportunityPartnersFrom" />
    <apex:relatedList list="OpportunityCompetitors" />
    <apex:relatedList list="OpportunityHistories" />
    </apex:page>

    Apex class:
    public class oppExtension {
    private ApexPages.StandardController controller {get;set;}
    private opportunity opp{get;set;}
    public Opportunity OpportunityCloned {get;set;}

    public oppExtension(ApexPages.StandardController controller){
    this.controller = controller;
    opp = (Opportunity)controller.getRecord();
    opp = [select Id,owner.name,Accountid,Amount,CloseDate,Contractid,Description,OrderNumber__c,MainCompetitors__c,
    CurrentGenerators__c,LeadSource,NextStep,Name,stageName,Ownerid,Campaignid,IsPrivate,Probability,
    Type,DeliveryInstallationStatus__c,TrackingNumber__c from Opportunity where id =: opp.Id];
    OpportunityCloned = opp.clone(false,true);

    }
    public PageReference save() {
    try {
    insert(OpportunityCloned);
    } catch(System.DMLException e) {
    ApexPages.addMessages(e);
    return null;
    }
    // After successful Save, navigate to the default view page
    return new PageReference('/'+OpportunityCloned.id);

    }

    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos