You need to sign in to do that
Don't have an account?
sai krishna 267
hi can anybody clear the error?account opportunity not having parent child relship can anybody clear the errorr?
public class opportunityAfterInsertHelper {
public static void OpportunitiesSize(list<Opportunity> triggerNew, map<Id,Opportunity> triggerNewMap) {
set<Id> accountIds = new set<Id>();
list<Opportunity> acc_List = new list<Opportunity>();
String OpportunityNames;
for(Opportunity O: triggerNew) {
if(O.accountId <> null)
accountIds.add(O.accountId);
}
for(Account acc : [SELECT id,name,No_Of_Opportunities__c,opp_Names__c,(SELECT id,stagename FROM Opportunity ORDER BY
CreatedDate ASC) FROM Account WHERE Id IN : accountIds]) {
contactNames='';
if(acc.Opportunities.size()>0) {
acc.No_Of_Opportunities__c = acc.Opportunities.size();
for(Opportunity c : acc.Opportunities) {
OpportunityNames+=O.stagename+';';
}
acc.Opportunities_Names__c=OpportunityNames.subString(0,OpportunityNames.length()-1);
}
acc_List.add(acc);
}
if(acc_List.size()>0)
update acc_List;
}
}
error is
Error: Compile Error:
opp_Names__c,(SELECT id,stagename__r FROM Opportunity ORDER BY
^
ERROR at Row:1:Column:81
Didn't understand relationship 'Opportunity' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 14 column 27
can anybody clear the error? any alternatecode for this logic?
public static void OpportunitiesSize(list<Opportunity> triggerNew, map<Id,Opportunity> triggerNewMap) {
set<Id> accountIds = new set<Id>();
list<Opportunity> acc_List = new list<Opportunity>();
String OpportunityNames;
for(Opportunity O: triggerNew) {
if(O.accountId <> null)
accountIds.add(O.accountId);
}
for(Account acc : [SELECT id,name,No_Of_Opportunities__c,opp_Names__c,(SELECT id,stagename FROM Opportunity ORDER BY
CreatedDate ASC) FROM Account WHERE Id IN : accountIds]) {
contactNames='';
if(acc.Opportunities.size()>0) {
acc.No_Of_Opportunities__c = acc.Opportunities.size();
for(Opportunity c : acc.Opportunities) {
OpportunityNames+=O.stagename+';';
}
acc.Opportunities_Names__c=OpportunityNames.subString(0,OpportunityNames.length()-1);
}
acc_List.add(acc);
}
if(acc_List.size()>0)
update acc_List;
}
}
error is
Error: Compile Error:
opp_Names__c,(SELECT id,stagename__r FROM Opportunity ORDER BY
^
ERROR at Row:1:Column:81
Didn't understand relationship 'Opportunity' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 14 column 27
can anybody clear the error? any alternatecode for this logic?
Please change your query as below: Hope This will work. Please let me know if helped by marking best answer.
Regards,
Ramakant