You need to sign in to do that
Don't have an account?
SObject row was retrieved via SOQL without querying the requested field: Case.ParentId
Hello All,
I need to update casecooment under case object . but while trying to update , it is throwing error meesage like "SObject row was retrieved via SOQL without querying the requested field: Case.ParentId"
Code snippet is below :
global class Case_Update implements Database.Batchable<sObject>, database.stateful
{
List<Case> childrenToUpdate = new List<Case>();
Set<Id> parentIds = new Set<Id>();
List<Case> parentCase = [SELECT id, Master_Ticket__c, resolution_notes__c,Status,Resolution_Type__c,Do_Not_Send_Email__c,Description, (Select id ,parentId, CommentBody From Case.CaseComments) FROM case WHERE is_Master_ticket__c= TRUE AND Master_Ticket__c =''];
global Database.QueryLocator start(Database.BatchableContext BC) {
for(Case p:parentCase ){
parentIds.add(p.id);
}
return Database.getQueryLocator('SELECT Id,Master_Ticket__r.resolution_notes__c,parentId,Master_Ticket__r.Resolution_Type__c,Master_Ticket__r.Status,Master_Ticket__r.Do_Not_Send_Email__c FROM Case WHERE master_ticket__c IN :parentIds');
}
global void Execute (Database.BatchableContext BC,List<case> scope) {
List<casecomment> lcm = new List<casecomment>();
if(parentIds.size() > 0) {
for(Case ch : scope) {
casecomment cm = new casecomment();
casecomment cmp = new casecomment();
cm.id = ch.Master_Ticket__r.parentid;
//cm.parentid = ch.parentid;
//cm.commentbody=ch.Master_Ticket__r.commentbody;
lcm.add(cmp);
lcm.add(cm);
system.debug('******************************'+cm);
ch.resolution_notes__c = ch.Master_Ticket__r.resolution_notes__c;
ch.Resolution_Type__c=ch.Master_Ticket__r.Resolution_Type__c;
ch.Do_Not_Send_Email__c= ch.Master_Ticket__r.Do_Not_Send_Email__c;
ch.Status=ch.Master_Ticket__r.Status;
childrenToUpdate.add(ch);
System.debug('childrecord ' + childrenToUpdate);
}
Update childrenToUpdate;
update lcm;
system.debug('============================================'+lcm);
}
}
global void finish(Database.BatchableContext BC){
}
}
Regards,
Raj
I need to update casecooment under case object . but while trying to update , it is throwing error meesage like "SObject row was retrieved via SOQL without querying the requested field: Case.ParentId"
Code snippet is below :
global class Case_Update implements Database.Batchable<sObject>, database.stateful
{
List<Case> childrenToUpdate = new List<Case>();
Set<Id> parentIds = new Set<Id>();
List<Case> parentCase = [SELECT id, Master_Ticket__c, resolution_notes__c,Status,Resolution_Type__c,Do_Not_Send_Email__c,Description, (Select id ,parentId, CommentBody From Case.CaseComments) FROM case WHERE is_Master_ticket__c= TRUE AND Master_Ticket__c =''];
global Database.QueryLocator start(Database.BatchableContext BC) {
for(Case p:parentCase ){
parentIds.add(p.id);
}
return Database.getQueryLocator('SELECT Id,Master_Ticket__r.resolution_notes__c,parentId,Master_Ticket__r.Resolution_Type__c,Master_Ticket__r.Status,Master_Ticket__r.Do_Not_Send_Email__c FROM Case WHERE master_ticket__c IN :parentIds');
}
global void Execute (Database.BatchableContext BC,List<case> scope) {
List<casecomment> lcm = new List<casecomment>();
if(parentIds.size() > 0) {
for(Case ch : scope) {
casecomment cm = new casecomment();
casecomment cmp = new casecomment();
cm.id = ch.Master_Ticket__r.parentid;
//cm.parentid = ch.parentid;
//cm.commentbody=ch.Master_Ticket__r.commentbody;
lcm.add(cmp);
lcm.add(cm);
system.debug('******************************'+cm);
ch.resolution_notes__c = ch.Master_Ticket__r.resolution_notes__c;
ch.Resolution_Type__c=ch.Master_Ticket__r.Resolution_Type__c;
ch.Do_Not_Send_Email__c= ch.Master_Ticket__r.Do_Not_Send_Email__c;
ch.Status=ch.Master_Ticket__r.Status;
childrenToUpdate.add(ch);
System.debug('childrecord ' + childrenToUpdate);
}
Update childrenToUpdate;
update lcm;
system.debug('============================================'+lcm);
}
}
global void finish(Database.BatchableContext BC){
}
}
Regards,
Raj
can you please help me how to map comment body in update ?
Regards,
Raja.
Make sure include the same field in query line below
Or remove the below code
Let us know if this will help you
Thanks for your reply . But when i mentioned field in query it is saving fine . But i was unable to map comment body . below is the error .
"Invalid field commentbody for SObject Case at line 23 column 32". Here i want to update case comments in below child record .
For example : case A having is parent case and Child 1,2,3 are child. When case is closed , i need to create case comments .
when i tried to map casecommentsbody to the field it is showing invalid .
I am seeking help here how to map casecommentbody with casecommet?
Regards,
Raja.