You need to sign in to do that
Don't have an account?
The 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.Prospecting_Opportunity__c=acc.id;
newacc.Name = acc.Name +'-'+'Cloned';
insert newacc;
}
}
Button code:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
var opptyId='{!Opportunity.Id}';
sforce.apex.execute("customClone","cloneAccount",{acctId: opptyId});
Thanks in advance
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.Prospecting_Opportunity__c=acc.id;
newacc.Name = acc.Name +'-'+'Cloned';
insert newacc;
}
}
Button code:
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
var opptyId='{!Opportunity.Id}';
sforce.apex.execute("customClone","cloneAccount",{acctId: opptyId});
Thanks in advance
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();
newopp.name=oldopp.name+'-'+'Cloned';
//newopp.recordtypeid = oldopp.recordtypeid;
//newopp.Prospecting_Opportunity__c=oldopp.id;
//newopp.Name = oldopp.Name +'-'+'Cloned';
insert newopp;
}
}
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
var newAccid = sforce.apex.execute("customClone","cloneOpportunity",{oldopptId:"{!Opportunity.Id}"});
window.location.href="/"+newAccid;