You need to sign in to do that
Don't have an account?
dcgb2332
Auto Populate Job Number (custom field) in Opportunity Tasks (pulling from Opportunity_Number__c)
I've tried work flow rules, process builder and apex triggers and keep running into a wall. Does anyone have a best practice for this? I simply need th Opportunity Record ID Number populated into my custom Job Number field in the Task in Lightning (shows up in Classic but lightning for some reason??)
Apex trigger or formula suggestions would be greatly appreciated.
Thanks!
Apex trigger or formula suggestions would be greatly appreciated.
Thanks!
I have written the trigger on task object to update job number field in task object from the opportunity number field from opportunity object.
This is working for me. Please check it and let me know if it helps for you.
Note: If it helps for you, Please mark it as the best answer.
Best Regards,
Navin
Are you refering any images in your code? Could you please explain the requirement little more? As per your requirement, the above trigger wil help you to update the task job number with opportunity number. Is there any other jobs that you are simultaneously doing?
Please put debug on trigger and check where the exception occurs in trigger. if trigger successfully runs, then there will be no error in the trigger or the code i provided.
This error is from some othe parts of your implementation apart from trigger implementation.
Regards,
Navin S
I'm at a loss, here are the errors I'm receiving:
Line 15 - Method does not exist or incorreect signature: void put(Id, String) from the type Map
Line 18 - Illegal assignment from Decimal to String
Thank you for your help, I really appreciate it.
trigger TaskTrigger on Task (before insert, after insert) {
List<Id> taskIds = new List<Id>();
List<Id> oppIds = new List<Id>();
Map<Id,Id> oppMap = new Map<Id,Id>();
if(Trigger.isAfter){
if(Trigger.isInsert){
for(Task taskObj : Trigger.New){
taskIds.add(taskObj.Id);
}
List<Task> tskObjLst = [SELECT Id,WhatId FROM Task where Id in: taskIds ];
List<Opportunity> oppLst = [SELECT Id,Opportunity_Number__c FROM Opportunity where Id in: oppIds ];
for(Opportunity oppObj : oppLst){
oppMap.put(oppObj.Id,oppObj.Opportunity_Number__c);
}
for(Task taskObj : tskObjLst){
taskObj.Job_Number__c = oppMap.get(taskObj.WhatId);
}
update tskObjLst;
}
}
}
in first for loop(Task loop using Trigger.New), you have missed the following line
oppIds.add(taskObj.WhatId); --> See my code that i shared line number 10
Then, after querying the data, please put system.debug whther any records are returning via SOQL list.
finally, put one system.debug inside the last for loop, that values from map is correclty getting
System.debug(oppMap.get(taskObj.WhatId));\
If the data comes correclty, sure the value gets updated.
In my personal org, it is working.
Regards,
Navin
I applied the fix and here's the error I receive once I perform the action of a new task:
TaskTrigger: execution of AfterInsert caused by: System.StringException: Invalid id: 102722 External entry point
Thanks
could you share your code. not exact code if it is confidential. just rename object name and column names. let me check
Regards,
Navin
1. When you need to perform this operation?
2. before or after? either insert or update?
3.Did you remove the what type of list and map from the code you provoided right? EX: list should be declared like the following as well as map
List<DataType> oppIds = new List<DataType>();
Map<Key,Value> oppMap = new Map<Key,Value>();
4. Invalid type argument count for Map : it is expecting key value pair. But you have given only one argument instead of two.
5.Variable does not exist: oppMap: visibility is not at the line number
2) So it would need to be at insert (after I'm assuming?)
3) I don't recall removing the list.
4) I gave the argument you included in the code
5) See my above
I just copied and pasted your code and made a few amendments to the object names, nothing else.
I can able to execute without error in my org with the follwoing code.
In system.debug i can able to get the values.
Please execute the above code and make sure there is no error. then create the task on the opportunity. check the values are coming into the list via system.debug. if the values are coming in list, it will work.
Regards,
Navin
Thanks for your help.