+ Start a Discussion
SFDC-DMGSFDC-DMG 

Trigger to create new Opp from Custom Object - need Opp ID in Custom Object

Hello,

 

We are implementing Zuora in our Salesforce, and I am trying to get some fields on the related Quote object to roll up to the Opportunity level. I'm running into some challenges doing so, and was hoping that someone would be able to help?

 

There are probably other errors that will pop up once I fix this one, but I'm currently running into the following error:

 

"Didn't understand relationship 'zqu__Quote__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' aftger the customer relationship name. Please reference your WSDL or the describe call for the appropraite names"

 

Here is the code as it currently stands, and if someone has insight on edits or knows how to make this work, that would be fantastic.

 

Thanks!

 

trigger OppUpdatefromQuoteObject on zqu__Quote__c (after delete, after insert, after undelete,
after update) {

// // This updates the opportunity with the term and amount information from the quote object

// If related to an Opportunity, query to find out the Opportunity number

public set<Id> OpportunityIDs = new Set<Id>();
public list<Opportunity> OpportunitiesToUpdate = new List<Opportunity>();


// Build the list of Opps to update
if(Trigger.isInsert || Trigger.isUnDelete || Trigger.isUpdate){
    for(zqu__Quote__c q: Trigger.new){
    if(q.zqu__Opportunity__c!=null && string.valueOf(q.zqu__Opportunity__c).startsWith('006'))
    OpportunityIDs.add(q.zqu__Opportunity__r.id );

    }
}

if(Trigger.isDelete || Trigger.isUpdate){
    for(zqu__Quote__c q: Trigger.old){
    if(q.zqu__Opportunity__c!=null && string.valueOf(q.zqu__Opportunity__c).startsWith('006'))
    OpportunityIDs.add(q.zqu__Opportunity__r.id );
    }
}


// Update the Opportunities

if(OpportunityIDs.size()>0){
for(Opportunity o: [Select o.Id, o.amount, o.average_contract_value__c, o.Expected_or_Implied_Term_Months_del__c,
(Select id From zqu__Quote__c where zqu__TCV__c > 0 )
From Opportunity o where zqu__Opportunity__r.Id  in :OpportunityIDs])
OpportunitiesToUpdate.add(new Opportunity(Id=o.Id, zqu__TCV__c = o.amount, zqu__InitialTerm__c = o.Initial_Term_From_Quote__c);
update OpportunitiesToUpdate;
}
if(OpportunitiesToUpdate != null && !OpportunitiesToUpdate.isEmpty())
Database.update(OpportunitiesToUpdate);
}

 

sushant sussushant sus

just replace ur this this

 

q.zqu__Opportunity__r.id

 

to

 

q.zqu__Opportunity__c in  every where it use .

 

q.zqu__Opportunity__c will return id as it is a lookup

SFDC-DMGSFDC-DMG

I replaced all of the "q.zqu__Opportunity__r.id" to read "q.zqu__Opportunity__c"

 

and I am still getting and error, which is the following:

 

"Didn't understand the relationship 'zqu__Quote__c'  in FROM part of query cal. If you are attempting to use a customer relationship, be sure to append the '__r' after the custom relationship name."

 

Any ideas on this?

souvik9086souvik9086

Hi, Try this

 

for(Opportunity o: [Select o.Id, o.amount, o.average_contract_value__c, o.Expected_or_Implied_Term_Months_del__c,
(Select id From zqu__Quote__r where zqu__TCV__c > 0 )
From Opportunity o where zqu__Opportunity__r.Id  in :OpportunityIDs])
OpportunitiesToUpdate.add(new Opportunity(Id=o.Id, zqu__TCV__c = o.amount, zqu__InitialTerm__c = o.Initial_Term_From_Quote__c);
update OpportunitiesToUpdate;
}

 

Change __c to __r in the nested query.

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks

 

 

SFDC-DMGSFDC-DMG

Thank you for your input as well!

 

When I make that change, I'm getting a similar error message that now says:

 

"Didn't understand the relationship 'zqu__Quote__r'  in FROM part of query cal. If you are attempting to use a customer relationship, be sure to append the '__r' after the custom relationship name."

souvik9086souvik9086

Hi,

 

Please check the child relationship name for that field in the object.

 

Go to the object -> that field -> then by clicking you will find a label child relationship name, then just use that name

 

ThatName__r in the form part of the query.

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks

 

SFDC-DMGSFDC-DMG

Hi All,

 

I still can't get this work.

 

Whenever I try updating some of the appendages to __c, I get the error saying "Didn't understand relationship 'zqu__Quote__c' in FROM part of query call."

 

And then if I change it to __r, I get the error saying "Didn't understand relationship 'zqu__Quote__r' in FROM part of query call."

 

and back and forth between those error messages as I change them. Here's what my code is looking like now if anyone has any input - the error I am getting is on line 30.

 

trigger OppUpdatefromQuoteObject on zqu__Quote__c (after delete, after insert, after undelete,
after update) {

// // This updates the opportunity with the term and amount information from the quote object

// If related to an Opportunity, query to find out the Opportunity number

public set<Id> OpportunityIDs = new Set<Id>();
public list<Opportunity> OpportunitiesToUpdate = new List<Opportunity>();


// Build the list of Opps to update
if(Trigger.isInsert || Trigger.isUnDelete || Trigger.isUpdate){
    for(zqu__Quote__c q: Trigger.new){
    OpportunityIDs.add(q.zqu__Opportunity__c );

    }
}

if(Trigger.isDelete || Trigger.isUpdate){
    for(zqu__Quote__c q: Trigger.old){
    OpportunityIDs.add(q.zqu__Opportunity__c );
    }
}


// Update the Opportunities

if(OpportunityIDs.size()>0){
for(opportunity o: [Select o.Id, o.amount, o.average_contract_value__c, o.Expected_or_Implied_Term_Months_del__c,
(Select id From zqu__Quote__c )
From Opportunity o where id  in :OpportunityIDs])
OpportunitiesToUpdate.add(new Opportunity(Id=o.Id, zqu__TCV__c = o.amount, zqu__InitialTerm__c = o.Initial_Term_From_Quote__c);
update OpportunitiesToUpdate;
}
if(OpportunitiesToUpdate != null && !OpportunitiesToUpdate.isEmpty())
Database.update(OpportunitiesToUpdate);
}