• naresh shetty
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I have requirment to create task from some other process on lead object .. I have a logic implimented in after trigger on task to find the Who id of the taks and find if it related to Lead than increament the coutner in lead object. But some reason I am not getting Whoid in task after insert trigger .. in the debug log its shoing null .. 

{Id=00T0k00000308vcEAA, RecordTypeId=01228000000nbeAAAQ, WhoId=null, WhatId=null, WhoCount=0, WhatCount=0, Subject=call [610386513500]2017-08-17 11:23:13, 
Batch job failing in PROD with error REQUEST_RUNNING_TOO_LONG .. field which I am using in SOQL is not indexed .. that could be issue? 
Limitation:
Recently I came across the issue where customer community does not have option to disable the standard page layout view for community users.
 
Scenerio:
Like https://xy.force.com/portal/pagename?Id=18digitid - this will be correct url for customer community users.
 
Someone changing the url to valid salesforce url
https://xy.force.com/portal/18digitid  - this is going to standard customer community layout which has all the standard settings.
 
Issue:
Some customer does not want to allow the community users to view standard page layout. As said there are no standard options to disable the page layout for community users.
 
Hello developer heroes!

I'm working through the Apex modules on Trailhead and can't seem to get past this one: https://developer.salesforce.com/en/trailhead/force_com_programmatic_beginner/apex_triggers/apex_triggers_bulk.

Hopefully this doesn't read like a 'please complete the course for me' kinda post, but I have written a trigger that I believe meets the criteria but it isn't passing the check, so I wanted to seek the guidance of the experts.

The challenge is to do this:

Create an Apex trigger for Opportunity that adds a task to any opportunity set to 'Closed Won'.

To complete this challenge, you need to add a trigger for Opportunity. The trigger will add a task to any opportunity inserted or updated with the stage of 'Closed Won'. The task's subject must be 'Follow Up Test Task'.The Apex trigger must be called 'ClosedOpportunityTrigger'

- With 'ClosedOpportunityTrigger' active, if an opportunity is inserted or updated with a stage of 'Closed Won', it will have a task created with the subject 'Follow Up Test Task'.
- To associate the task with the opportunity, fill the 'WhatId' field with the opportunity ID.
- This challenge specifically tests 200 records in one operation.


And here is the trigger I have come up with, which compiles OK and stands up to a manual (though admittedly unbulkified) test:
trigger ClosedOpportunityTrigger on Opportunity (after insert, after update) {

    List<Task> taskList = new List<Task>();
    
    for (Opportunity opp : [SELECT Id, StageName FROM Opportunity WHERE StageName = 'Closed Won' AND Id IN :Trigger.new]){
                    
            taskList.add(new Task(Subject = 'Follow Up Test Task',
                                  WhatId = opp.Id));
       
    }

    if(taskList.size()>0){
        
        insert taskList;
        
    }
    
}
I have tried replacing the SOQL with a straightforward 'for (Opportunity opp : Trigger.new)' and having the taskList.add inside an IF that checks for Closed Won - no luck. I also thought about checking to see if the stage was being changed to Closed Won, rather than the trigger firing on every edit, but I don't think this is what the module is asking for.

Where do you think I'm going wrong?

Huge thanks in advance!