function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vetriselvan ManoharanVetriselvan Manoharan 

Can't to query the Contract field in opportunity

Hi,
I need to query the Contract lookup field from Opportunity to check if contract exists. But I can't able to see the contract field to query.

Any help
Sindhu1234Sindhu1234
Do you have contract lookup field on Opportunity? 
Vetriselvan ManoharanVetriselvan Manoharan
yes.. But could not query it??
Vetriselvan ManoharanVetriselvan Manoharan
Any ideas please??
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I hope that will help u
trigger OppTrigger on Opportunity( after insert, after update )
{
	Set<String> setOppId = new Set<String>();
	for( Opportunity opp : Trigger.New )
	{
		setOppId.add(opp.id);
	}
	List<Contract> lstContact = [select id,OpportunityId from contract where OpportunityId in :setOppId ];
	Map<Id,Contract> mapOppWiseContract = new Map<Id,Contract>();
	
	for(Contract contr : lstContact)
	{
		if(mapOppWiseContract.containsKey(contr.OpportunityId)== false)
		{
			mapOppWiseContract.put(contr.OpportunityId,contr);
		}
	}
	for( Opportunity opp : Trigger.New )
	{
		if(mapOppWiseContract.containsKey(opp.id))
		{
			Contract contr = mapOppWiseContract.get(opp.id);
		}
	}
	
	
}

NOte:- I created above code in notepad. My be you will get some sytex error.

Please let us know if above code will help u

Thanks,
Amit Chaudhary
 
Vetriselvan ManoharanVetriselvan Manoharan
Hi,

Below is my query

List<AggregateResult> ar = [SELECT AccountId, Sum(ACV__c) ACVSum ,Sum(Total_Contract_Value__c) TCVSum from Opportunity where AccountId in :qualifiedAccIds and StageName = '6 - Client' and Contract_End_Date__c >= TODAY  Group By AccountId];

I need to check if contract lookup exists in it..
WhyserWhyser
I'm noticing this problem too.

The Contract field on the Opportunity is a standard lookup field.
Yet, when you try to query for it, that field simply isn't there.

A query such as this
 
Select ContractId from Opportunity where OpportunityId = 'xxxxxxxxxxxxxxxx'

will result in this error:
 
ERROR at Row:1:Column:8
No such column 'ContractId' on entity 'Opportunity'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.

This is a problem and needs to be fixed.
dalia sarkar 3dalia sarkar 3
Please check the FLS of Contract field in opportunity give accss to ur profile then only u can query
Shyam VaishnavShyam Vaishnav
The contract is a standard lookup field on Opportunity. By default the FLS is not given for any profile. To query the contract field on the opportunity we need to give FLS.
Minnie McGinnisMinnie McGinnis
The FLS is set yet users are still not able to lookup contracts. Need help.