Hot answers tagged

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

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_task.htm There is a field called status in task. Setting this to the string 'Completed' solves the issue. No need to write this isClosed flag. This flag gets checked once task status is closed.


10

You just need to Edit the task itself to see the Add Attachment button. It's only available in the task edit view.


10

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 ...


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","")))...


9

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 }


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 ...


6

You're correct, its just a Task completed in a particular way. (except for Email2Case which has a special EmailMessage object, which IIRC, isn't in the public API). The Task approach is what the Outlook integration and others (e.g. Maildrop) do.


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

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


6

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"). ...


5

You can indeed achieve this with an Apex Trigger, however there is also an out of the box or declarative in Force.com speak way to do this. The standard Workflow functionality under Setup > App Setup > Create is where to look for this... This is the basic setup to get an email as shown below...


5

Well seems like you are doing DML from either Constructor or Getter method. Please try to do the same from action attribute of the page by calling a method


5

Background Very interesting question, it seems like what you're doing should work just fine. After some further investigation it appears that the Tasks child relationship subquery only returns tasks directly related to accounts by Task.WhatId where as your direct query will return all tasks related to the account by Task.AccountId (which is a formula field ...


5

Are you working from Apex of via the UI? From Apex, have a read of Task - Recurring Tasks. If the IsRecurrence field is true on the current Task you can use the RecurrenceActivityId to get the ID of the main record that created the current recurrence. You can then modify this parent record. From the UI, first use the edit series link in the recurrence to ...


5

There is no such field in API available as of now. Also you will not be able to achieve this with the help of workflows since for the TASK object even in workflow the email alert option is not available. The probable approach according to me is to write down a trigger on the task object to send an email to the assigned user. refer to this link for ...


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

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 ...


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

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.


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

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

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 ...


4

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);


4

I'm hoping I'm wrong on this, but I don't believe the data loader provides support for this, and as far as I know none of the other data loading tools do either. If you're inserting records with APEX or via the API most of the standard notification emails don't get sent. Fortunately for those avenues you can use the DMLOptions config parameter, ...


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.


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.


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