• Rahul63
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
I need to fetch the list of parent records which are not having child records associated to parent
Parent Object : Building__c
Child Object : InstallationInstallation_Address__c

I have tried the query in workbench : Select Id,Name  from Building__c WHERE Id NOT IN (Select Building__r.Id from Installation_Address__c) 
But i couldn't able to execute the query due to below error,

MALFORMED_QUERY: 
Building__c WHERE Id NOT IN (Select Building__r.Id from Installation_Address__c)
^
ERROR at Row:1:Column:90
The inner select field 'Building__r.Id' cannot have more than one level of relationships

Can you please help to fix above query.
Thanks in advance.

//Rahul
We have 3 fields  Ex_Period_End_Date__c (DataType Date) and Contract_Notice_Exclusivity_months__c (DataType Number), Exclusivity_Date__c (Formula field).

Our requirment is Exclusivity_Date__c = Ex_Period_End_Date__c - Contract_Notice_Exclusivity_months__c

By using formula feild i wrote below code, it works for addition i.e, Ex_Period_End_Date__c + Contract_Notice_Exclusivity_months__c

if(AND( NOT( ISBLANK(Ex_Period_End_Date__c) ),NOT( ISBLANK(Contract_Notice_Exclusivity_months__c ) )),DATE ( 

/*YEAR*/ 
YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c - 1)/12), 

/*MONTH*/ 
CASE ( MOD ( MONTH ( Ex_Period_End_Date__c )+Contract_Notice_Exclusivity_months__c, 12 ),0,12,MOD ( MONTH ( Ex_Period_End_Date__c )+Contract_Notice_Exclusivity_months__c, 12 )), 

/*DAY*/ 
MIN ( DAY ( Ex_Period_End_Date__c ), 
CASE ( MOD ( MONTH ( Ex_Period_End_Date__c )+Contract_Notice_Exclusivity_months__c,12 ) ,9,30,4,30,6,30,11,30,2, 

/* return max days for February dependent on if end date is leap year */ IF ( MOD ( YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c)/12) , 400 ) = 0 || ( MOD ( YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c)/12) , 4 ) = 0 && MOD ( YEAR ( Ex_Period_End_Date__c ) + FLOOR ( (MONTH ( Ex_Period_End_Date__c ) + Contract_Notice_Exclusivity_months__c)/12) , 100 ) <> 0 

, 29,28) 

,31 ) ))-1, 

null)

The above snippet works for addition but our logic changed to substraction, can any one help out



Regards,
Rahul
public void beforeUpdate( ) {
    List<Opportunity> oppLst = Trigger.old;
List < Opportunity > newOptyList = Trigger.New;
    List < Quote > QuoteList = [SELECT Id, Name, Opportunity.name  FROM Quote where OpportunityID = : oppLst[0].Id];
    List < Opportunity_Building__c > buildingopportunityList = new List < Opportunity_Building__c > ([SELECT Opportunity__c,Id, Name FROM Opportunity_Building__c where Opportunity__c = : oppLst[0].Id]);
   for(Opportunity oppNew :newOptyList ) {
    for(opportunity oppOld: oppLst){
        if ((buildingopportunityList.size() == 0 )){ 
        if(oppOld.StageName == 'Prospecting' && oppNew.StageName == 'Cost analysis' ) {
            oppNew.StageName.addError(Label.Opp_Stage_CostAnalysis_Error_without_OppBldg);
           }
        
        }
        if ((QuoteList.size() == 0)){
             if(oppOld.StageName == 'Cost analysis' && oppNew.StageName == 'Offer negotiation'){
                oppNew.StageName.addError(Label.Opp_Stage_Offernegotiation_Error_without_Quote);
            }
        }   
I need to fetch the list of parent records which are not having child records associated to parent
Parent Object : Building__c
Child Object : InstallationInstallation_Address__c

I have tried the query in workbench : Select Id,Name  from Building__c WHERE Id NOT IN (Select Building__r.Id from Installation_Address__c) 
But i couldn't able to execute the query due to below error,

MALFORMED_QUERY: 
Building__c WHERE Id NOT IN (Select Building__r.Id from Installation_Address__c)
^
ERROR at Row:1:Column:90
The inner select field 'Building__r.Id' cannot have more than one level of relationships

Can you please help to fix above query.
Thanks in advance.

//Rahul
public void beforeUpdate( ) {
    List<Opportunity> oppLst = Trigger.old;
List < Opportunity > newOptyList = Trigger.New;
    List < Quote > QuoteList = [SELECT Id, Name, Opportunity.name  FROM Quote where OpportunityID = : oppLst[0].Id];
    List < Opportunity_Building__c > buildingopportunityList = new List < Opportunity_Building__c > ([SELECT Opportunity__c,Id, Name FROM Opportunity_Building__c where Opportunity__c = : oppLst[0].Id]);
   for(Opportunity oppNew :newOptyList ) {
    for(opportunity oppOld: oppLst){
        if ((buildingopportunityList.size() == 0 )){ 
        if(oppOld.StageName == 'Prospecting' && oppNew.StageName == 'Cost analysis' ) {
            oppNew.StageName.addError(Label.Opp_Stage_CostAnalysis_Error_without_OppBldg);
           }
        
        }
        if ((QuoteList.size() == 0)){
             if(oppOld.StageName == 'Cost analysis' && oppNew.StageName == 'Offer negotiation'){
                oppNew.StageName.addError(Label.Opp_Stage_Offernegotiation_Error_without_Quote);
            }
        }