function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shwetal DesaiShwetal Desai 

Override Custom Object Tab by its Edit URL

I have one custom object. only one record will be there in that custom object.
Now there is one Visual force page for my custom object which i need to open on the click of Tab of the object but with that value in all inputText and other inputComponent.

i.e. If there is no record found in the object then "save" button will insert the new record else update the existing one.

How can i do this?

Thanks in Advance
Luke@TWSLuke@TWS
In the constructor of the controller you load in the record. If that fails you make a new one. Insert it there and there then you have the ID for the update on save.
Shwetal DesaiShwetal Desai
u r right... but i have confusion that if i got the record by using constructor using "getRecord()" then how will i set those each and every field values in inputField/inputText??

any guidance?
Luke@TWSLuke@TWS
You have to have a variable for each one like:
public myVariable {get;set;}
Set those in the constructor when you load in the record. Then use each one with an inputText etc

Shwetal DesaiShwetal Desai
hmmmmm.........
Okie.........
i ll try this and let u know tomorrow.
Thank you for guiding me...
Shwetal DesaiShwetal Desai
Not working yet...i tried this code in my controller.

APEX CODE:-

public class Setup
{
Companypref__c cmp;
public Companypref__c getcmp()
{
Companypref__c cmpref = [select Id from Companypref__c];
if (cmpref == null)
{cmp = new Companypref__c();}
else
{cmp = new Companypref__c(ID = cmpref.Id);}
return cmp;
}

public String locationId,company,address,city,state,country,phone,fax;
public Double zip;
public ID fedemp,stateemp;

public String getlocationId()
{
locationId = cmp.LocationId__c;
return locationId;
}
public void setlocationId(String lid)
{
locationId = lid;
}
public String getcompany()
{
company = cmp.Company__c;
return company;
}
public void setCompany(String c)
{company = c;}
public String getaddress()
{
address = cmp.address__c;
return address;
}
public void setaddress(String ad)
{address = ad;}
public String getcity()
{
city = cmp.City__c;
return city;
}
public void setcity(String ct)
{city = ct;}
public String getstate()
{state = cmp.State__c; return state;}
public void setstate(String st)
{state = st;}
public String getcountry()
{country = cmp.Country__c;return country;}
public void setcountry(String cn)
{country = cn;}
public Double getzip()
{zip=cmp.Zip__c;return zip;}
public void setzip(Double z)
{zip = z;}
public String getphone()
{phone = cmp.Phone__c; return phone;}
public void setphone(String p)
{phone = p;}
public String getfax(){fax=cmp.Fax__c;return fax;}
public void setfax(String f){fax= f;}
public ID getfedemp(){fedemp = cmp.FedEmpId__c;return fedemp;}
public void setfedemp(ID fe){fedemp = fe;}
public ID getstateemp(){stateemp = cmp.StateEmpId__c;return stateemp;}
public void setstateemp(ID se){stateemp=se;}
}

if i use this code for my VF page it gives me error:

"System.NullPointerException: Attempt to de-reference a null object

Class.Setup.getlocationId: line 41, column 18
External entry point "

where i did mistake in code?