Hot answers tagged

7

An alternate way to do this without going through Schema.getGlobalDescribe(): SObjectType sObjType = ((SObject) Type.forName(myString).newInstance()) .getSObjectType()); speed comparison between above and getXXDescribe methods


7

Equality and the hash code value are based on all the properties of the SObject which makes sense. But when an object is placed in a hashMap, the hash code is used to determine which "bucket" the object reference is placed in at add time. So if you then change any property of the object after that, it is highly likely that the object reference will be lost ...


7

You can use the generic sObject: void recordsByFieldToMap(Map<String, sObject> target, SObjectField field, sObject[] source) { for(sObject record: source) { target.put((String)record.get(field), record); } } It would be used like this: Map<String, License_Item__c> items = new Map<String, License_Item__c>(); recordsByFieldToMap(...


7

This is probably because the clas Name contains the definition of another inner class like this: public class name{ public class test{ } } If so, you have to specify the parent class name before referencing the test inner class. So if you want to make a list of records of type name.test, you have to use: List<name.test>


6

There was a question a while back that can provide some context here: How to avoid instantiating object inside a loop? To summarize: Cloning is very fast Using the SObject constructor to set name-value pairs is also very fast, and faster than cloning if you need to change even a single field on a cloned record (e.g. newRec = record.clone(); newRec.Field = ...


5

try with sObject instead of Contact since get and set methods are available in sObject class. Replace your Contact objContact with sObject objContact in for loop. Also, try without Object obj as it should work fine without casting it to Object type


4

The API name for the Owner field is OwnerId. You will need to use the same here: mTargetFields.get('OwnerId');


4

This isn't possible today. I've reached out to the Surveys team to ask them either mark the object type as not available for Apex triggers, or make it possible to test Apex triggers on it.


4

From the sObjectType object, use the newSobject method to create a new record in memory. It accepts a single optional parameter for the record Id: targetSObject = new sor.getSObjectType().newSobject(sObjectID); As an aside, if you already know the Id, you don't need the describe: targetSObject = sObjectID.getSobjectType().newSobject(sObjectID); Also, you ...


4

What I feel is Discount_Reason__c would be null and hence it was not part of mapQuote. I quickly wrote a test class to test this behaviour. Account a = new Account(); a.name = 'TestMapAccount1'; insert a; a = [select Id,Name,Type from Account where id=:a.Id]; Map<String, Object> fieldsToValue = a.getPopulatedFieldsAsMap(); System.assert(...


3

Lead's Name is a compound field and you cannot directly write values in Name field. Instead you will need to use the FirstName, LastName (same as you have with Contact). The SOAP API documentation lists down the standard fields that is available for a particular SObject in Salesforce. You can additionally use the Object Management Settings for a particular ...


3

My personal opinion is go for Salesforce Files (Content objects). There are couple of good articles for using Salesforce Files over Attachment. Salesforce Files provides you more features especially when it comes to sharing when compared to the old Attachments. There are good resources available which can help you to get more details on this topic: ...


3

You won't be able to get the values of the related fields. You will be able to access only those fields which are present on the object on which trigger got fired. And as you are trying to access the related fields, they won't be present in the object your trigger is fired on. You'll need create the Set<Id> with the Ids and will have to query to get ...


3

I see you're new there, you can use the official documentation there ; This may be what you're looking for ?


3

An SObject by itself can be cast to EmailTemplate, however, Map cannot, that happens, because you may have not only EmailTemplate as values in Map, but also other SObjects. Example: Map<String, SObject> sobjectMap = new Map<String, SObject>(); sobjectMap.put('red', new Account(Name = '123')); sobjectMap.put('green', new Contact(LastName = '123')...


3

You can easily parse your String into Map and then serialize Map itself. Here is an example how to do it: String toMap = 'Profile:[UID=, crmId=0000o00002XXXXxXXX, email=top@top.com, firstname=null, lastname=test]'; Map<String, String> ans = new Map<String, String>(); String actualValues = toMap.substringAfter(':'); actualValues = actualValues....


2

You can use below equivalent dynamic soql. List<Opportunity> opps = Database.query( 'SELECT Id,Name,Amount,CloseDate,Stagename,Near_to_Close_Date__c '+ +'FROM Opportunity '+ +'WHERE Stagename Not In (\'Closed Lost\', \'Closed Won\')'); More on Dynamic soql.


2

Please verify that the sobjectType parameter is spelled correctly. If you're using an object in a namespace, you may also need the namespace for it to operate correctly (e.g. "packagens__objectname__c"). The following code works in my org: ({ doInit: function(component, event, helper) { var action = component.get("c.method"); action....


2

It depends on the fields and their values being added for that SObject. Refer to Sets of Objects for details: Uniqueness of sObjects is determined by comparing the objects’ fields. For example, if you try to add two accounts with the same name to a set, with no other fields set, only one sObject is added to the set. Sample code from the link: // Create ...


2

You can access the the Salesforce ORG agains which you are performing operations and can check under the Schema builder, where you will see something like this: , additionally, you can check the Object Reference for Salesforce and Lightning Platform


2

Use Map<String, Object> getPopulatedFieldsAsMap() method on the sobject. It gives you a map of fields and values that got queried. Please refer to this release notes for more information: (http://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_apex_sobject_getmap.htm)


2

It's not overwriteable because of the hidden background logic regarding related lists. Namely, they can either be a normal List<Sobject> (for some specific type), or they can be a QueryResultIterator (or a similar type), which is when the list isn't populated directly, but instead is given a database cursor to iterate over. In order to preserve this ...


2

Formula fields are inherently read-only. As you found, you cannot write to them. SObject.recalculateFormulas() doesn't recalculate cross-object formulas. From the documentation: This method doesn’t recalculate cross-object formulas. If you call this method on objects that have both cross-object and non-cross-object formula fields, only the non-cross-...


2

Generic SObject and SObject[] are not yet supported at the interface between LWC and Flow (TLDR: You can't get there from here). We're working on it right now, though, and hope to get it into Summer '20. You can get an early taste for some of the experience by looking at how we implemented it for Apex Invocable Actions in Spring '20 We don't have any short-...


2

You can use getRelationshipName to determine the name: for(ChildRelationship rel: SobjectType.Opportunity.childRelationships) { System.debug(rel.getRelationshipName()); System.debug(rel.getChildSObject()); System.debug(rel.getField()); } Please note that not all relationships have a name. Note also that you can't get the parent sObject, it's ...


1

This issue was fixed in JetForcer 2.0.15 https://plugins.jetbrains.com/plugin/9238-jetforcer--the-smartest-force-com-ide/update/64221


1

Since API 46, there is a new FieldType json. You can see an example of standard object using this field type on the field "RecordData" from object "ApiEvent": https://developer.salesforce.com/docs/atlas.en-us.220.0.api.meta/api/sforce_api_objects_apievent.htm?search_text=ApiEvent Jetforcer must be using an outdated force-wsc (version >46.0.0) package but ...


1

Using Salesforce files over attachments has many advantages:- Migrating to Files instead of Attachments, or to Enhanced Notes instead of Notes, is a good idea because Salesforce Files provide you much more capabilities around sharing the file (or enhanced note) with other users, groups, or records. It also supports file previews and revisions. It is the ...


1

If you create a record multiple times without cloning then all the record relationships are disjoint. So, changing an object will not change other objects. If you clone like the above way then that is known as Deep cloning. So, All fields on the SObject are duplicated in memory, including relationship fields. Consequently, if you make changes to a field on ...


1

You can check the Schema Builder in Setup for available fields in your org (including custom fields), the Field Reference Guide for standard objects and fields, and other places as well.


Only top voted, non community-wiki answers of a minimum length are eligible