You need to sign in to do that
Don't have an account?

Lookup field to auto populate
So we're looking to be able to auto-populate a field within the Case object (Entitlement) upon case creation with the value of a field from a custom field from the Accounts object (Entitlement__c). Looks like from what we've been told, this can be done only via Apex code. Can someone give any suggestions as to how it should be written.....thanks.
This use case is one of the most popular problem to solve with Apex code.
Please remember you will need to write tests for this code, and I didn't test this before posting just wrote it so you might have to tweek it.
You can also do this by overriding the New button for Case as follows (note this is not org-proof and will not port to your sandbox successfully as the IDs are org-specific)
https://na2.salesforce.com/500/e?id of field to set={!Account.Entitlement__c}
&id of Account lookup on Case_lkid={!Account.Id}
&retURL=/{!Account.Id}
Use Firebug or equivalent to locate the ids of the fields on the Case Edit page
TRY this code defenitly u get the solution for Autopopulation just you have to make Looup relation with User
trigger populateContactfromUser on Contact (before insert , before update){
Set<ID> setConIds = new Set<ID>();
for(Contact obj : trigger.new){
if(obj.User_Name__c!= null)
setConIds.add(obj.User_Name__c);
}
MAP<ID , User> mapCon = new MAP<ID , User>([Select Id,Email,Phone from User where id in: setConIds]);
for(Contact obj : trigger.new)
{
if(obj.User_Name__c != null)
{
User c = mapCon.get(obj.User_Name__c);
obj.Email= c.Email;
//Similarly you can assign Address fields as well, just add those field in Contact SOQL as well
}
}
}
trigger populateContactfromUser on Contact (before insert , before update){
Set<ID> setConIds = new Set<ID>();
for(Contact obj : trigger.new){
if(obj.User_Name__c!= null)
setConIds.add(obj.User_Name__c);
}
MAP<ID , User> mapCon = new MAP<ID , User>([Select Id,Email,Phone from User where id in: setConIds]);
for(Contact obj : trigger.new)
{
if(obj.User_Name__c != null)
{
User c = mapCon.get(obj.User_Name__c);
obj.Email= c.Email;
//Similarly you can assign Address fields as well, just add those field in Contact SOQL as well
}
}
}