Apex- Set Picklist Field Selected Value - salesforce

I have a picklist field in some object. And, through apex, I want to set the selected value of the picklist. When I try to do that, it says "bad value for restricted picklist field:".
but the value I am trying to set is there in the value set. And I have enabled "Restrict picklist to the values defined in the value set" too.
MyObject.MyPickListField = 'Belgium';
May I know where I have gone wrong in setting the picklist field's selected value ?

To resolve this issue, remove the default value from the Record Type or picklist field (depending on where it is set).
Remove the default value: Record Type
Lightning Experience instructions:
Select the Gear icon | Setup
Click Object Manager
Select the Object for the Record Type that contains the picklist
Select Record Types
Select Record Type that contains the picklist
Click Edit for the picklist you wish to change
In the 'Default' field, select --None--
Click Save
Salesforce Classic instructions:
Select Setup | Customize
Select the Object containing the Picklist, then select Record Types
Click the name of the Record Type that contains the picklist
Click Edit for the picklist you wish to change
In the 'Default' field, select --None--
Click Save
Remove the default value: Picklist
Lightning Experience instructions:
Select the Gear icon | Setup
Click Object Manager
Select the Object that contains the picklist
Select Fields and Relationships
Select the picklist field you wish to change
Click Edit for the picklist value that is set as the Default
Deselect the 'Default' checkbox. Note: Make this value the default for the master picklist.
Click Save
Salesforce Classic instructions:
Select Setup | Customize
Select the Object containing the picklist, then select Fields
Select the picklist field you wish to change
Click Edit for the picklist value that is set as the Default
Deselect the 'Default' checkbox. Note: Make this value the default for the master picklist.
Click Save

Related

How to query for User Display Name using LisData.svc SharePoint Online

As you know when using the listdata.svc people picker fields return the userID, not the display name (createdby, modifiedby). I have been looking for a way to query the userprofile svc but have found nothing helpful.
What i am looking to do, is simply convert this ID to their respected display name. I am new to using this listsvc and this was never and issue using empty data views and XSL. If anyone has an example of grabbing list data, and showing the createdby, modifiedby, or a custom people picker field and showing their name not id that would be very helpful.
Thanks in advance
This is a default behavior, for a user field, only Id property is getting returned in the result. To return all the properties of user field $expand query options needs to be applied to the query, for example:
/_vti_bin/ListData.svc/Documents?$expand=CreatedBy,ModifiedBy
In that case the projected field values for CreatedByand ModifiedBy fields (from User Information List) are returned along with the result.
To return a specific user field properties, the $select query option could be specified. For example, the following query returns DisplayName (Title property) of CreatedBy and ModifiedBy fields:
/_vti_bin/ListData.svc/Documents?$select=CreatedBy/Title,ModifiedBy/Title&$expand=CreatedBy,ModifiedBy

Ability to click through salesforce reports

I want to perform the following. I have a report of summary type with four fields say name type date and status. Report is generated based on the filter. When the report is run, it displays the list of records for that report. I want some of the field values in the report to be a hyperlink.i.e., want that to be navigated to the record detail page if i click a particular field value. Please let me know what are the options available. Here is the screenshot attached for reference.
Mostly name fields in salesforce will have hyperlink by default. For other fields if we want to have we need to have custom formula field for the object. I created a custom formula field with the HYPERLINK function.
Here is the formula
HYPERLINK(
IF(
CONTAINS($Api.Partner_Server_URL_260, 'visual'),
'https://'+
MID($Api.Partner_Server_URL_260, FIND( 'visual', $Api.Partner_Server_URL_260)-4,4)
+'salesforce.com/',
LEFT($Api.Partner_Server_URL_260, FIND( '/pagename', $Api.Partner_Server_URL_260))
) + Id ,
custom field name/ or any string
)

Table with dummy row (ID 0) and auto increment index

Is it legal/okay to create a row with ID '0' and AFTER that set auto increment of that ID column to (1, 1)?
Why do I ask this?
I have a table Products with columns ID and Name. I want to show all Products inside my application in a ComboBox. Users can select a product but the default entry should not be 'Product 1' but something like '(Nothing selected)'. Is it okay to create a 'dummy row' with 'ID = 0' and Name = '(Nothing selected)' in database so the application will automatically display it as default selected item?
I think the better solution is to programmatically add a please select option and validate against it, assuming you don't really want users to have this selected? I guess in theory what you've proposed should be OK though? You'd have to be careful retrieving the values in order of their Id though, if you ordered them by name you'd have to ensure you pulled Id = 0 first then ordered the rest which feels like more work then programmatically adding the option where needed to me.
If your users can have nothing selected then programmatically add the nothing selected option and handle saving no value if it is selected. Otherwise you're saving data that represents no data really which could be deemed a waste of memory.

Changing abbreviation values coming for Database in ADF view Object

I am using ADF JDeveloper 11g Release 2
I am using Entity object called Project referring to actual database table. This table contains fileds that hold abbreviation values; for example this table have filed called STATUS that describe the current status for the project. this filed will have values like: 'A' for Approved, 'X' for Rejected, and so on.
In the interface( JSPX, or JSF Pages) I am just drag and drop the View object that refers to the Project Entity object. and the page will display the project records with their status as specified.
Question is:
Is there any way to change this observation values to the actual value somewhere; That is, Instead of having values like ( A, X,...) I want to have ( Approved, Rejected,...)
You can create a transient attribute at VO level. In the value of this attribute you can write groovy expression which will use the value of attribute named status and decode it.
Alternatively, you can alter the VO query using DECODE function by doing something like this :
SELECT name and other fields needed,
DECODE(status, 'A', 'Approved',
'X', 'Rejected',
'P', 'Pending',
'Default') decodedstatus
FROM projects;
You will need to have an additional attribute in VO in this case and can directly use the value returned by VO in UI.

SalesForce, How do I update a field on one object from using data from another obj?

In SalesForce. I have 3 objects in an MDR:
obj_1 ---< obj_2 >--- Contacts.
Object_1 = meeting types and budget
Object_2 = attendees at each meeting and money spent on each.
Each time a record involving a contact in obj_2 gets updated, I need to update a field in the contacts object ONLY if the meeting took place in the past year.
How do I do this? Workflows? Formulas?
This can be accomplished by a workflow or an Apex Trigger.
To use a workflow, go to Setup - Create - Workflow & Approvals - Workflow Rules.
Click 'New rule'
Select the Obj2 if that's the object that initiates change
Choose a name for the rule such as 'Update contact on Obj2 update'
Specify criteria for when workflow should be enacted by selecting 'formula evaluates to true' from a dropbox in the 'Rule Criteria' section and writing in the formula editor something like: DATEVALUE(MeetingDate) > DATE(YEAR(TODAY())-1, MONTH(TODAY()), DAY(TODAY())).
Click 'Save & Next'
Choose 'New Field Update' from the 'Add workflow action' dropbox.
Pick a name for the update action such as 'Update contact budget'
Specify the field to be updated by selecting from dropboxes below Contact and the field name in Contact such as ContactBudget
In the 'Specify new field value' section below choose 'Use a formula to set the new value' and enter the name of the field in Obj2 that specifies the budget like Meeting_budget__c
Save
Go to Setup - Create - Workflow & Approvals - Workflow Rules again
Click 'Activate' next to the rule you have just created
Greets,
lenin_ra

Resources