• dbush2765
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 1
    Replies

So I'm trying to run some code through the developer console with execute anonymous. 

 

Anytime I try to run the code, it hangs for a second at Sending Request, then just shows Execution Failed and...that's it. No error message, nothing. Since I'm not getting an error message, I'm not really sure what's going wrong. It was working just fine a few days ago with the exact same code I'm trying to run now. Anyone ever see this issue before?

So I'm I'm writing a test method for some code that queries RecordType.Name on the Opportunity object. I'm able to grab the RecordType ID and assign it to the Opportunity. System.debug shows that the RecordType I query in the test method has an ID and Name as well.

 

For some reason, it's telling me that Opportunity.RecordType.Name is null, even after I've assigned a RecordType to the Opportunity. Anyone know what's going wrong here? Here's the code:

 

RecordType UpsellRT = [SELECT Id,Name FROM RecordType WHERE sObjectType = 'Opportunity' AND Name = 'UpSell' LIMIT 1];

Opportunity OPP = new Opportunity(
	Name = 'Test Opp',
	RecordTypeId = UpsellRT.Id,
	CloseDate = Date.valueOf('2013-01-01'),
	StageName = 'Closed Won');
insert OPP; 

Fairly new to APEX, and just wasn't really sure on where to even start looking for this. Also haven't had a chance to learn any Visualforce, yet.

Is it possible to create APEX code that runs based off of what a user selects from a list of options? For example, say I had a batch setup that automatically does some stuff with Opportunities in a custom object. Is there anything I can put into that batch to make it so the user can select, before it runs, to only look at certain types of Opps? 

 

Essentially, I'm wondering if I can set the code up so that when it queries, for example, Opps, it selects the needed fields from Opp where Type equals *whatever types user selected*.

I've been fighting this all day and can't seem to figure out what's going on.

I have a test method in which I need to have a Campaign Member, which is tied to a Contact. In the test method, I create an Account, Campaign, Contact, and Campaign Member.

 

The issue is that the Campaign Member seems to have no idea that the Contact's Account ID even exists. I can't see force Campaign Member to see it.

 

@isTest
global class TestGainsightUserGroupBatch implements Schedulable{
	
	static testMethod void GainsightUserGroupBatchTest() {

		// --------------- BEGIN SET UP --------------- //

		// Create new Account
		Account ACC = new Account(
			Name = 'Test Account'
			);
		insert ACC;

		// Create new Contact
		Contact CON = new Contact(
			FirstName = 'Test',
			LastName = 'Name',
			AccountId = ACC.Id
			);
		insert CON;

		// Create new Campaign
		Campaign CAM = new Campaign(
			Name = 'Test User Group Attendee',
			StartDate = Date.valueOf('2013-09-01')
			);
		insert CAM;

		// Create new Campaign Member
		CampaignMember CM = new CampaignMember(
			ContactId = CON.Id,
			CampaignId = CAM.Id,
			Status = 'Attended'
			);
		insert CM;

		System.Debug('---> Campaign Name = ' + CAM.Name);
		System.Debug('---> Campaign Member Account ID = ' + CM.Contact.AccountId);
		System.Debug('---> Campaign Member Account ID 2 = ' + CM.Contact.Account.Id);
		System.Debug('---> Account ID = ' + ACC.Id);
		System.Debug('---> Contacts Account ID = ' + CON.AccountId);

 I can always see the Account ID, and can see it when I just check CON.AccountID. It always returns null when I try to find it through the Campaign Member, though. Any ideas?

So I'm I'm writing a test method for some code that queries RecordType.Name on the Opportunity object. I'm able to grab the RecordType ID and assign it to the Opportunity. System.debug shows that the RecordType I query in the test method has an ID and Name as well.

 

For some reason, it's telling me that Opportunity.RecordType.Name is null, even after I've assigned a RecordType to the Opportunity. Anyone know what's going wrong here? Here's the code:

 

RecordType UpsellRT = [SELECT Id,Name FROM RecordType WHERE sObjectType = 'Opportunity' AND Name = 'UpSell' LIMIT 1];

Opportunity OPP = new Opportunity(
	Name = 'Test Opp',
	RecordTypeId = UpsellRT.Id,
	CloseDate = Date.valueOf('2013-01-01'),
	StageName = 'Closed Won');
insert OPP;