I have an object called Sales_and_Marketing__c
, and I would like to override the standard New button so that the field Sales_Contact__c
(lookup to Contact
) gets pre populated with the logged in User
.
On the User
object we have a field ContactId__c
. This field is a of a data type of Text(18) and just holds the contact id.
I have looked on online for scenarios and have attempted to write this but i am a little confused and appreciate some help
Apex class :
public with sharing class NewMKtMaterialsRequest
{
public Contact profileInfo {get;set;}
public NewMKtMaterialsRequest(ApexPages.StandardController controller)
//public NewMKtMaterialsRequest()
{
Id userId = UserInfo.getUserId();
List<User> UserList = [select U.ContactId from User U where Id =: userId];
Id contactId = UserList.get(0).ContactId;
//Contact profileInfo = [SELECT ID FROM Contact WHERE Id =: contactId LIMIT 1];
Contact profileInfo = [SELECT
Id,
FirstName,
User__c,
User__r.Id,
User__r.Name
FROM Contact WHERE Id =: contactId LIMIT 1];
}
public PageReference RedirectToMKTRequest()
{
return new PageReference('/a0R/e?Sales_Contact__c=contactId.id&nooverride=1');
}
}
Visual Force Page ;
<apex:page standardController="sales_and_marketing__c" extensions="NewMKtMaterialsRequest" action="{!RedirectToMKTRequest}">
</apex:page>