You need to sign in to do that
Don't have an account?
Yang Wang
Check record type and set default value for closedate field in creating opportunity page
public with sharing class TestVFController {
public String recordtype = '';
public TestVFController(ApexPages.StandardController controller) {
recordtype = ApexPages.currentPage().getParameters().get('RecordType');
if(String.isEmpty(recordtype)) {
Map<Id,Schema.RecordTypeInfo> recordTypeInfos = Opportunity.SObjectType.getDescribe().getRecordTypeInfosByID();
if(recordTypeInfos.get('012280000011A6F').isAvailable()){
recordtype = '012280000011A6F';
system.debug('debug:TypeA');
}
if(recordTypeInfos.get('012280000011A6K').isAvailable()){
recordtype = '012280000011A6K';
system.debug('debug:TypeB');
}
}
}
public PageReference init(){
String url = '';
system.debug('debug:recordtype:' + recordtype);
if(recordtype == '012280000011A6F') {
url = '/006/e?nooverride=1&retURL=/006/o';
} else if(recordtype == '012280000011A6K') {
url = '/006/e?opp9=' + system.today().addDays(5).format() + '&nooverride=1&retURL=/006/o';
}
return new PageReference(url);
}
}
public String recordtype = '';
public TestVFController(ApexPages.StandardController controller) {
recordtype = ApexPages.currentPage().getParameters().get('RecordType');
if(String.isEmpty(recordtype)) {
Map<Id,Schema.RecordTypeInfo> recordTypeInfos = Opportunity.SObjectType.getDescribe().getRecordTypeInfosByID();
if(recordTypeInfos.get('012280000011A6F').isAvailable()){
recordtype = '012280000011A6F';
system.debug('debug:TypeA');
}
if(recordTypeInfos.get('012280000011A6K').isAvailable()){
recordtype = '012280000011A6K';
system.debug('debug:TypeB');
}
}
}
public PageReference init(){
String url = '';
system.debug('debug:recordtype:' + recordtype);
if(recordtype == '012280000011A6F') {
url = '/006/e?nooverride=1&retURL=/006/o';
} else if(recordtype == '012280000011A6K') {
url = '/006/e?opp9=' + system.today().addDays(5).format() + '&nooverride=1&retURL=/006/o';
}
return new PageReference(url);
}
}
Please use getRecordTypeInfosByName() instead of getRecordTypeInfosByID. This code will not work if it is deployed to another org as you are hard coding IDs and Record Type ids used to vary from org to org.
Thanks,
Prosenjit