function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
swain 10swain 10 

Error in Clonning opoortunity, Need help

I am getting the above error. My requirement is to change the currency field data, if opportunity already having child quote records. So its not possible through standard . Thus I am working out for custom solution. Earlier its was working on clicking cancel it use to create clonned opportunity but now its not working now on create and on cancel both.

Apex:-


public with sharing class CloneOpportunityExtension {
    //to get opp id from url
    public String recId {get;set;}
    // for new currency and name
    public Opportunity cloneOpp {get;set;}
    
    public CloneOpportunityExtension(ApexPages.StandardController stdCon) {
        cloneOpp = new Opportunity();
        recId = null;
        recId = ApexPages.currentPage().getParameters().get('id'); 
        System.debug('recId'+recId);
        if(recId!=null) {
            // setting the currency on page load
            cloneOpp.CurrencyIsoCode = ((opportunity)stdCon.getRecord()).CurrencyIsoCode;
            // setting Name
            cloneOpp.Name = ((opportunity)stdCon.getRecord()).Name;
            

//setting Account Name
// cloneOpp.Account= ((opportunity)stdCon.getRecord()).Account;
        } else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ' '+Label.select_a_vaild_Opportunity));
        }
    }
   
    /**
    * to save the Clone Opportunity with New Currency
    * 
    */
    public PageReference saveNewOpp(){   
        PageReference pRef = null;
        if(recId!=null) {
            if(cloneOpp!=null) {
                try{
                    // calling clone class
                    String returnId = null;
                    returnId = Cls_CloneOptyRelated.CloneOpportunity(recId, cloneOpp.CurrencyIsoCode, cloneOpp.Name);
                    if(returnId!=null) {
                        pRef = new PageReference('/'+returnId);
                        pRef.setRedirect(true);
                    }
                    else {
                       ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ' '+Label.Issue_in_Cloning));
                    }
                }
                catch(Exception e) {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR, ' ' + Label.Issue_in_Cloning + ' ' + e.getMessage()));
                }
            }
        }
        return pRef;
    }
}


Visualforce Page:-

<apex:page standardController="Opportunity" extensions="CloneOpportunityExtension" tabStyle="Opportunity" title="{!$ObjectType.Opportunity.Label} {!$Label.Clone}">
<apex:sectionHeader subtitle="{!Opportunity.Name}" title="{!Opportunity.Name} {!$Label.Clone}" rendered="{!recId != null}"/>
<apex:form >
<apex:pageMessages >
</apex:pageMessages>
<apex:pageBlock title="{!$ObjectType.Opportunity.Label} {!$Label.Clone}">
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!saveNewOpp}" value="{!$Label.Clone}" rendered="{!recId != null}"/>
<apex:commandButton action="{!cancel}" value="{!$Label.Cancel}" rendered="{!recId != null}"/>
<apex:outputPanel rendered="{!recId == null}"> <input type="button" name="{!$Label.Back}" value="{!$Label.Back}" class="btn" onclick="window.top.location='/006/o';"/>
</apex:outputPanel>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="1">
<apex:inputField value="{!cloneOpp.Name}" label="{!$ObjectType.Opportunity.fields.Name.Label}"/>
<apex:inputField value="{!cloneOpp.CurrencyIsoCode}" label="{!$ObjectType.Opportunity.fields.CurrencyIsoCode.Label}"/>
<!--- <apex:inputField value="{!cloneOpp.Account.Name}" label="{!$ObjectType.Opportunity.fields.Account.Name.Label}"/> ----> </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Errorr Message:-

Errors

Parent Opportunity: Value does not exist or does not match filter criteria.
Issue in cloning Opportunity, Please Contact System Administrator Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [CBG_Parent_Opportunity__c]
shailesh_rawteshailesh_rawte
Hi swain,

Do you have a required look-up field on which there is a filter set?

Let say you have a custom object TestCO and you have added a look-up field (Account) on the object. Additionally let say you added a look-up filter (site = 'Chicago') on this field (Account). Now when you create a new record on this object (TestCO) and provide some value ('test'), it will result in an error ( Error: Value does not exist or does not match filter criteria.). This is because the value you entered on the lookup field does not matches.

refer below link
https://success.salesforce.com/answers?id=90630000000gupKAAQ

Thanks
shailesh rawte
swain 10swain 10
Hi Shailesh,

Thanks for your response. I will check based on your response. In my Visualforce page for clonning only two fields available 1. Opportunity 2. Currency  , If i will not modify anything its clonning succesfully.   But If I try to modify the currency from existing currency to different one its showing this error:-

User-added image

Errors

Quote Currency: Can't change currency code. Enable quotes without parent opportunities.
Issue in cloning Opportunity, Please Contact System Administrator Update failed. First exception on row 0 with id 0Q05E0000009sCvSAI; first error: FIELD_INTEGRITY_EXCEPTION, Can't change currency code. Enable quotes without parent opportunities.: [CurrencyIsoCode]