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
msb-appsupport1.3905906418879758E12msb-appsupport1.3905906418879758E12 

How to search ticket based on campaign name?

Hi,
I want to search ticket number based on campagin. However, the console told me the campaing is not on the entity list of the ticket. 

The code I have tried is below

sbxe1__Ticket__c[] ticket = [SELECT Name FROM sbxe1__Ticket__c WHERE campaing =:'CampaginTest'];
System.debug(ticket);

How could I search based on campaign?

Thanks.

Best Answer chosen by msb-appsupport1.3905906418879758E12
msb-appsupport1.3905906418879758E12msb-appsupport1.3905906418879758E12
The below works.

sbxe1__Ticket__c[] ticket = [SELECT Name FROM sbxe1__Ticket__c WHERE sbxe1_sbx_Campaign__r.ID =:<pass the ID of the campaign for which you wish to pull the NAME field>'];

All Answers

Sonam_SFDCSonam_SFDC
Is there are relation between sbxe1__Ticket__c Object and Campaign?

sbxe1__Ticket__c Object appears to be a custom Object so i would suggest you to go through the fields present on this object - if there is no relationship between sbxe1__Ticket__c and campaign object - create one and then you will be able to filter the records on sbxe1__Ticket__c object using Campaign as a filter.


msb-appsupport1.3905906418879758E12msb-appsupport1.3905906418879758E12
It does have a lookup relationship between campaing and ticket.
User-added image
However, the selection still does not work.

Could you give me more suggestions?

Thanks.
Sonam_SFDCSonam_SFDC
From the screenshot I understand that the API name is sbxe1_sbx_Campaign__c so this will have to be used in the SOQL:

like this:

sbxe1__Ticket__c[] ticket = [SELECT Name FROM sbxe1__Ticket__c WHERE sbxe1_sbx_Campaign__c.ID =:<pass the ID of the campaign for which you wish to pull the NAME field>'];
msb-appsupport1.3905906418879758E12msb-appsupport1.3905906418879758E12
It still didn't work and gave the belwo error msg.User-added image
Sonam_SFDCSonam_SFDC
pls try this:
sbxe1__Ticket__c[] ticket = [SELECT Name FROM sbxe1__Ticket__c WHERE sbxe1__Ticket__c.sbxe1_sbx_Campaign__r.ID =:<pass the ID of the campaign for which you wish to pull the NAME field>'];

reference:
http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_relationships.htm
msb-appsupport1.3905906418879758E12msb-appsupport1.3905906418879758E12
This still did not work and gave me the error
User-added image
msb-appsupport1.3905906418879758E12msb-appsupport1.3905906418879758E12
The below works.

sbxe1__Ticket__c[] ticket = [SELECT Name FROM sbxe1__Ticket__c WHERE sbxe1_sbx_Campaign__r.ID =:<pass the ID of the campaign for which you wish to pull the NAME field>'];
This was selected as the best answer