New answers tagged

0

Ok then, this calls for a change to the plan of attack. The important detail here is that there should only be one role history that we pull data from (as opposed to aggregating the data from all role histories). The good news is that this ends up making the code a little simpler. Subqueries (i.e. parent-child queries, or semi/anti-joins) can also have ...


0

Based on your example, it should show role1; role2, but is it showing role1; role1; role2 ? The reason for that is when you are querying the parentReps you are fetching all the child objects and iterating over the entire list, while what you wanted is to filter out the Active ones (the one that doesn't have end date stamped on it). So, add the filter ...


0

Write SOQL outside from for Loop means you trigger are not bulky, not handle large records due to salesforce governor limits, Bulk Trigger. for Between you have to compare start <= :startDate and end >= :endDate Use <= , >= operators to get records between start date and end date. SELECT id FROM hr__c WHERE status__c date_start__c >=: startDate ...


1

You can us RecordTypeInfo class to determine which records types are available to a user. Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe(); List<Schema.RecordTypeInfo> RT = R.getRecordTypeInfos(); for (Schema.RecordTypeInfo RTI : RT) { if (RTI.isAvailable()){ // they have access to this record type } }


0

Check this Article: This error may show up when an Opportunity record you own is transferred to another User. This may appear even if the User that is being specified as the new owner has read access to Accounts, Contacts or Opportunities. You can try: Depending on the Profile, or License used, you might check whether you can provide more access, ...


0

It does not really makes logical sense to assign owner when user has some level of access. You would assign the record to new owner in order to give access to new user. Also if you want to give access (read/edit) to additional users, you would use roles/permission sets. Note: Even if new user does not has access to record, assigning that user as owner will ...


0

i was with @gs650x while we are working on above. And yes this is related to Order Of execution.What we are doing here is we have created a field in contact object named 'NumberField' of datatype 'number' as shown below What logic we are using here to test order of Execution is we have created 1) A trigger to add Integer 1 to Number field 2) A Workflow ...


0

Seems like you're on the right track to me. A few things to note: When you're querying (and later accessing) data on a related record, you use __r at the end instead of __c Specifically for parent-child subqueries, you use the child relationship name. This can be found by a few different methods (apex, looking at the relationship field on the child object, ...


1

The second piece of your question is an example of a (usually) non-pathological recursion guard, where you suppress recursive trigger operation only around a single DML operation. You'd usually have it like this: if (!beingupdated) { beingupdated = true; update contactRecord; beingupdated = false; } This ensures that your ...


0

As it turns out, there was code that abruptly ended the execution of the trigger because of a missing Custom Setting in the test context. After removing this code, the trigger executed as expected.


0

Welcome to Salesforce StackExchange. the test method creates an Event and inserts it into the database temporarily. So for retrieving the other value you should write the SOQL on Event to get the value of other Feild. Please Read Apex Test Class Documentation. So changes in your code need to do. System.assertEquals(1,[Select Id, DurationInHours__c From ...


0

I suggest instead of debugging the code you rewrite it: not only do you need to get the code to work now, but others will have to maintain it in the future. Something like the following would be clearer (but note that I may not have captured the details correctly). That uses these approaches: Include the specific types in the method signature Only declare ...


3

You're error is because accWithCaseSalesDiv.get(i.Id) returns null and you are attempting to dereference it .Id The . is the dereference operator. Attempt to dereference a null object happens when the object to the left hand side of the dereference operator is null. Instead of: If( accWithCaseSalesDiv.get(i.Id).id != null && ...


0

Background CaseArticle is a junction object between Case and KnowledgeArticle and is inserted by SFDC when you attach a Knowledge Article to a Case in Service Console There is no trigger support on CaseArticle so an after insert event can not be used to signal processing on the parent Case. However, When an article is attached, there is a FeedItem created ...


-2

trigger Task2Income on Contact (after update,after insert,after delete,after undelete) { List<Contact> ContactsLst; set<String> vAccId = new set<String>(); if(!trigger.isdelete) ContactsLst = trigger.new; else ContactsLst = trigger.old; for(Contact vContact : ContactsLst){ if(vContact.AccountId != null){ ...


0

As per your trigger code, Updateopptyowner method is called in before insert event. Your code should be look like this. Your class code is also not upto the salesforce best practice. You should not do update on the same record from trigger. Your logic can be handled in before update method. Trigger trigger Updateoppty on Opportunity(before insert, before ...


0

To check if a field has changed in a trigger, you must use the Trigger.old list to compare with the Trigger.New. Pass it to the updateopptyowner as a param and then, do something like: if(newOpportunity.Owner__c != oldOpportunity.Owner__c) // logic when Owner__c field has changed For more information check the Trigger Context Variables in the Apex ...


0

Welcome to SF.SE Leo. From your description, it sounds like you're perhaps attaching the knowledge article to the Case Record from the Knowledge Component. If not, you're likely doing it from someplace within a Knowledge Search where you still have the Case Record in context. By adding the knowledge article as an attachment to the Case record, it's clear you'...


0

Following Changes i did in your code Create a separate Set<ID> of ids to store cObject.Med_Question_Section__c Write SOQL to get the records using a set of Ids. Create a map to store Ids, with record Map<Id,Med_Question_Section__c> mapOfIdToRecord = new Map<Id,Med_Question_Section__c>(); At the last for loop you will get the record from ...


2

If Secondary_Contact__c is a lookup to Contact, you're then querying the wrong object. This is how I'd do it. trigger populateContactEmail on Case (before insert , before update){ Set<Id> setConIds = new Set<Id>(); for (Case obj : trigger.new) { if (obj.Secondary_Contact__c != null) { setConIds.add(obj....


3

I suspect the issue is that the user experiencing this issue has no role assigned. That would cause System.userInfo.getUserRoleId(); to return null, and in turn cause the query on UserRole to return no rows and give you that particular error. Like I mentioned on your other question, assigning the result of a query to a single object instead of a List is a ...


1

Following are the things you could do to solve your problem. The problem with your query is that you are querying on User object and filtering the UserId by RoleId, hence it won't return any records. Also, you don't have to query on User in for loop as current user will always be same. And to get the values separated by ; i.e. as a value in multiselect ...


2

A couple of items to note here: You're storing the result of your query in usrRole, but are then trying to use userRole in the debug The above might just be a typo, but beyond that, a query will return a list of objects. You'd need to index into the list to get a specific object instance before you can use dot-notation to get at an individual field You're ...


1

I don't quite get your use case, but in order to get the Role Name you are trying to retrieve, you should replace this: List<User> usrRole = [select id, name, userRole.name from user where id =: roleId]; With this: List<UserRole> usrRole = [SELECT Name, DeveloperName FROM UserRole WHERE id =: roleId];


0

Yep, closing the parent case when any child case is closed is certainly what your current code is set up to do. Probably the biggest conceptual roadblock that you have here is that you're only querying for child cases that are specifically Status = closed. If there are any child cases that aren't closed, that query won't find them. For simple binary ...


0

public static void limitFileForSofonFastFlow(List<Attachment> attachmentList){ set<id> quotid = new set<id>(); for(Attachment at:attachmentList){ quotid.add(at.parentId); } List<customobject__c> qt = [select id from customobject__c where id=:quotid and Recordtype.Name='channel']; ...


0

I don't see any records being updated in the code mentioned by you. You are updating accupdate list which does not have any elements in it i.e. you are not adding any record in that list and you are trying to update it. Hence nothing is getting updated. Also, as far as bulkification is concerned, I don't see any problems with your code. Only thing to take ...


-1

Step 1.I create a Map of accountid to list of opportunity to store the data. 2.I loop through the map and add to list for update the account description public class AccountHandler { public static boolean flag=true; public static void updateAcc(list<account> accList) { set<id>ids=new set<id>(); for (account acc:accList) { ...


0

In case anyone ends up here, and hard as it is to believe, in Winter 20, apex triggers are now supported on OpportunityContactRole, along with custom fields and layouts Opportunity contact role customization options give you the flexibility to track and attribute revenue to roles, titles, and individuals. With custom fields and page layouts, ...


0

Fields need to be assigned, whichever trigger you use, you can write class like this or also you can look there: https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_triggers OR https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_code_coverage_intro.htm FOR EXAMPLE: @isTest public class ...


0

Writing a trigger on after insert to clone an opportunity, update the parent opportunity field (self relationship) and also update the Stage accordingly then insert. trigger OpportunityTrigger on Opportunity (after insert) { List<Opportunity> opportunitiesToBeAdded=new List<Opportunity>(); for(Opportunity opportunity:Trigger.New){ //...


1

Before triggers, when executed in the context of the user interface will be all-or-nothing. If the trigger fails a validation rule or other SFDC-imposed requirement, the trigger will fail and all updates rolled back. The user will see an error at the top of the screen that identifies the failure If you have multiple triggers on the same object and one ...


0

your trigger can flag a record as having an error try{ if(Opp.Owner__c!=null && Opp.Owner__c != trigger.oldMap.get(Opp.Id).Owner__c){ Opp.ownerid = opp.Owner__c; } } catch(exception ex) {opp.addError('Your custom error message'); } this can show a custom error message


5

(Please, excuse the indentation in the code snippets) Because you are passing the Lists of sObjects to the handler, they are passed by reference and the only thing you need to do to update them is modify the fields you are interested in (just like you are currently doing using the equal sign for assignment). The Salesforce execution framework and the ...


0

Firstly, if(Trigger.isUpdate) should be the outermost tag (to only check once) Secondly, NEVER HARDCODE IDs !!!! Create a custom label and reference it in your code. Having debug logs on or off will not alter the execution logic, so something must be off with your methods ExceptionManager.saveMessage or Service_Docusign.generateOpportunityDocusignPDF The ...


2

It's not just after triggers that can be a problem, any trigger can have problems with recursion, though some are more likely than others to experience that problem. Update triggers are the most likely to have recursion issues (especially after update), but Insert triggers can pretty easily be set up to recurse infinitely too. I suppose that even Delete ...


0

There are some limitations to what you can do to the record that is triggering and after trigger, so you won't get in an endless loop. Because from a logical perspective the trigger would be triggered, insert something, trigger again based on its own action, insert something, trigger again... To make it harder to get in an endless loop Salesforce there are ...


0

You are trying to update Lead newLead = new Lead(), you didn't give it an ID so it doesn't know who it needs to update. You would have to do something like newLead = new Lead(Id=l.id) inside the loop; But in general, i think you need to bulkify your code. Currently you will only do the update on one lead, and it will be the last lead in the trigger.


0

To store objects you need to insert them, and to relate one object to another, you need to set the Id value of the "another" object in the foreign key field of the "one" object. The "another" must have been inserted first so that it has an Id value allocated. This also needs to be done "in bulk" in triggers. Work through this Data Modeling module, and also ...


0

Hi i have similar solution implemented in my project. You have to check for the Agent Work Status. If status is agent works status is Opened then it means agent agent accepted the work item in your example it will be case record. And you should handle this scenario in After update event. Below is the sample code and this code should be executed in after ...


0

Not sure why you're not getting a single line of coverage, but you have a bug after insert opp; in your test method. You are doing: insert opp; opplistid.add(acc.id); Looks like you want to actually be adding the newly created Opportunity Id rather than the Account Id. Use this instead: opplistid.add(opp.id); Try updating and see if that helps


0

If you are trying to update them one by one you will run into the Salesforce governor limit for DML operations which is limited to 150. If you use collections you can update them more efficiently and the limits might be sufficient. It's always helpful to include an example in your post if you need more detailed advice.


1

I suspect something like the following is occurring. Firstly, the Database.SaveResult isSuccess() method indicates that the event was successfully published. But then you attempt to iterate the Database.Error records via sr.getErrors(). That is resulting in the VARIABLE_ASSIGNMENT error, as there aren't any errors to iterate. I'm assuming this is resulting ...


0

Triggers are basically metadata, that means in order to active a trigger you have to do a deployment. Various app exchange packages do this, one notable example being DRLS, they use Apex metadata API wrapper to dynamically deploy code on its own org.


1

Apex trigger is the code which is directly attached to database and can be invoked ONLY by Apex DML Operations. You may use Apex class as handler/helper classes which when invoked from trigger will have trigger context variables but when you try to invoke same handler/helper classes from outside like lightning component/process builder, you will not have any ...


2

You are getting that exception because the value of AreaCount__c for the ar instance that you are using is null. Below line i.e. ar.AreaCount__c += mapCount.get(ar.id); // which is equal to //ar.AreaCount__c = ar.AreaCount__c + mapCount.get(ar.id); As ar.AreaCount__c is null and as you are referencing a null object in your code, it will give you ...


1

Multipickist values are stored in a string that separates each value by a semicolon. So if you have Apple Orange and Banana all selected as values for a Contact.My_Multi_Picklist__c, they can be saved in the Salesforce field as follows: Contact.My_Multi_Picklist__c = 'Apple;Orange;Banana'; If you're getting an array of strings and want to convert to a ...


1

You need to use SUBSTITUTE in a nested fashion like this: SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE(Name , "1", "One" )...


0

first you can use the 'in' statement as a best practice . Never do a query inside a for loop statement can you try doing a list of objects then you add em all? like this ; public class BudgetTriggerHandler { public static void RefreshTransactions(List<Budget__c> Budget){ for(Budget__c b : Budget){ datetime selectedDate = b....


1

There are at least three potential solutions. You could choose to use Process Builder, since it would run after your after-update trigger. For that matter, you could copy the text values to the children using Process Builder as well, which would avoid the need for any code. Aside from that, there is no hard rule preventing you from updating children in a ...


Top 50 recent answers are included