The usual way to get the ID is by way of StandardController.getId()
. You use it as follows:
public ControllerCreateProposalView(ApexPages.StandardController stdController){
lId = stdController.getId();
}
Overall, I don't see any reason why your code should be failing. Assuming your page is using the Property__c
standard controller, the ID value is correct. If it is not using the Property__c
standard controller, then your error is in your page, not the code you've provided.
One thing you should always be doing is trying to cut all the fluff out of your code. Here's how you could have optimized your code:
public class ControllerCreateProposalView {
Id lId;
ApexPages.StandardController stdController;
public ControllerCreateProposalView(ApexPages.StandardController stdController){
lId = stdController.getId();
this.stdController = stdController;
}
public PageReference convert(){
Property__c l = [SELECT Name, Primary_Contact__c, Square_Footage__c, Anchor_GLA__c, CAP_Rate__c, Year_Built__c, Lot__c, Occupancy__c, Number_of_Buildings__c, Number_of_Retail_Units__c, Loan_Balance__c, Maturity_Date__c,
Interest_Rate__c, Term__c, Original_Lease_Term__c, Options__c, Term_Remaining_on_Lease__c, Gross_Leasable_Area__c, Type_of_Ownership__c, Parking__c, Parking_Ratio__c, Lease_Type__c,
Date_Reported__c, Loan_Amount__c, Loan_Type_bcc__c, LTV__c, Lender__c, Lender_Type__c, Amortization__c, Recourse__c, Current_Interest_Rate__c, Payment__c, Prepayment__c
FROM Property__c
WHERE Id = :lId];
Proposal__c c = new Proposal__c(Name=l.Name, Property__c=l.Id, Client__c=l.Primary_Contact__c, Square_Footage__c=l.Square_Footage__c, CAP_Rate__c=l.CAP_Rate__c, Lot__c=l.Lot__c, Loan_Balance__c=l.Loan_Balance__c,
Maturity_Date__c=l.Maturity_Date__c, Term__c=l.Term__c, Original_Lease_Term__c=l.Original_Lease_Term__c, Options__c=l.Options__c, Term_Remaining_on_Lease__c=l.Term_Remaining_on_Lease__c,
Anchor_GLA__c=l.Anchor_GLA__c, Occupancy__c=l.Occupancy__c, Number_of_Buildings__c=l.Number_of_Buildings__c, Number_of_Retail_Units__c=l.Number_of_Retail_Units__c,
Gross_Leasable_Area__c=l.Gross_Leasable_Area__c, Type_of_Ownership__c=l.Type_of_Ownership__c, Parking__c=l.Parking__c,Parking_Ratio__c=l.Parking_Ratio__c, Year_Built__c=l.Year_Built__c,
Lease_Type__c=l.Lease_Type__c, Date_Reported__c=l.Date_Reported__c, Loan_Amount__c=l.Loan_Amount__c, Loan_Type__c=l.Loan_Type_bcc__c, LTV__c=l.LTV__c, Lender__c=l.Lender__c,
Interest_Rate__c=l.Interest_Rate__c, Lender_Type__c=l.Lender_Type__c, Amortization__c=l.Amortization__c, Recourse__c=l.Recourse__c, Current_Interest_Rate__c=l.Current_Interest_Rate__c,
Payment__c=l.Payment__c, Prepayment__c=l.Prepayment__c);
insert c;
update new Property__c(Id=lId, Sales_Status__c = 'Proposal', Proposal_Date__c=Date.today());
Id cID = l.Primary_Contact__c;
//update contact stage
if([SELECT COUNT() FROM Contact WHERE Id = :cID AND Sales_Status__c IN (null, 'unconfirmed')] == 1) {
update new Contact(Id=cID, Sales_Status__c='Proposal');
}
// Redirect to new view
return new ApexPages.StandardController(c).view();
}
public PageReference back(){
return stdController.cancel();
}
}
Some notes:
- You don't need to query fields you plan on updating.
- You don't need to query fields you don't plan on using.
- You don't need to check if a list is empty before iterating over it.
- You shouldn't need that many debug statements.
- You don't need to query the Id field by default, unless no other fields are specified.
- You should try to query specific records to avoid excess Apex Code (see line after "update contact stage").
Best Answer
Looks like language field is not available via $User global variable. Here is a knowledge article about it
https://help.salesforce.com/apex/HTViewSolution?id=000205451&language=en_US
I checked for the available values for user and Language is not one of them. However there are other ways to implement this
Use Remote object and query the languageISOCode from there
< apex:page>
Use SFDC JS Toolkit to query it (JS Wrapper for APIs). Connection.js