Hot answers tagged

11

The Task object has a WhatId field (label "Related To") that can be set to the ID of any type of object. This allows zero to many Tasks to be associated with an object, with those Tasks presented as a related list in the object detail page. This is the normal way to relate a Task to some other object: a field on an object that is a lookup to a Task is not ...


11

You don't get cross-object fields in the trigger context. You would need to query for them. However, you can get the SObjectType instead and spare yourself the query. if (T.WhatId != null && T.WhatId.getSObjectType() == Employee_Session__c.sObjectType) { // logic here }


11

The error is in your Status. In the trigger you've got: if (l.Status =='Open- Not Contacted') (note the n- N), and in your test class you create it as: ld.Status='Open -Not Contacted'; (note the n -N). That misplaces whitespace is probably the reason why that line is not getting covered Edit: Try to use constants for this kind of things. It will make ...


10

Assuming your formula was copied directly from salesforce.com, the problem has to do with "Smart Quotes." Salesforce formulas don't recognize “ and ” as actual quotation marks. Try using the following: IF( BEGINS(WhatId, "006"), "Opportunity", IF( BEGINS(WhatId, "001"), "Account", IF( BEGINS(WhoId, "00Q"), "Lead", IF( BEGINS(WhoId, "003"), "Contact","")))...


8

David, have you tried setting the SeeAllData modifier to true for your test class? I tried out your code, and it appears that in order for you to validate that the ActivityHistory table was populated, you need start your test class with this: @isTest(SeeAllData = true)


8

Activity is the base shape of Task and Event, custom fields on the activity object are inherited by Task and Event. You should be able to just do: for (Task t: Trigger.New){ // if they are related to a contact, add the contact id (whoID) and their values to a map if (t.WhatId != null && (t.Call_Disposition__c == 'Contact - Call'|...


8

The only way to @mention someone in apex is using the ConnectApi (AKA Chatter in apex) and not by just creating a FeedItem in apex. You'll need to refactor most everything in your code around the posting to Chatter. Here is a code sample of a text post with a mention borrowed from an example that Jeff Douglas has on his blog: // makes a simple chatter text ...


7

Edit your custom object and check the 'allow activities' checkbox. This should solve your problem.


7

For removing the actions in Lightning, Go to Setup->Object Manager then select the object. Go to page layouts and edit the Page layout currently assigned. Under "Salesforce Mobile and Lightning Experience Actions" you can keep the ones you need and remove the ones not needed (If the actions are not displayed, click on the "override the predefined actions"). ...


6

You'll have to do this through code I'm afraid. Each task is assigned to exactly one user, so multiple users means multiple tasks. The way I've handled this in the past is to have a trigger on the task sobject, and when a task is marked as complete, find all other tasks matching the criteria (same name, for example) and remove them. I used the remove as I ...


6

You're running into the Archived Activities limitation. Events older than 365 days and tasks closed more than 30 days don't appear in "normal" queries. This is a performance benefit. If you're using Apex Code, use the ALL ROWS SOQL modifier to query those records, and if you're using the Data Loader or another tool, use the QueryAll function (e.g. Export All ...


6

Yes, you need to use the TYPEOF operator. You can have multiple WHEN clauses in the SELECT, one for each valid type. Example: SELECT Id, Subject, TYPEOF Owner WHEN User THEN Owner.MyField__c END FROM Task Additional information can be at SOQL Polymorphism.


6

From what I understand, You don't need to create a task to insert an EmailMessage. Email message has relatedToId field which you can use to directly link it to any desired record. As relatedToId is polymorphic like ParentId for Attachments, you should be fine. Source: https://developer.salesforce.com/docs/atlas.en-us.212.0.api.meta/api/...


5

You need to set DMLOptions like this before inserting the task Task t = new Task(Subject='Follow-up'); Database.DMLOptions dmlo = new Database.DMLOptions(); dmlo.EmailHeader.triggerUserEmail = true; database.insert(t, dmlo);


5

That is not currently possible for email handlers. When you create an email service you set the context user and that cannot be changed at run-time. When testing, there is a System.runAs() method that lets you set the user running the code, but that is only available for unit testing. The best option might be to create a custom field and populate that as ...


5

If you have it the SOQL Polymorphism and Type OF feature enabled in your org, then you could use TYPEOF in your SQOL to try to get this info. Something like below SELECT TYPEOF Who WHEN Contact THEN Phone WHEN Lead THEN LeadSource ELSE Name END FROM Task If it is not enabled, then I think you are forced to use a second query as related ...


5

You should be able to query the object TaskStatus to pull the list of all status values, along with a field IsClosed to tell you which values would mark a task as closed. Your query would look something like this. SELECT MasterLabel, IsClosed FROM TaskStatus WHERE IsClosed = true You can then execute the query using the standard query endpoint (details ...


5

You can't relabel the Task.CallDisposition field. I attempted to outsmart the system and use Translation Workbench to provide a "translated" label in my own language but that didn't work either. I also tried to edit the metadata via Eclipse and received a denial error there too. It appears that your best option is to create a custom field with your desired ...


5

If you want a link in a text email template, you can use https://login.salesforce.com/{task.Id} (or https://test.salesforce.com/{task.Id} in a sandbox) - if the user is already logged in, this will go straight to the Task; otherwise, it will take them to the Task via the login page. It also has the benefit of avoiding a direct reference to the instance (e.g. ...


5

Override the Log a call button to take to a VF page, controller checks for record type via page action method and if should go to standard, redirects using the nooverride=1 parameter, otherwise stay on the vf page


5

You need to write a delete trigger. Validations should happen before delete. You can get the Id of the running user via UserInfo.getUserId(). You can compare the CreatedById to the running user Id. You can validate in an Apex Trigger using the SObject.addError method. I recommend implementing a handler pattern. I recommend putting the error message in a ...


5

If you look at LookedUpFromActivity object. There is no Type field, instead you can use ActivityType or ActivitySubtype field


5

You will need to SOQL Contact first then feed the Tasks List with those ContactIds to get the related Tasks. Contact SOQL Contact[] cons = [SELECT id from Contact ]; Now, feed these ContactIDs to get related Tasks Tasks Task[] conTasks = [SELECT id, subject FROM Task WHERE Whoid in: cons]; System.debug('tasks:' + conTasks);


5

You need to split out a separate query. As the error states, you can't use this join: Id NOT IN (Select WhatId from Task) One possible approach to splitting out the query: Set<Id> opportunityIdsWithTask = new Map<Id, AggregateResult>([ SELECT WhatId Id FROM Task WHERE WhatId IN :trigger.new GROUP BY WhatId ]).keySet(); Then just ...


5

What is wrong with this specific code, why is it not creating a new task on the donation? You didn't actually call the code that commits data to the database, as in: insert taskList; Which you should do outside of the for loop, before the end of your code. In the future, what tools are available to me in SF to diagnose why Apex code is not working? Are ...


5

Note: Some of the following is conclusions my team reached for which we could not find explicit documentation; Salesforce support eventually confirmed our findings, just this past week. The EmailMessage object does not have any explicit CRUD or Sharing Settings. There is also no EmailMessage__Share object, so Apex sharing is off the table. With no ...


5

Triggers are supposed to work that way. They do not pre-populate data on the screens but only update it during the transaction. Out of the box, you will not be able to pre-populate data. If you can create some lightning component, then you can utilize force:createRecord event here which lets you to open the standard screen for record creation with an option ...


5

Usually this problem happens when the FLS is not enabled for the user's profile. First thing to check in such cases is to create the record from Salesforce UI to verify if the field is visible.


4

SELECT Id, (SELECT Id FROM ActivityHistories ORDER BY ActivityDate DESC LIMIT 1), (SELECT Id FROM OpenActivities ORDER BY ActivityDate ASC LIMIT 1) FROM Account You could also tweak the query based on other parameters, but this should be a good start.


4

Using the IsRecurrence field you can know which is the main task that generated the recurrence. If the strategy applies to your business just clone those tasks with a different owner. Than delete all task which RecurrenceActivityId = taskYouAreClonning. And Last delete the task you just clonned.


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