New answers tagged

0

It's not the neatest thing, but you could used the format() method of the DateTime class to convert the DateTime to a string with an adjusted timezone, and then convert it back to DateTime. More information about the format() method can be found here. String timeFormat = 'yyyy-MM-dd HH:mm:ss'; String timeZone = 'Pacific/Auckland'; DateTime convertedStart = ...


0

This is what is happening: The VF page is instantiating two controller objects ExtOne, ExtTwo The custom VF component is instantiating a third controller object ExtTwo The JS line const values = '{!value}'; is invoking the getter on the page's ExtTwo object. But that object's setter public String extraInfoTitleFieldKeys {get; set;} is never invoked; it is ...


1

After some annoying debugging using a special logging tool we built that writes logs as records, I found the culprit was in List.contains(Object). This method does not know how to deal with an Id parameter when it's template type is also Id . My first step was to replace: if (RECORD_TYPE_IDS.contains(customRecord.RecordTypeId)) with... for (Id i : ...


0

I found a solution--its on the Google Side. You can pass the base64 encoded body, and when done properly, get it decoded on the other side which eliminates the need for decoding in apex. However, if anyone needs to decode a file in apex, this might do the trick


1

You are using the old Note object, which supports only plaintext in the body. See Note documentation. If you want to use rich text in a note, you need to enable the new Notes functionality and then use the new ContentNote object. See ContentNote documentation


1

On the face of it, a Batch on Contract would be appropriate. I would write the batch to iterate the Contracts and have the execute perform the aggregate query and related processing. Your aggregate query would simply change to: public Database.QueryLocator start(BatchableContext context) { // You might like to restrict the contracts examined, e.g. to ...


2

Rather than using a Custom Setting, create a new unique External Id Text field on Activities (which includes Task and Event) to store the Call Id. Your code cannot reasonably expect to maintain a persistent mapping between Call Ids and Task Ids in Custom Settings. Instead, store the Call Id on the Task object itself, and handle updates by upserting ...


0

It is 2019 and I think this question deserves and update. I don't know how this was working before but if one does the comparison with the like instead of = you get the match. The like is case insensitive were = is case sensitive. If you do where "JOHN" like "john" you get a match. Docs here


1

You can easily remove the @seeAllData from the test class. Just take a look to this page Test classes has @seAllData set to false as default. you can set in this way the setting to true only for interested methods. The @isTest(SeeAllData=true) annotation is used to open up data access when applied at the class or method level. However, if the containing ...


1

Each SObject has a sharing object (for example Account has AccountShare). You can fetch these with the condition ParentID = :accId. Further details here


0

If you are talking about sharing, you can read this part of the developer guide. If they have already the same permission sets/profile, this is the way.


0

No, it's not possible. Executing this code in the anonymous window will throw an error. List<Id> listofUserIds = new List<Id>{''}; List<Id> allRecordIds = new List<Id>{''}; List<UserRecordAccess> res = [SELECT RecordId FROM UserRecordAccess WHERE UserId IN :listofUserIds AND HasReadAccess = true AND RecordId IN :...


0

You can create an attribute to store the latest search id with name searchId. Then you can use separate methods for keyup and keydown to search and then remove the previous search id. CMP: <aura:attribute name="searchId" type="Object" /> <span onkeyup="{!c.handleSearchEvent}" onkeydown="{!c.handleClearSearchEvent}"> <lightning:input ...


0

If you look at the timer event handler, it is using "this". I assume you want this to reference the helper. In which case you need to change how you set the timer: timeId = setTimeout(helper.handleSearchEventClicking( component, mapName, listForSearchDisplay, controllerMethod, event.getSource()...


0

Important to note that while the other answers here will do what you're looking to do, there is a subtle gotcha I discovered while making a method to grab any phone numbers off of a record on a standard controller: public String getSObjectPhoneFields() { SObject sObj = scon.getRecord(); Schema.DescribeSObjectResult objectDescribe = sObj....


1

You'll want to use the put() method for this. for(Schema.FieldSetMember field : SObjectType.Account.FieldSets.AccountFieldSet.getFields()) { String fieldName = field.getName(); targetRecord.put(fieldName, sourceRecord.get(fieldName); } Information regarding the put() and get() methods as they pertain to SObjects can be found here.


0

We use Solenopsis for deployments at my job. You should be able to create a zip with all the components you want to validate and then leverage deploy-zip [zip_file] --dryrun to check for deployment errors.


0

The compiler error is telling you that you're not using the correct syntax to create an instance of a custom object record. You need to explicitly call out a field that you want to set. So something like the below: donList.add(new Donation__c(Contact__c = c.Id , My_Boolean_Field__c = false)); However, Adrian Larson's answer is a better example of how to ...


3

It looks like what you are trying to accomplish is to return all child records for the specified Contact.Id. Just query on and return Donation__c records directly. If your lookup field has an API Name of Contact__c, your entire method body would look like: return [SELECT Name, Email1__c FROM Donation__c WHERE Contact__c = :recordId];


3

A List is basically an Array. Whenever you query for data you usually get a List back. The shorthand SObject obj = [SELECT ... FROM ... LIMIT 1]; can be used to get one record back, but error handling is a bit more difficult. When you are absolutely sure that you will get a record back, the shorthand is fine, but if there is no record, you will get a System....


1

It looks like you expect one record in your query, but you're storing it in a list? https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_list.htm Since it's a list, you can't simply just reference the whole list (which contains elements of whatever data type you specify). You need to either specify the specific ...


0

It depends partially on how you need to use the data. It may be easier for you execute two queries, but you could also try something like the following to do it in a single query: [SELECT Id, (SELECT Id FROM Pire__r), (SELECT Id FROM School__r) FROM Student WHERE Id IN (SELECT Student__c FROM Pire__c)] This should return a list of Students and should ...


2

Instead of Student_Name__r.Id, just use Student_Name__c. They technically mean the same thing, but doesn't fall foul of the relationship rule. In general, you should actively avoid the use of __r.Id instead of simply using __c, because it is more efficient in terms of memory use, amount of code you need to type, and to avoid certain classes of errors such as ...


0

In the end, the only solution was to get the products with an APEX controller. this.allLineItems=new List<OpportunityLineItem>([select id,UnitPrice,Product2.Name,Quantity,Product2.Hasavshevet_product_ID__c from OpportunityLineItem where OpportunityId = :Opp.id ORDER BY SortOrder]); this.userinput = this.allLineItems[0].Product2.Name; m_names ...


0

You'll want to query the existing leads by email and company in order to identify potential duplicates. Here's one possible solution: public static Map<Boolean, Lead[]> leadCheck(Lead[] newLeads) { // true => non-duplicate lead, false => duplicate lead Map<Boolean, Lead[]> results = new Map<Boolean, Lead[]> { false => new ...


0

FlowDefinitionView has some basic information about Process Builders and Flows.


2

The only way I can think of to reproduce your error is to introduce a naming conflict. Here is a simple analogue: public class Foo { public String property = 'abcde'; } public class Bar { public static void doStuff() { Object foo = 42; system.debug(Foo.property); } } It seems like within your method you must have named some ...


0

You need to make your method static. I tried something like this and it works just fine. public class OpportunitiesHelper { public static void myMethod() { String a = 'a'; if (Opportunities.DIRECT_RECORD_TYPES.contains(a)) { System.debug('It contains'); } Opportunities is exactly as yours except that I don't extand the fflib_SObjectDomain ...


1

I think you should try to set up a singletone pattern for your helper class. You need to make sure that every instance of the helper class is independent. This will help you to reduce governor limits. You are passing all Rents records that are changing. I think you should use here a logic to pass only those Rents that have changes on the fields that have ...


2

Salesforce bug. We're fixing this in Spring '20 via the "Restrict Reflective Access to Non-Global Controller Constructors in Packages" critical update. As noted in the comments to @sfdxfox's answer, similar issues exist with Type.newInstance, which this critical update also resolves, as well as removing legacy versioned behavior with these tricks that was......


1

Try this: public class ContactWrapper { public Boolean isSelected {get; set;} public Contact c {get; set;} public ContactWrapper(Boolean isSelected, Contact c) { this.isSelected = isSelected; this.c = c; } Map<Id,ContactWrapper> contactWrappersById = new Map<Id,ContactWrapper>(); for (Contact c: [SELECT Id, Name, ... ...


2

Recursion guards are very tricky. Using a simple static Boolean is a bad practice: there are lots of reasons for your trigger to be fired more than once in a transaction, and using a runOnce-style Boolean will mean your trigger just silently does nothing in those cases. This often produces difficult to debug behavior. Instead, use static Booleans that are ...


1

Your callout is performed synchronously. That is, Apex blocks until a response is received. (Incidentally, this is why you have to make the callout in a @future method and not from a trigger). The @future method as a whole is run asynchronously, but that doesn't affect the synchronous nature of the callout made within it. There is no possibility that your ...


0

The solution is to create a trigger that references a class with the desired code in it. adding @future to the class: trigger: trigger createPOTasks on Purchase_Order__c (after insert) { bartsClass.test(); } and the class: public with sharing class bartsClass { @future (callout=true) public static void test() { Http h = new Http(); /...


1

Add a space after the keyword "on". trigger SAR_FORM on SAR_FORM__c (after update) { Probably also worth doing this trailhead.


0

Just closing the loop here.. I ended up using jQuery to detect unfriendly URLs and make them friendly on the page.


0

you can create a helper like this public class ContactTriggerHelper {public static Boolean runOnce = true; public static void onAfterUpdate(List<Contact> newacc){ for(Integer i=0;i<newacc.size();i++) { insert (new Account(Name='Test'+i)); runOnce = true; System.debug('Is ...


0

Interesting problem. Left to me, I would take a hard look at the whole real-time, one-way sync architecture for so many records. I am sure you've considered the queuable Apex limit and chaining jobs to make it all efficient. That can lead to the target system process time being a big variable when trying to process 100K records (~ 1+ transaction / second ...


3

Certain types of debug statements are "always" truncated (assuming they reach some arbitrary length), notably Map, List, and Set values that are debugged directly to the log. For example: System.debug([SELECT Name FROM Account LIMIT 50000]); Also, if you reach the maximum log size (20MB), then there will definitely be truncation. If you need to see the ...


1

Anytime you deploy or validate a change set, you can specify what tests you'd like to run. There's a quick read about it here: Since you're not deploying any code changes, the Default or Run local tests options should validate the changeset properly without having to run all the tests in your org.


1

Correct, you cannot catch this error in a trigger. This error occurs before any triggers are executed. This is true for all standard validations, such as DUPLICATE_VALUE, REQUIRED_FIELD_MISSING, etc.


0

If anyone else ran into this a way to solve it is by getting the default record type ID from the Profile. If you want the users to be able to choose then you would have to write a separate Visual force Page for that. For(Schema.RecordTypeInfo rti : dsr.getRecordTypeInfos()) { If(rti.isDefaultRecordTypeMapping()) { ...


0

Public static boolean isHoliday(Date checkDate) { BusinessHours bt = [SELECT Id,MondayStartDate FROM BusinessHours WHERE isDefault = true]; Datetime checkDatetime = Datetime.newInstance(checkDate.year(), checkDate.month(), checkDate.day(), bt.MondayStartDate.hour(), bt.MondayStartDate.minute(), bt.MondayStartDate.seconds()); ...


0

Instead of a trigger, can you do this on a scheduled basis? A design pattern for that would be having a batch class that runs on a predetermined schedule that would query the records for "integration" and perform the callout to your other org: global class YourBatchClassvimplements Database.Batchable<sObject>,Database.AllowCallouts { //... ...


-1

public static void DoExport() { ApexPages.PageReference rept = new ApexPages.PageReference('/00O0K00000AwUifUAF?csv=1&isdtp=p1'); List<Messaging.EmailFileAttachment> attnt = new list<Messaging.EmailFileAttachment>(); Messaging.EmailFileAttachment attnt1=new Messaging.EmailFileAttachment(); //attachment.setBody(Blob.valueof(...


1

There is an issue in the loop exit. In case if i equals arr.size() - 1, it will still not exit the loop, but rather try to access i+1 element of an arr array, and that would cause an exception. This is proper code public static List < Integer > getMovingSum(List < Integer > arr) { List < Integer > movingSumList = new List < ...


2

I recommend you maintain a map of OpportunityId to count of child records. Start with the aggregates, then increment by your context records. Please note from Triggers: Before triggers are used to update or validate record values before they’re saved to the database. Given that you are validating record values, a move to the after context would be ...


1

In a before trigger, the changes to the database have not been committed yet, so you can't query for the data. Accordingly, you wouldn't see the new rows being created yet. Change the trigger to an after insert trigger to see the correct values. Note that your trigger isn't bulkified. Nor, is it even necessary. Just create a normal Roll-Up Summary Field for ...


0

Remove the conditional rendering ($User.UIThemeDisplayed) from the outputPanel that will be reRendered and instead add it to a sub tag. Then your conditional rendering will behave accordingly and the actionFunction will begin to work again. <apex:outputPanel id="classicPanel" > <apex:someOtherTag rendered="{! $User.UIThemeDisplayed == 'Theme3'...


1

When you want to generate the JSON return value for an Apex REST call directly, rather than returning an Apex type for the system, you need to set that JSON body in the RestResponse object. The docs specify how return values are handled (under responseBody): The response is either the serialized form of the method return value or it's the value of the ...


Top 50 recent answers are included