Values in scripts - newmips

I have an app with an entity Order with a field Status. The values of the Status is "related to" an entity Status in the admin module which contains one field with values : Shipped, Resolved, Cancelled, On hold, Disputed, In Process.
Is it possible to define these values in the nps script ?

No. It's not if you use a field "related to". You must fill in form of entity status to provide values you want.
If you want your drop down list to rely on values that you write in your script, you must use "enum" type.
add field Status with type enum and values Shipped, Resolved, Cancelled, On hold, Disputed, In Process
But this way, you won't benefit from status component features.

Related

Custom field on opportunity object not available in historical table

I have created a custom currency field, in Salesforce, on the standard Opportunity object. It's not a formula field; a workflow updates this field on edit/new opportunity. I have enabled Field History tracking on this field.
I want to include this field on a trend report with 2 snapshots of the field's value. The issue is that I don't see the field's historic value available to be selected under the "Opportunity (Historical)" field list. So, it seems like the value has not been added to this related object. (I can see the other standard fields' snapshot values.)
I went to the Report Type to see if I could add it there, but again, it's not available to be selected; only the field that's in the actual opportunity is selectable.
What steps have I missed?
if your field history report isn’t returning any records even though you know that records have changed, then ask your admin to turn on field history tracking.
Resource:
https://trailhead.salesforce.com/content/learn/projects/customize-a-salesforce-object/account-field-history-tracking
https://help.salesforce.com/s/articleView?id=sf.reports_filter_old_value_new_value.htm&type=5
PDF:
https://resources.docs.salesforce.com/latest/latest/en-us/sfdc/pdf/field_history_retention.pdf

Custom Work Item Type: Adding Unique ID Constraint

I created a custom work item type (WIT) and I added a field of type integer for usage as unique identifier. It is called ID and is a required field.
I would like the following constraint:
When a user creates a new work item of this type and inserts a value for ID, a check is run to verify that there is no work item of this type that already has the same ID. If so the user should be prevented from creating the work item.
The point is to avoid having multiple work items of this type with duplicate unique IDs. I looked into the "Rules" section to see if I could add a constraint to check for pre-existing integers of the same value, and prevent the user from creating the WIT if it already exists in the system. However I was not able to find a way to do so. I also tried making the field of type identifier but that just forces you to user a person (not number) as an identifier.
Your goals are not clear in your question. You already have ID (or System.Id as system reference) for each work item type. You do not need to create something new. Rules in work items types do not support complex logic (Sample custom rule scenarios).
As a workaround (if you need the second id for your work item type), you can:
Set default value 0 for your field.
Create a custom app to:
Find 0 ids: Query By Wiql.
Updated them to the calculated value: Work Items - Update.

Does it make sense to have required null parameter?

We can define a parameter that is required and nullable in Flutter version 2, does it make sense? Why should we have a required parameter which accepts null?
In terms of database values like in SQL, NULL specifically refers to a "missing" value. In other words it references a value that could or will be defined but has not (yet) been.
To answer your question, it depends on what the field is and whether or not it's being stored in any kind of state, whether that state is front or back end.
One example where I would consider using a nullable but required field would be if I'm soft deleting records and am marking a deleted_at column. I want to require this field for a soft delete, but it is expected to not be defined until an actual delete occurs, whenever that is.
Flutter is basically a data-driven UI that should have one UI page for any given state. So if you, say, had a user record that was soft deletable on the backend and a profile user page that might be shown (to an admin or whatever), you might want to set the deleted_at field in the Dart code to be required but nullable to distinguish the state of a soft deletable user record.

Keeping two fields in sync when one of them is updated

The application I'm working on is a character based application. there is a field adfc.unme-code in a table and another field arbu.unit-code-shu. These two fields are shown in different windows but they must be in sync. When I update unme-code, unit-code-shu must be updated too.
Is a simple assign statement would be enough or should I do something else? Also, should I use the actual fields or a buffer?
You can use the ASSIGN statement in your code to assign both values at the same time. If there's a possibility of some other process changing those fields, you can create a database trigger procedures on each field to copy the value over to the other field. In the Data Dictionary, view the field properties and click on the "Triggers..." button to do that.
Yes, ASSIGN is used to set the value of a buffers/records field. However: certain critera needs to be met:
The buffer/record needs to be available.
You must have the "lock" of the buffer/record.
If you have the record available and locked you can simply do:
ASSIGN arbu.unit-code-shu = adfc.unme-code.
To make this code "safer" you can simply make sure that arbu is available and not locked by any other user. And finally it will handle if your assign fails because you have no lock at all.
IF AVAILABLE arbu AND NOT LOCKED arbu THEN DO:
ASSIGN arbu.unit-code-shu = adfc.unme-code NO-ERROR.
IF ERROR-STATUS:GET-NUMBER(1) = 396 THEN DO:
MESSAGE "Apparently the record is locked." VIEW-AS ALERT-BOX ERROR.
END.
END.
If you do not have the record (or the right locking) you need to look into your application and see how you can add this feature. What identifies the right record of the second table? A single id? Something else? Are there always a 1 to 1 relation between arbu and adfc etc?
Perhaps your application has a simple way of setting the value of a field. If there is a architecture at place you should try to stick to it...

Salesforce: trigger on related list

Suppose I have two objects
1.Account- standard object[it has a field name Status_c which is a picklist having value inprogress and closed]
2.Client_c - custom object[it also have same field name Status__c which is a picklist having value inprogress and closed]
and Client__c has lookup to Account name which means Account has a related list of client object .
My question is :
I want to write a trigger where if I put account status to "closed" I can not put client status to "closed",it should throw an error message on client object or if I put client status to closed I can not put account status to closed vice versa.
Can any one please help me to write a trigger on this??
Conceptually, I think what you are looking to do is set up Validation Rules on both of those objects. Your validation rule on Client_c should be pretty simple: TEXT(Status_c) == 'Closed' && TEXT(Account_c.Status_c) == 'Closed'
The more interesting piece is how you handle making sure none of your related items are Closed when you move the Account to Closed. I tend to prefer creating a field on the Account that keeps track of the status of the related items (checkbox) that basically tells me whether it is valid for me to change my status or not. In this case, the validation rule becomes pretty simple. In order to set that boolean value, I end up using a Trigger on Client__c that basically just grabs all the Accounts when a Client is being modified in the batch (taking into account both inserts, upserts, and deletes):
SELECT Account__c.Id FROM Client__c WHERE Id =: Trigger.new OR Id =: Trigger.old
Then create a Set of all the Account Ids (in this example, named accounts), and run a query to retrieve ALL Clients related to those Ids (in a single query to ensure you don't hit SOQL limits).
SELECT Account__c.Id, Status__c FROM Client__c WHERE Account__c.Id =: accounts
From the results of this, you will iterate over all of the entries, tossing them into a Map keyed by the Account Id where the value is a List of Clients. When you are done, run a query to get all accounts based on the "accounts" list from earlier (which was just a list of strings, not actual Accounts), subsequently iterate over all the Clients associated with that Account, and if a Client is marked as Closed, you will update the metadata of that Account accordingly. If no Clients are closed, the Account will be marked as such. Once you are finished, run an update statement to update the list of Accounts that you have modified.