You need to sign in to do that
Don't have an account?
Pre-Populate fields via URL when Record Type is required?
I've created a custom button that appends al the needed field id's and values in order to pre-populate a form but i'm running into an issue. My object has a Record Type so the first page has to be the form to select which Record Type, then it goes to the actual form I want to pre-populate. The problem is that I'm losing the URL params before I go to that form.
My Contact object has a lookup field called Transcript and a related list called Course Records. I've created a custom button on the Course Record related list called "Create New Course Record". The new button adds all the needed field id's and values for pre-populating a new Course Record form, but I first have to select a Record Type, and I cannot by-pass it. Is there a way to ensure the URL passes the vales from the create button to the Record Type selection form to the Course Record Form?
Even if I created a visual force page to append the URL params, I would end up with the same problem. Any ideas?
Thank You
Hi,
Through the url u cannot bypass the record type page. But through the vf page u can bypass the record type page. We have already implemented this in our project.Use this declaration and pre-set the recordtype through the id value u got from the url.
public RecordType recType { get; private set; }
Let me know if u want the complete class for reference.
Thanks,
Malar
Well I can't auto select the record type. I still need the users to determine this. Could I create a vfp that would re-append my url params after the button for selecting the record type is clicked? I just don't know where to overide that button at.
Hi Please below the sample vf page for ur reference. U have to create one custom button through which u can pass the id of the related list object. And we can also preset the record type.
public without sharing class cntStageDetail {
public StageDetail__c stageObj { get; private set; }
public opportunity opp { get; private set; }
public RecordType recType { get; private set; }
public cntStageDetail(ApexPages.StandardController controller) {
Id id = ApexPages.currentPage().getParameters().get('id');
String opst= ApexPages.currentPage().getParameters().get('oppid');
String oppId = opst.substring(0,15);
String stage;
String s1='Closed';
if(opst.length()>15)
{
stage=opst.substring(15,opst.length());
}
stageObj = (id == null) ? new StageDetail__c():[SELECT name,stage__C,Opportunity_del__c,RecordTypeid, stage_details__c FROM StageDetail__c WHERE id = :id];
if(oppId != null)
opp =[select Id, Selling_Approach__c,stageName, account.Account_Type_new__c FROM Opportunity WHERE id =:ApexPages.currentPage().getParameters().get('oppid').substring(0,15)];
else
opp =[select Id, Selling_Approach__c,stageName, account.Account_Type_new__c FROM Opportunity WHERE id =:stageObj.Opportunity_del__c];
if(id == null)
{
if(opp.Selling_Approach__c!=Null){
// if(opp.Selling_Approach__c == '3D') {
recType = [SELECT name, id FROM RecordType WHERE name = :opp.Selling_Approach__c];}
/*} else
{
recType = [SELECT name, id FROM RecordType WHERE name = :(opp.Selling_Approach__c)];
}
}*/
else {
recType = [SELECT name, id FROM RecordType WHERE name = '3D'];
}
stageObj.RecordTypeID = recType.Id;
stageObj.stage__c = opp.stageName;
if((opp.stageName=='Closed Won')||(opp.stageName=='Closed Lost'))
{
stageObj.stage__c='Close';
}
if(stage!=Null) { stageObj.stage__c=stage;}
if((stage!=Null)&&(stage.contains(s1))){stageObj.stage__c='Close';}
stageObj.Opportunity_del__c = opp.Id;
}
}
public PageReference save() {
try
{
if(stageObj.stage_details__c != null)
upsert(stageObj);
}
catch(System.DMLException e)
{
ApexPages.addMessages(e);
return null;
}
return (new ApexPages.StandardController(opp)).view();
}
static testMethod void myUnitTest() {
Account a2=new Account();
a2.Name='Test1';
a2.Account_Channel__c='Global';
a2.Phone='1111';
a2.ShippingStreet='arena';
a2.ShippingCity='brian';
a2.ShippingState='cew';
a2.ShippingCountry='d3';
a2.ShippingPostalCode='e';
a2.CheckBox__c=true;
insert a2;
Opportunity oppObj = new opportunity();
oppObj.name = 'Test Opportunity';
oppObj.Accountid=a2.Id;
oppObj.StageName = 'Closed Won';
oppObj.Win_Loss_Reason__c='Credit';
oppObj.Type = 'Net New Add';
oppObj.CloseDate = system.today();
oppObj.Selling_Approach__c = '3D';
insert oppObj;
Id oppId = ApexPages.currentPage().getParameters().put('oppid',oppObj.id);
StageDetail__c sObj = new StageDetail__c();
insert(sObj);
//Id id = ApexPages.currentPage().getParameters().put('id', sobj.id);
cntStageDetail e=new cntStageDetail(new ApexPages.StandardController(new StageDetail__c(Opportunity_del__c = oppid)));
e.opp.name = 'Test Opportunity';
e.opp.Accountid=a2.Id;
e.opp.StageName = 'Discover';
e.opp.Type = 'Net New Add';
e.opp.CloseDate = system.today();
e.opp.Selling_Approach__c='SAS';
e.stageObj.Opportunity_del__c=oppid;
e.stageObj.Stage__c='Propose';
e.stageObj.Stage_Details__c='Create proposal;Present proposal'; e.save();
Account a=new Account();
a.Name='Test1';
a.Account_Channel__c='Global';
a.Phone='1111';
a.ShippingStreet='a';
a.ShippingCity='b';
a.ShippingState='c';
a.ShippingCountry='d';
a.ShippingPostalCode='e';
a.BillingStreet='a';
a.BillingCity='b';
a.BillingState='c';
a.BillingCountry='d';
a.BillingPostalCode='e';
insert a;
Opportunity oppObj1 = new opportunity();
oppObj1.name = 'Test Opportunity';
oppObj1.Accountid=a.Id;
oppObj1.StageName = 'Discover';
oppObj1.Type = 'Net New Add';
oppObj1.CloseDate = system.today();
oppObj1.Selling_Approach__c = 'MDS';
insert oppObj1;
Id oppId1 = ApexPages.currentPage().getParameters().put('oppid',oppObj1.id);
StageDetail__c sObj1 = new StageDetail__c();
insert(sObj1);
Id id = ApexPages.currentPage().getParameters().put('id', sobj1.id);
cntStageDetail e2=new cntStageDetail(new ApexPages.StandardController(new StageDetail__c(Opportunity_del__c = oppid)));
e2.opp.name = 'Test Opportunity';
e2.opp.Accountid=a.Id;
e2.opp.StageName = 'Discover';
e2.opp.Type = 'Net New Add';
e2.opp.CloseDate = system.today();
e2.opp.Selling_Approach__c='3D';
//e2.stageObj.Opportunity_del__c= oppObj1.id;
e2.save();
e2.stageObj.Opportunity_del__c=oppObj.id;
//update e2;
Account a3=new Account();
a3.Name='Test1';
a3.Account_Channel__c='Global';
a3.Phone='1111';
a3.ShippingStreet='a';
a3.ShippingCity='b';
a3.ShippingState='c';
a3.ShippingCountry='d';
a3.ShippingPostalCode='e';
a3.BillingStreet='a';
a3.BillingCity='b';
a3.BillingState='c';
a3.BillingCountry='d';
a3.BillingPostalCode='e';
insert a3;
Opportunity oppObj2 = new opportunity();
oppObj2.name = 'Test Opportunity';
oppObj2.Accountid=a.Id;
oppObj2.StageName = 'Closed Won';
oppObj2.Win_Loss_Reason__c='Credit';
oppObj2.Type = 'Net New Add';
oppObj2.CloseDate = system.today();
oppObj2.Selling_Approach__c='None';
insert(oppObj2);
Id oppId2 = ApexPages.currentPage().getParameters().put('oppid',oppObj2.id);
StageDetail__c sObj2 = new StageDetail__c();
insert(sObj2);
Id id1 = ApexPages.currentPage().getParameters().put('id1', sobj2.id);
cntStageDetail e3=new cntStageDetail(new ApexPages.StandardController(new StageDetail__c(Opportunity_del__c = oppid)));
e3.stageObj.Opportunity_del__c= oppid;
e3.stageObj.Stage__c='Propose';
e3.save();
}
}