You need to sign in to do that
Don't have an account?
Swap Fields DataType in VF Page
Hi,
I have a problem where i need to swap the field type in VF Page. The senario is as below:
1) I have a contact Creation Page where i have a Lookup for Account. If i have a matching account present i will create a contact wiht that Acocunt.
2) If i dont have the Account I need to create the Account first and then create the contact on the same page.
For first case i will be having the Account Filed as Id(since it is a lookup). I am not able to create an account with this as the second case requires the field to be a String to create the account.
Note: I am calling an Ajax Call( using an apex:actionSupport on the account field on onchange event) to get some other information and display.
Is there any way to tackel with this?
Cheers
Bramha
Ok now I understand your requirement,
Here is I developed a smaller version of your req, just use it for your issue as well
VFP :
Controller :
Use this example and use it for your requirement, I hope it helps you.
All Answers
I hope your lookUp for Account is not required on the page.
What you should do is that you should ahve a save action of contact
if(contact.accountId == null)
{
Account a = new Account(Name = contact.lastName;
insert a;
contact.accountId = a.id;
}
insert contact;
try to do like above code, just given you a way
Hi,
I need the lookup as well, because we need clients to select the account using the lookup as well. If they type an account name and TAB is pressed(means a onchange event occurs) , i am retrieving some address(from Address__c) on the onchange event. So, i need a lookup for the clients user friendly. Some thing like if the account exists it should be a lookup field, else it should behave as a normal input text field( Name field for account).
Thanks
Bramha
Ok now I understand your requirement,
Here is I developed a smaller version of your req, just use it for your issue as well
VFP :
Controller :
Use this example and use it for your requirement, I hope it helps you.
Hi,
can you explain me the code in VF Page where we have:
Thanks
Bramha
Any lookup will have two parts
1) Text : This is the text in the text box , this is the name that apperas when you select any value from the lookup window, we are binding it with controller property SupplierName
2)ID : The lookup will save a reference to the selected item, this id is not visible to the user but we just keep it in backgroundion
The Old id is not of any use for you, it comes in use when you need to perform any action on change of .lookup value.
Reason for using vField prefix and lkid suffix is that on a standard lookup page salesforce has these field and openLookup page copies selected values to thesee fields. If we will not use these prefix then javascript error will occur.
I hope above explanation will help you.
Hi,
Thanks, but the code create duplicate acocunts. Example if we already have an Account TestAcocunt1 and then when create a new contact with Account as TestAccount1, then TestAccount1 is being created again.
Cheers
Bramha
Hi,
Could you let me know why we are using 001 in the javascript fucntion here:
javascript:showLookup('pg:theform:thePageBlock:pageSection:pbsiAccountID:vField_SupplierName','001')"
Cheers
Bramha
001 specifies that the record is for Account i.e. 001 is prefix for Account.
For more information check here:
http://www.wohill.com/standard-salesforce-object-prefixes/
Regards,
Lakshman
Thanks Guys,
That was helpful, i made little modifications to tackle with duplicate account creation.
Thanks
Bramha