You need to sign in to do that
Don't have an account?
Autofilling lookup from URL using extension
Hi there,
I have an extension that someone from the forum assisted me in writing. It is used for autofilling the account field (from the URL) and saving a custom object - Destiny Survey. This is a child of account. Basically, the extension is designed so that should the url to the force.com site is appended with acct={!Account.Id} it will autofill Account__c and therefore upon completion of the survey it will place the record into the correct account.
I was hoping someone could help me do the same, except for a picklist field "Which_Product_Service__c" and more importantly Office__c which is a lookup field. Accounts also have a lookup to office if this helps?
This is what the extension looks like:
public class extDestinySurvey
{
public Destiny_Survey__c Dess {get;set;}
private Id AccountId
{
get
{
if ( AccountId == null )
{
String acctParam = ApexPages.currentPage().getParameters().get( 'acct' );
try
{
if ( !String.isBlank( acctParam ) ) AccountId = Id.valueOf( acctParam );
}
catch ( Exception e ) {}
}
return AccountId;
}
private set;
}
public extDestinySurvey(ApexPages.StandardController controller)
{
Dess = (Destiny_Survey__c)controller.getRecord();
}
public PageReference saveDestinySurvey()
{
Dess.Account__c = AccountId;
upsert Dess;
// Send the user to the detail page for the new account.
return new PageReference('/apex/Destiny_Survey_Thank_You');
}
}
This is my ATTEMPT at a method which will do the same for the office__c field.
private Id OfficeId
{
get
{
if ( OfficeId == null )
{
String OffIdParam = ApexPages.currentPage().getParameters().get( 'OffId' );
try
{
if ( !String.isBlank( OffIdParam ) ) OfficeId = Id.valueOf( OffIdParam );
}
catch ( Exception e ) {}
}
return OfficeId;
}
private set;
}
Please help, any advice or ehlp would be much appreciated
I have an extension that someone from the forum assisted me in writing. It is used for autofilling the account field (from the URL) and saving a custom object - Destiny Survey. This is a child of account. Basically, the extension is designed so that should the url to the force.com site is appended with acct={!Account.Id} it will autofill Account__c and therefore upon completion of the survey it will place the record into the correct account.
I was hoping someone could help me do the same, except for a picklist field "Which_Product_Service__c" and more importantly Office__c which is a lookup field. Accounts also have a lookup to office if this helps?
This is what the extension looks like:
public class extDestinySurvey
{
public Destiny_Survey__c Dess {get;set;}
private Id AccountId
{
get
{
if ( AccountId == null )
{
String acctParam = ApexPages.currentPage().getParameters().get( 'acct' );
try
{
if ( !String.isBlank( acctParam ) ) AccountId = Id.valueOf( acctParam );
}
catch ( Exception e ) {}
}
return AccountId;
}
private set;
}
public extDestinySurvey(ApexPages.StandardController controller)
{
Dess = (Destiny_Survey__c)controller.getRecord();
}
public PageReference saveDestinySurvey()
{
Dess.Account__c = AccountId;
upsert Dess;
// Send the user to the detail page for the new account.
return new PageReference('/apex/Destiny_Survey_Thank_You');
}
}
This is my ATTEMPT at a method which will do the same for the office__c field.
private Id OfficeId
{
get
{
if ( OfficeId == null )
{
String OffIdParam = ApexPages.currentPage().getParameters().get( 'OffId' );
try
{
if ( !String.isBlank( OffIdParam ) ) OfficeId = Id.valueOf( OffIdParam );
}
catch ( Exception e ) {}
}
return OfficeId;
}
private set;
}
Please help, any advice or ehlp would be much appreciated
public class extDestinySurvey
{
public Destiny_Survey__c Dess {get;set;}
private Id AccountId
{
get
{
if ( AccountId == null )
{
String acctParam = ApexPages.currentPage().getParameters().get( 'acct' );
try
{
if ( !String.isBlank( acctParam ) ) AccountId = Id.valueOf( acctParam );
}
catch ( Exception e ) {}
}
return AccountId;
}
private set;
}
private Id OfficeId
{
get
{
if ( OfficeId == null )
{
String OffIdParam = ApexPages.currentPage().getParameters().get( 'Off' );
try
{
if ( !String.isBlank( OffIdParam ) ) OfficeId = Id.valueOf( OffIdParam );
}
catch ( Exception e ) {}
}
return OfficeId;
}
private set;
}
public extDestinySurvey(ApexPages.StandardController controller)
{
Dess = (Destiny_Survey__c)controller.getRecord();
Dess = (Destiny_Survey__c) controller.getRecord();
Dess.Which_Product_or_Service__c = ApexPages.currentPage().getParameters().get('Ser');
}
public PageReference saveDestinySurvey()
{
Dess.Account__c = AccountId;
Dess.Office__c = OfficeID;
upsert Dess;
// Send the user to the detail page for the new account.
return new PageReference('/apex/Destiny_Survey_Thank_You');
}
}
All Answers
Does your extension class just prepopulates the lookup.??
You might want to try this for prepopulating the lookup through URL hacking technique and URLFOR function in VF Page.:
https://developer.salesforce.com/forums/ForumsMain?id=906F00000009m9EIAQ
Hope this helps.
Regards,
Ankit Gupta
public class extDestinySurvey
{
public Destiny_Survey__c Dess {get;set;}
private Id AccountId
{
get
{
if ( AccountId == null )
{
String acctParam = ApexPages.currentPage().getParameters().get( 'acct' );
try
{
if ( !String.isBlank( acctParam ) ) AccountId = Id.valueOf( acctParam );
}
catch ( Exception e ) {}
}
return AccountId;
}
private set;
}
private Id OfficeId
{
get
{
if ( OfficeId == null )
{
String OffIdParam = ApexPages.currentPage().getParameters().get( 'Off' );
try
{
if ( !String.isBlank( OffIdParam ) ) OfficeId = Id.valueOf( OffIdParam );
}
catch ( Exception e ) {}
}
return OfficeId;
}
private set;
}
private Id RecordTypeId
{
get
{
if ( RecordTypeId== null )
{
String RecordIdParam = ApexPages.currentPage().getParameters().get( 'Record' );
try
{
if ( !String.isBlank( RecordIdParam ) ) RecordTypeId= Id.valueOf( RecordIdParam );
}
catch ( Exception e ) {}
}
return RecordTypeId;
}
private set;
}
public extDestinySurvey(ApexPages.StandardController controller)
{
Dess = (Destiny_Survey__c)controller.getRecord();
}
public PageReference saveDestinySurvey()
{
Dess.Account__c = AccountId;
Dess.Office__c = OfficeID;
Dess.RecordTypeId = RecordTypeId;
upsert Dess;
// Send the user to the detail page for the new account.
return new PageReference('/apex/Destiny_Survey_Thank_You');
}
}
However, thank you so much for taking the time to reply.
TestExtDestinySurvey.TestExtDestinySurvey() Class 72 Failure Message: "System.DmlException: Upsert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: : [RecordTypeId]", Failure Stack Trace: "Class.extDestinySurvey.saveDestinySurvey: line 72, column 1 Class.TestExtDestinySurvey.TestExtDestinySurvey: li...
public class extDestinySurvey
{
public Destiny_Survey__c Dess {get;set;}
private Id AccountId
{
get
{
if ( AccountId == null )
{
String acctParam = ApexPages.currentPage().getParameters().get( 'acct' );
try
{
if ( !String.isBlank( acctParam ) ) AccountId = Id.valueOf( acctParam );
}
catch ( Exception e ) {}
}
return AccountId;
}
private set;
}
private Id OfficeId
{
get
{
if ( OfficeId == null )
{
String OffIdParam = ApexPages.currentPage().getParameters().get( 'Off' );
try
{
if ( !String.isBlank( OffIdParam ) ) OfficeId = Id.valueOf( OffIdParam );
}
catch ( Exception e ) {}
}
return OfficeId;
}
private set;
}
public extDestinySurvey(ApexPages.StandardController controller)
{
Dess = (Destiny_Survey__c)controller.getRecord();
Dess = (Destiny_Survey__c) controller.getRecord();
Dess.Which_Product_or_Service__c = ApexPages.currentPage().getParameters().get('Ser');
}
public PageReference saveDestinySurvey()
{
Dess.Account__c = AccountId;
Dess.Office__c = OfficeID;
upsert Dess;
// Send the user to the detail page for the new account.
return new PageReference('/apex/Destiny_Survey_Thank_You');
}
}