Contents
- 1 How to look up a custom object in apex?
- 2 How to look up a field in apex?
- 3 Why is SQL-apex compare value against CURRENT USER ID invalid?
- 4 How to work with schema class in apex?
- 5 How to create custom fields in apex dynamically?
- 6 How to insert a record with lookup value in apex?
- 7 How to iterate over fields in a sobject in apex?
- 8 Where are the update fields in apex trigger?
- 9 What’s the best way to create an apex trigger?
- 10 How to create custom text fields in apex?
- 11 How to query more than one level in apex?
- 12 How to dynamically reference object fields in apex?
- 13 Do you need to hard code an object name in apex?
- 14 How to update fin accounts in Salesforce apex?
- 15 How to find all apex references in Salesforce.com?
- 16 Can a string in apex be null or empty?
- 17 What do you need to know about caching sites in apex?
- 18 How to make field read only for user and editable by Apex?
- 19 How to create custom setting record in apex?
- 20 How to test batch apex with only one execution?
How to look up a custom object in apex?
If Project_Sheet_Opportunity__c field is the lookup field for Opportunity in Project sheet custom object, custObj.Project_Sheet_Opportunity__c should work. As lookup field references displays Name on the screen, but internally its an Id.
How to look up a field in apex?
As lookup field references displays Name on the screen, but internally its an Id. So Project_Sheet_Opportunity__c gives you Id value when you reference them in queries. Hope all this makes sense.
How to get current user info using APEX?
String FirstName = UserInfo.getFirstName (); String LastName = UserInfo.getLastName (); String UserName = UserInfo.getUserName (); String ProfileId = UserInfo.getProfileId (); String UserRoleId = UserInfo.getUserRoleId (); TimeZone tz = UserInfo.getTimeZone (); String DefaultCurrency = UserInfo.getDefaultCurrency ();
Why is SQL-apex compare value against CURRENT USER ID invalid?
I am fairly new to APEX. Any ideas why this code is invalid? In Apex you retrieve the user by using :APP_USER. This bind variable contains the value used by the user to log in to the application (the value from :P101_USERNAME on the login page thus).
How to work with schema class in apex?
Working with Schema class in Apex is pretty much straight forward but when it comes to LWC there are a few things that we need to handle in a different way. We will be looking at the bottle necks and all the work arounds that we will try to implement to get this working.
Where to find project sheet opportunity in apex?
The Project_sheet_Opportunity__c is the lookup field for the Opportunity. Then you need to query the records for Project sheet again explicitly. Hope this helps. Thank you so much. I understand the whole thing far better now.
How to create custom fields in apex dynamically?
Not using API’s, Can we create fields for the objects using apex programming dynamically. Any one had know about it please provide the code or suggestions to create fields. You can try the following. Consume the Metadata api in apex. This will require a bit of tweaking in the Metadata api wsdl.
How to insert a record with lookup value in apex?
This will most likely be coming from the line: (please indicate in your responses which line is throwing the exception) There are a couple of problems with this line: You are using a short hand syntax that assumes exactly one Code__c record will always be returned by this query.
How to skip the ID field in apex?
You are querying the Name and Code__c fields and then using the Id field, which isn’t part of the SOQL query. Check if the field is required in the profile then if this is not required you could skip the field when you are creating the record. Be sure that field is not an a master detail because by default it is required.
How to iterate over fields in a sobject in apex?
As an Apex developer writing code with layers of code abstraction, I would like to be able to efficiently iterate over all the fields in an SObject so that I can convert SObjects into JSON.
Where are the update fields in apex trigger?
Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times): Trigger.UpdateCommissionFields: line 9, column 1 I understand that the issue is within the List, but I’m just not sure how to correct it.
What causes an unexpected exception in apex trigger?
Review all error messages below to correct your data. Apex trigger UpdateCommissionFields caused an unexpected exception, contact your administrator: UpdateCommissionFields: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 rows).
What’s the best way to create an apex trigger?
You will need to understand some concepts in order to start with Apex, the Apex Developers Guide has some great introductory sections, as well as these on Apex Triggers. The basic steps in your trigger will be as follows. Loop over the Trigger.new list and store in a Set list all the related Opportunity Id’s.
How to create custom text fields in apex?
Anybody knows how to create custom text fields on salesforce.com objects using apex? You can do that by using the metadata API and a web service written by Andrew Fawcett that you can find here. And here is the original thread.
How to set field level security for profile from apex class?
You can also refer to https://developer.salesforce.com/forums/?id=906F00000005HTsIAM. Shubham Nandwana. Please see below query.
How to query more than one level in apex?
List < Customer__c > customers = [ select Name , ( select Name , ( select Quantity__c, Product__r. Name from Line_Items__r ) from Orders__r ) from Customer__c where Id = : customerIds ]; SOQL statements cannot query aggregate relationships more than 1 level away from the root entity object.
How to dynamically reference object fields in apex?
Upon modifying the code from .getSObject to .get I now receive the following error: This error is referencing the line where I assign scope [s] to existingCustObj [0]. getSobject () is the generic sObject method for obtaining an sObject instance value for a given relationship field name.
Which is a use case for apex getsobject?
The use case for this functionality is that if blank fields are returned from an endpoint which we are getting the data from, I do not want the retrieved field data to overwrite the existing fields if there is data in the existing fields.
Do you need to hard code an object name in apex?
You don’t need to hard code the Object name as you have specified, you can indeed do it dynamically, for example: The docs suggest you use the newer Schema.describeSObjects (List) method – that lets you pass one or more names of objects as a list, and get back the results.
How to update fin accounts in Salesforce apex?
Using the fin_acct_txt__c=fin_accounts__c.name I would be able to get the fin_accounts__c.id and update the transactions__c.fin_acct__c with that data. But being new to Apex seems to be causing me some problems that I’m unsure how to resolve. Here’s a copy of what I’ve done to date:
How to check checkbox field in apex trigger?
The requirement is that if a specific ObjectA__c has a related ObjectC__c record, check the Checkbox__c field from ObjectB__c related to that ObjectA__c record. According to what you’re showing, ObjectC__c has a lookup on it to ObjectA__c, so there’s no need to run a query to get the related ObjectA__c record.
How to find all apex references in Salesforce.com?
Enter the class name you want to search and select the scope (mostly “Enclosing project”). Click on “Search” button. For ex. If we want to find all references for class “utility” Now you will see the list of all components where the class is referred with navigation to actual line.
Can a string in apex be null or empty?
Conversely, Strings in Apex can be null or empty and can include leading and trailing whitespace, which can be used to construct a message. The Solution sObject field SolutionNote operates as a special type of String. If you have HTML Solutions enabled, any HTML tags used in this field are verified before the object is created or updated.
Can you instantiate currency in any type in apex?
You cannot instantiate Currency in any other type of Apex. For more information on the AnyType data type, see Field Types in the Object Reference for Salesforce. In API version 16 (Summer ’09) and later, Apex uses the higher-precision Decimal data type in certain types such as currency.
What do you need to know about caching sites in apex?
For details on caching Sites pages, see “Caching Force.com Sites Pages” in the Salesforce online help. The name of one or more custom controller extensions written in Apex that add additional logic to this page. An identifier for the page that allows it to be referenced by other components in the page.
How to make field read only for user and editable by Apex?
You can use any of the above 4 methods in your use case. You can create validation rule to restrict user other billing users to update this checkbox. Also you can create separate permission sets for different users for which this field can be readonly.
How to create custom fields in Visualforce apex?
To do this you need to use actionPoller in Visualforce context or via Batch Apex job (@future is not suitable as you cannot creating a polling condition in this context) in other contexts, such as Apex Trigger in your case.
How to create custom setting record in apex?
Hierarchy Custom Setting Methods. 1 getInstance () Returns a custom setting data set record for the current user. The fields returned in the custom setting record are merged based on the 2 getInstance (userId) 3 getInstance (profileId) 4 getOrgDefaults () 5 getValues (userId)
How to test batch apex with only one execution?
When testing your batch Apex, you can test only one execution of the execute method. Use the scope parameter of the executeBatch method to limit the number of records passed into the execute method to ensure that you aren’t running into governor limits. The executeBatch method starts an asynchronous process.