You need to sign in to do that
Don't have an account?
Srini
Need SOQL Help
Hi Team,
We are facing the error like Unknown parsing query, while we are trying the query mentioned below,can any one please help us where we made the mistakes.
Select id,name,Opportunity.RecordType.name,(SELECT CreatedById,Id,LastModifiedDate,OwnerId, WhatId FROM Task),(SELECT OpportunityId FROM OpportunityTeamMember where UserId =' '),
(SELECT Id,IsActive,UseRole.Name FROM User Where IsActive=true and UserRoleId ='' And UseRole.Name like 'Assign-A%')) From Opportunity
Thanks
We are facing the error like Unknown parsing query, while we are trying the query mentioned below,can any one please help us where we made the mistakes.
Select id,name,Opportunity.RecordType.name,(SELECT CreatedById,Id,LastModifiedDate,OwnerId, WhatId FROM Task),(SELECT OpportunityId FROM OpportunityTeamMember where UserId =' '),
(SELECT Id,IsActive,UseRole.Name FROM User Where IsActive=true and UserRoleId ='' And UseRole.Name like 'Assign-A%')) From Opportunity
Thanks
There are several issues with the query:
- There is 2 times UseRole.Name used. This should be UserRole.Name
- There is an extra ")"-character after 'Assign-A%'. Please remove this.
- You cannot query the RecordType.Name directly. You will have to use a separate query for the RecordType record and later match it with the opportunity record you retrieve from the query. (see example code below)
- You will need to use the relationship names to query the related records: "From Tasks" in stead of "From Task" and "From OpportunityTeamMembers" in stead of "OpportunityTeamMember".
- You cannot query related users to an opportunity, since the User object is not directly linked to the Opportunity object. You will need to create a separate query for this.
So your code will need to look something like this: Hope this helps!Best regards,
Martijn Schwärzer
Sorry for the late reply...Thanks for your help.
We have one more issue .who ever having the Team roles "Assign" we need to remove them in the opportunity along with particular Recordtypes.
Record types are : 1.Sale,Desing,Flow.
Can you please help us that would be great.
Please check my below Apex code: and where we need to include role level.
Global class BatchApex_UpdateOpp implements Database.Batchable<Sobject>{
String TeamRole = 'Assign';
Public String query = 'SELECT id,name,Opportunity.RecordType.name,(SELECT ID,Subject,LastModifiedDate FROM ActivityHistories order by LastModifiedDate DESC LIMIT 1 ),(SELECT id,LastModifiedDate,TeamMemberRole FROM OpportunityTeamMembers WHERE TeamMemberRole = \'TeamRole\') From Opportunity ';
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator(query);
}
//Execute Method
global void execute(Database.BatchableContext BC,List<Opportunity> scope){
List<OpenActivity> alist=New List<OpenActivity>();
//set<id> aset=new set<id>();
// set<id> oset=new set<id>();
List<OpportunityTeamMember> plist=New List<OpportunityTeamMember>();
for(Opportunity ot : scope){
system.debug('@@@@@@OpportunityTeamMembers'+ot.getSObjects('OpportunityTeamMembers'));
for(ActivityHistory OPA : ot.getSObjects('ActivityHistories')){
DateTime dT = OPA.LastModifiedDate;
//DateTime dT = ot.ActivityDate.LastModifiedDate;
Date myDate = date.newinstance(dT.year(),dT.month(),dT.day());
Integer numberDaysDue = (myDate.daysBetween(system.today()));
system.debug('@@@@@@Subject'+OPA.Subject);
system.debug('@@@@@@numberDaysDue'+numberDaysDue);
if(OPA.Subject !=null){
if(numberDaysDue > Integer.valueOf(System.Label.OppTeamDays)){
for(OpportunityTeamMember optm: ot.getSObjects('OpportunityTeamMembers')){
if(optm.TeamMemberRole=='Assign'){
system.debug('@@@@@@TeamMemberRole'+optm.TeamMemberRole);
plist.add(optm);
system.debug('@@@@@@OpportunityTeamMember '+plist);
}
}
}
}else{
for(OpportunityTeamMember optm: ot.getSObjects('OpportunityTeamMembers')){
if(optm.TeamMemberRole=='Assign'){
system.debug('@@@@@@TeamMemberRole'+optm.TeamMemberRole);
plist.add(optm);
system.debug('@@@@@@OpportunityTeamMember '+plist);
}
}
}
}
}
if(Plist.size()>0){
delete plist;
}
}
//Finish Method
global void finish(Database.BatchableContext BC){
}
}
Thanks in Advance