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
The new LearnerThe new Learner 

Need help on record types---little urgent please

Hi Experts,

I have requirment that is there is an Record type called Prospecting and i have custom clone button on the Prospecting record type record which is there in the Opportunity.

When ever i click on that Prospecting record type record a  new record has to create and it need to populate the parent record(original record which i cloned) that id needs to populate in field called 'Prospecting_Opportunity__c'.  i wrote code but its throwing validations rules of another record type can you guys help me pleaes.

1 ) Prospecting is record type which is there in the opportunity
2) created a button and assigned to the pagelayout

Apex class code:

global class customClone
    webservice static void cloneAccount(Id acctId) // you can pass parameters
      Opportunity acc = [SELECT ID, Name,recordtypeid FROM Opportunity WHERE Id = : acctId];
      //Id AccRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('200+').getRecordTypeId();
      Opportunity newacc=acc.clone(false);;
       newacc.Name = acc.Name +'-'+'Cloned';
       insert newacc;

Button code:

var opptyId='{!Opportunity.Id}'; 
sforce.apex.execute("customClone","cloneAccount",{acctId: opptyId});

Thanks in advance
Thiruchuri AdityanThiruchuri Adityan
What is the validation error you are getting ?? And validation rules will be applicable for all the records (not based on recordtypes unless you specify explicilily.  Are you sure that validation rule is ignoring this record type)
The new LearnerThe new Learner
there almost 20 to 25 validations rules are there , those are firing one by one  while inserting the record.
Thiruchuri AdityanThiruchuri Adityan
Either you have to change the logic in the validation rule so that it ignores Prospecting Record Type or cloning of your record should be done in a way such that it satisfies your validation rules
The new LearnerThe new Learner
can i bypass all the validaitons for prospecting record type , if yes kindly help me please
Thiruchuri AdityanThiruchuri Adityan
No.. What I mean to say is add a condition in your validation rule which checks for Prospect Record Type and if found then ignore validation rule
The new LearnerThe new Learner
kindly tell me how can i insert record static way , i am trying like this to insert the record but i am getting error on button click can you help me 

 public class customClone
public static void cloneOpportunity(Id oldopptId) // you can pass parameters
      Opportunity oldopp= [SELECT ID, Name,recordtypeid FROM Opportunity WHERE Id = : oldopptId];
       //Opportunity newopp= oldopp.clone(false,true);
       Opportunity newopp=new Opportunity();'-'+'Cloned';
     //newopp.recordtypeid = oldopp.recordtypeid;
       //newopp.Name = oldopp.Name +'-'+'Cloned';       
       insert newopp;           



var newAccid = sforce.apex.execute("customClone","cloneOpportunity",{oldopptId:"{!Opportunity.Id}"});