3

I created a VF page that is accessed from the Contact record that quickly helps the user identify the Primary Campaign for an opportunity as well as the record. Now I'm struggling to figure out how to make it work in salesforce1.

I can get the page to display but it performs inconsistently. In addition, I can't figure out how to pre-populate fields, ie Primary Campaign, Contact and others.

I'm using the sforce.one.createOpportunity method to take the user to the Opportunity.

Does anyone have a good example of how to implement a VF page in SF1 (few exist). Just as important, how do I pre-populate fields on the record that's being created.

1
  • If you want to pre-populate your fields when the page is open you can use action={!Populate} in your page tag, so in your controller you can create a void Populate(){ } and get all the data you want to pre-populate.
    – Carlos
    Commented Nov 10, 2014 at 21:32

2 Answers 2

1

do you mean sforce.one.createRecord(entityName, recordTypeId)? If so, I'm not quite sure if it is fully working in Spring '14 as the last news that I had were that It was going to be ready on Summer '14.(Last time I tested it, but going to test it again! :) ) However the sooner the better. But I think to your main question is about how to implement VF pages in SF1 and populate values. The idea is that the VF pages are going to continue the same way as they were, but with the option to be visible in mobile directly clicking a checkbox. Then in order to pre-populate fields you will need also a VF page in opportunity, and your controller will send the values to populate fields. Then here is your case: you have your initial VF page that will send you to Opportunitiy ( might be using navigateToSObject? or createRecord) and in opportunity you will have another VF in order to pre-populate fields and after everything is correct click save and create the new opportunity record, unless you created already your opportunity from your initial page and navitate to it using navigateToSobject ( I personally like this one and I used it already). Then in this case here you wont need VF page in opportunity, as the new record has been created in your initial VF-controller and you are only navigating to it and showing it.

Now comming back to how implement VF for SF1, I personally have in count user experience and where is going to be use the new VF page: only mobile? in desktop and mobile? I try to give same experience in both and be consistent. Might be use a little of JQuery? But appart from that it should have to be any difference to build a VF page for mobile than for desktop. Salesforce allows us to build the VF and with a simple click on Available for Salesforce mobile apps. There are also some known bugs around:known issues Apart from that the best guide that you can use in order to build VF pages is this one: VF Developer guide

Ah! I just forgot 2 really nice links from Keir Bowden and Sandeep Bhanot: Salesforce1 for Visualforce Developers / Salesforce1 and Visualforce - Things I've Learned and the other one Using Visualforce in Salesforce1

Hope it helps! If I can help further let me know :) - and sorry for the long answer -

0

sforce.one.createRecord has been significantly improved with Summer'17 and now you can even add default values. Plain and simple, you can use it like this one-liner:

sforce.one.createRecord('Opportunity',null,{ 
    Name : "2017-10-01 - Power Corp. - Big Deak - 999k",
    PrimaryCampaignId : "ENTER_ANY_VALID_CAMPAIGN_ID_HERE",
});

From the Summer '17 Release Notes - Prepopulate Fields on a Record Create Panel

Speed up record creation with prepopulated field values. The sforce.one.createRecord function now includes defaultFieldValues (optional) so you can define fields on a record create panel, including fields not displayed on the panel. This change applies to Lightning Experience and the Salesforce1 mobile browser app.

Users must have create access to prepopulated fields. Errors during saving that are caused by field access limitations do not display error messages.

Caution 1:

The this feature from Summer'17 works only if you put your Visualforce Page to API v40.0 or higher.

Caution 2:

Objectnames and Fieldnames are CASE-SENSITiVE! So name is not Name and only Name is correct

See also:

https://developer.salesforce.com/docs/atlas.en-us.salesforce1.meta/salesforce1/salesforce1_dev_jsapi_sforce_one.htm

https://developer.salesforce.com/docs/atlas.en-us.208.0.lightning.meta/lightning/ref_force_createRecord.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .