I have a custom object. I would like to refer the custom field from opportunity object in my custom object as a read only field. How to do that?
You'd need some relation between the 2 tables in database. For example if you add a lookup field in your custom object, call it Opportunity__c & populate it on few recods, then you can display Opportunity Name but also reference other Opportunity fields in reports or formula fields. You could make another field (type = formula and then pick what matches the field you're interested in, text, date, checkbox...). Make the formula similar to Opportunity__r.MyCustomFieldOnOpportunity__c and you're good to go.
If you can't define any sensible relation between Opp and your custom object you'd have to tell us what exactly you try to achieve. Perhaps there's config (or code) way to copy values across. But making a lookup field and then a formula that jumps through this lookup is the most natural way.
Related
I have two objects - "Account" and "Appointment". I'm trying to pull the value of the field "Status" from the "Appointment" object where "Account.Initial_Date" matches "Appointment.Date_Time". I initially tried making a new field in the "Account" object to return a text field and see if maybe it would return the first value:
Appointment__c.Status__c
Which results in the error:
"Field Appointment__c does not exist. Check spelling."
I was told that it's too difficult to link from "Appointment" to "Account" because there can be multiple appointments per account, which is why I'm trying to link based on the date fields. My next attempt was using VLOOKUP, but I read that this only works between custom objects, and I think I'm working with standard objects here... what kind of solution should I be looking for?
Adding the tag apex here in case this can only be achieved via a script of some sort - if that's the case, I'll make attempt via that.
I was told that it's too difficult to link from "Appointment" to "Account" because there can be multiple appointments per account
This is incorrect. That relationship appears to be exactly the same as that between Contact and Account - one Contact, many Accounts. It's a very common relationship pattern in Salesforce.
If an Appointment is logically related to an Account, it should have a relationship field referencing the Account object to which it is related.
However, having a one-to-many relationship does not mean you can trivially represent specific data points from the many side to the one side. The native tool to do so is the Roll-Up Summary Field, but it does not apply to your use case.
There's really three ways to implement your objective, which is essentially implementing a variant of a roll-up summary. VLOOKUP(), which works only in Validation Rules, does not apply here.
Write two Apex triggers (one on Account and one on Appointment) to react to all changes that would influence what value should appear in the Account__c.Status__c field.
Write equivalent Process and Flow declarative automation, which cannot get 100% of the way there because Process Builder and Flow cannot react to delete events.
Use the free and open source Declarative Lookup Rollup Summaries application to define a roll-up summary. DLRS can populate a field from the child object (Appointment) to the parent (Account) based on a sorting by another field (Date_Time__c).
I am kind of new to Salesforce. Could you please let me know what is the difference between Standard Fields and Custom Fields in Salesforce? Can I consider combination of Standard Fields as the unique identifier for a record?
Custom fields are just that. Fields that have been added to the standard Salesforce schema to tailor the data for each object. The user who creates the field can specify the field type and any applicable limitations, such as the maximum number of characters in a text field. These fields might be added to an Org via a managed package or through direct customization.
Standard fields in contrast are those that are already present in the Salesforce schema when a new Organization is created. They are present in all Orgs where the same features are enabled. You can't customize these fields to the same degree. E.g. you could change the display label, but not the underlying API name or data type.
You can see the list of the standard fields in the Salesforce Field Reference Guide
From an API perspective, custom fields are usually identified by a __c suffix (there are a few exceptions, such as GeoLocation fields).
Can I consider combination of Standard Fields as the unique identifier for a record?
You would usually rely on the Id field to be unique. If you wanted to augment this with another unique value, you would create a custom field and mark it as an External ID.
A composite key isn't directly supported. Instead you need to create a Unique Text field and then use a workflow field update or before trigger to populate the unique field with the components of the composite key.
Incidentally, the salesforce.stackexchange.com site is a great place to ask Salesforce specific questions.
I was creating the Recruitment App with Salesforce by going through the study material. I have a question. In the custom object, I saw that I have created a Standard field named "Position Title" and after that I have to create all other fields as "Custom Field & RelationShips". My question is -> Is it the case that Position title is the primary key/unique identified in this object? If that is the case, why the data type is Text(80)? I can have two records with same Position Title "Sr. Manager", right? In that case, my primary key/unique constraint violates.
I have attached the screenshot below:
I am new to salesforce. So please help me in understanding the system? Thanks in advance
Salesforce always create by default a group of fields called 'Standard fields', such as Created date, Last modified Date or Owner. In that list you'll probably interested in two, Id what is the primary key/unique identifier and Name which is a Text(80) field that you can't modify (only define if it's going to be text or an autonumber).
So to answer your first question, Name is actually not unique nor you identifier, and unfortunately at the moment salesforce doesn't give an easy option to have this functionality, in order to achieve that you could write a trigger with that restriction or define the Name as an autonumber and add the position title as a custom field with the unique checkbox marked.
The only problem with that last implementation is that the Name field is a special one with some behavior associated with it and it might obscure some of this functionality. For example, it will be the field shown when adding a relation to that object or in case you add the field to a related list, it will include a link to the actual object, but it will show the autonumber instead of the position title what doesn't give much information about the related object.
Here's a link with other people asking for the same idea.
My client requested to have a field that can be a lookup on either contacts or users.
I know that Salesforce does something like this in some standard objects. For instance, the Task objects has fields "who" (lookup on account or contact) and "what" (lookup on case, opportunity, and more stuff). Also, I know the Owner field on Case can reference either a User or a Queue.
Can I make custom fields that look up on more than one kind of object?
You can't create a custom lookup field that references multiple types. You would have to create 2 different fields.
I've been using cakephp for a while, but have not learned all the ins and outs yet so I may be missing something simple. Or the problem may lie with my database structure. Either way, if anyone has any idea of what I'm doing wrong, please share.
Is there a way to order the data returned by cakephp's find using values stored in another table?
I am creating custom form fields on a per category basis, so when I choose a particular category to post in, custom fields will be added to my form. I have 3 tables: Posts, Fields, and Answers. The Posts table stores the basic static information for the post, such as id, category_id, title, and description. The Fields table stores the custom field data, such as category_id, field_label, field size, etc. The Answers table stores the values that are entered for particular fields, such as post_id, field_id, value.
I am trying to display the posts for a particular category, and create html table headers on the fly, using select fields, set by a column toggle in the fields table, and also select the answers associated with that particular field and post.
I am able to select all the data I want, and paginate everything just fine, but what I can't seem to figure out is how to order the data using one of the dynamic column values. For example, if I have year, make, and model as 3 custom fields, I would like to click the year column to sort my results by the year values, and if I click the make column, I would like to sort my results by the make values, etc.
I know how to order the results by a particular field inside the posts table, such as id or title, but is it possible to order using the custom fields? Am I setting up the database and/or something else wrong, and if not is there are particular cakephp method or sql command that I need to use in order to sort by the custom fields? I'm not really well versed in complex sql commands.
Thanks.
I'd suggest you pass the field name and sort direction in the URL (GET param). So when you have your table header link, form it so that it links to a URL as so:
http://somesite.com/pages/index/sort:customfield1/dir:asc
Then when you're grabbing the data from the db in your find() query, include the named parameters as the order parameter that can be sent to find.
You'll need to determine a default sorting column and direction. Maybe have that be selectable with a boolean field in the schema -- if there are no parameters sent to the action above, pull the field from your other table that has default set to true in the record.
To clarify: when a user visits a given action, first you'll pull the custom fields from the other table. Then using those fields (either the default as mentioned above, or the named params passed in the URL) form the query for the actual data, using the order parameter.