3 votes

Adding a local variable into a trigger gives error

This is due to an effect called Name Shadowing. Basically, when you create a class or variable that conflicts with a system class, your local copy takes predence. In addition, Apex is case-insensitive,...
sfdcfox's user avatar
  • 487k
2 votes
Accepted

Adding a local variable into a trigger gives error

Try String url = System.URL.getCurrentRequestUrl().toExternalForm(); The reason being, you're creating a string call 'url', and you're trying to reference something called 'URL'. With the System ...
Nick C's user avatar
  • 6,553
2 votes

List index out of bounds: 0 in IF condition

This behavior is just how lists work in Apex. If you do not know an index is in the list, and you try to retrieve it, you get this type of error. You must first check the list is not empty to use a 0 ...
Adrian Larson's user avatar
  • 150k
2 votes
Accepted

Trigger IF statement will not fire

Assignment rules run after the after insert triggers, so OwnerId will be the user who created the record if unset, or the specified user or queue if set from the parent transaction. See Triggers and ...
sfdcfox's user avatar
  • 487k
2 votes

caused by: System.SObjectException: Opportunity.AccountId does not belong to SObject type AggregateResult

You cannot retrieve any data off an AggregateResult using field tokens (SObjectField). You must always use a String instead. Even if it would work, your field token must actually match the object in ...
Adrian Larson's user avatar
  • 150k
2 votes

AfterInsert caused by: System.FinalException: Record is read-only

That's because records contained in trigger context variables are read-only in after triggers (and you're passing trigger.new, a trigger context variable, into createCaseManually()). In this case, ...
Derek F's user avatar
  • 60.9k
2 votes
Accepted

Field is not writeable: Account.ShippingAddress

Billing and Shipping Address fields are compound fields. They're read-only (as indicated by your error) and mostly just a quality-of-life thing. You'll need to explicitly copy each individual ...
Derek F's user avatar
  • 60.9k
2 votes
Accepted

How to rearrange the priorities of the records using Apex?

Your code is trying to move the requests one priority at a time (-1 and +1), but this assumes that all of your priorities are already correct to begin with. What happens if, for example, a record is ...
sfdcfox's user avatar
  • 487k
2 votes
Accepted

Error: Apex Trigger - Read only record (Opportunity/Quote)

Data in trigger.new and trigger.newMap is read-only when you're in an after trigger (and old/oldMap are always read only. Not an issue here, but worth mentioning). Collections (lists, maps, sets) ...
Derek F's user avatar
  • 60.9k
1 vote
Accepted

Trigger Error Handling

If any part of a transaction fails without the error being handled then the entire transaction is automatically failed. An error can be handled by catching an exception, or where an error is added to ...
Phil W's user avatar
  • 35.5k
1 vote

Apex Trigger rollback DML operation if error occurs in bulk insert

It is a bit tricky without knowing the exact logic that your after insert trigger is running, but from your original post it seems that the connector is using Salesforce's Bulk API to perform the DML ...
Renato Oliveira's user avatar
1 vote
Accepted

Create ContentDocumentLink after insert ContentDocument error

What I did in the following is: direct retrieval of the FileGroupId__c from SomeCustomSetting__c as an Id, eliminating unnecessary type casting. Also added, null checks are introduced to ensure the ...
TSCAmerica.com's user avatar
1 vote

caused by: System.SObjectException: Opportunity.AccountId does not belong to SObject type AggregateResult

When you're using SObject's .get() method with an AggregateResult (and AggregateResult is a subtype of SObject), you need to pass it a string containing the field name. Using a field token won't work. ...
Derek F's user avatar
  • 60.9k
1 vote
Accepted

caused by: System.SObjectException: Opportunity.AccountId does not belong to SObject type AggregateResult

Opportunity.AccountId Is a sObjectField token that represents a field. Specifically, it's a field that doesn't exist on AggregateResult. Instead, give it an alias, and use that, instead: List<...
sfdcfox's user avatar
  • 487k
1 vote

Querying History Object in update trigger, not showing the new History Object record?

History records are not calculated until the end of the transaction, so the earliest you can see those new entries would be in asynchronous code that runs after the transaction that caused the changes ...
sfdcfox's user avatar
  • 487k
1 vote
Accepted

Updated triggering record with value from related record

Pull the name in by its parts rather than using the 'full name'. Create a formula in the Flow that pulls in User FirstName and LastName (User.FirstName &" " & User.LastName or ...
Adam Vatterott's user avatar

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