0

I have cloned some Opportunities now i want to Query Opportunities where IsClone == True. How can I achive this?

 List<opportunity> opportunities = [select id,Name,Contract_Start__c,Contract_End__c,CloseDate,AccountId,Amount,Account.subscription_End_date__c,Account.subscription_Ending__c,(select id,Name,Contact__c,OpportunityId,Quantity,unitprice,ListPrice,Product2Id,PricebookEntryID from OpportunityLineItems) from opportunity where AccountId IN: accounids AND Amount>0];

//creating on Opportunity and all lineitems 
system.debug(opportunities);
  if(opportunities.size()>0){
      Opportunity clonedopp = opportunities[0].clone(false,false,false,false);
      clonedopp.StageName = 'Qualification';
     //clonedopp.Account.subscription_Ending__c = false;
      clonedopp.Contract_Start__c = opportunities[0].Account.subscription_End_date__c.adddays(1);
      clonedopp.Contract_End__c = Opportunities[0].Account.subscription_End_date__c.addmonths(12);
        insert clonedopp;
  }
  • set a field Is_Cloned__c on the cloned Opportunity, then query on that – cropredy Apr 5 '17 at 3:10
0

It is not possible to achieve this functionality using SOQL query, but you can achieve this by using sObject isClone() functionality. For example :

List<opportunity> opportunities = [select      id,Name,Contract_Start__c,Contract_End__c,CloseDate,AccountId,Amount,Account.subscription_End_date__c,Account.subscription_Ending__c,(select id,Name,Contact__c,OpportunityId,Quantity,unitprice,ListPrice,Product2Id,PricebookEntryID from OpportunityLineItems) from opportunity where AccountId IN: accounids AND Amount>0]; 

for(Opportunity opp : opportunities){
    if(opp.isClone()){
       // Add your logic
    }
}
  • 1
    I think this method only detects clones in memory. – Adrian Larson Apr 4 '17 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.