You need to sign in to do that
Don't have an account?
Pritam Shekhawat
How to autopopulate whoid and whatid for task
Hello,
I am using visualforce page for task and log a call.And i set some default value for subject , due date and assigned to. But am not able to autopopulate whoid and whatid for lead and opportunity. Without this it is working fine for every object except opportunity. Whenever i click on new task from opportunity it will give below error.Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Name ID: id value of incorrect type: 0011100000sysNbAAI".Below is my code am something missing here??
I am using visualforce page for task and log a call.And i set some default value for subject , due date and assigned to. But am not able to autopopulate whoid and whatid for lead and opportunity. Without this it is working fine for every object except opportunity. Whenever i click on new task from opportunity it will give below error.Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Name ID: id value of incorrect type: 0011100000sysNbAAI".Below is my code am something missing here??
public with sharing class LogACallControllerExtension { public Task task; ApexPages.Standardcontroller controller; public LogACallControllerExtension(ApexPages.StandardController controller) { User u = [select firstname,Id ,LastName from user where id=:userinfo.getuserid()]; this.task = (Task)controller.getRecord(); this.task.status = 'Completed'; this.task.Subject ='Call'; this.task.OwnerId =u.Id; this.task.ActivityDate= date.today(); this.controller = controller; } }Click here to return to the previous page.
Now it working fine. It is right apporach?? I am using custom button for New Task here only for opportunity and for other standard button is working fine.
All Answers
I think you have created a custom button ,That button if you have over rid ethe Vf page and make available in the related list .Assume the button is there in Account related list .Then you need to get the account id in the constructor of the class as below .
Id parentId =ApexPages.currentPage.getParameters.get('id'); will give you the account id .
Task/event is related to Contact/Lead as who id apart from that all related with whatid .
You can check if the parentid startswith 003/00Q then assign the id to WhoId else assign to WhatId.
Let m eknow if it helps .
Thanks
Manoj
check if the parentid startswith 003/00Q then assign the id to WhoId else assign to WhatId.
If am using this then it works fine for account and opportunity but it will not autopopulated whoid for lead/contact.How to do this?
Do one thing modify the code like below .
And check the debug log by clicking the button under Lead and Contact .
As per my knowledge is concern the relationship of whoId is not there with Account and Opportunity .
You can cehck below link .
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_activities.htm
Don't forget to create record under opportunity ,An dcontact and Lead .
And assign task.WhatId=OpportunityId not Task.WhoId .
Let me know if it helps .
Thanks
Manoj
Now it working fine. It is right apporach?? I am using custom button for New Task here only for opportunity and for other standard button is working fine.