• Mitchellb
  • NEWBIE
  • 50 Points
  • Member since 2013

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 9
    Questions
  • 7
    Replies

Error at run time: Variable does not exist: ProgramFlowExperiment.EmailCounter

----------------------------

 

Running this example of a test class using a trigger fails when I get to the TestContactOwnerChange class. The EmailCounter variable is not visible and the System.assertEquals does not see the variable EmailCounter created in the ProgramFlowExperiment class. 

 

------------------------------------
public class ProgramFlowExperiment {

public static Integer EmailCounter = 0;

private void SendEmail(){
EmailCounter++;
System.Debug('Queueing the email to send');
}

private void SendQueuedEmails(){
System.Debug('Sending queued emails');
}

public void HandleContactUpdateTrigger(List<Contact> newlist, Map<Id, Contact> oldmap){
for(Contact ct: newlist){
if(ct.OwnerId != oldmap.get(ct.Id).OwnerId){
SendEmail();
}
}
SendQueuedEmails();
}
}

------

trigger ContactOwnerChangeTrigger on Contact (after update) {
ProgramFlowExpermient pf = new ProgramFlowExperiment();
pf.HandleContactUpdateTrigger(trigger.new, trigger.oldmap);
}

-------


@isTest
private class TestContactOwnerChange {

static testMethod void TestOwnerChange() {
// Create some tests
List<Contact> newcontacts = initTextContacts('c', 5);

user u = initTestUser('myname', 'myname');

System.runAs(u){
//These contacts will be created with the fake user as owner
insert newcontacts;
}

Test.StartTest();
for(Contact ct: newcontacts){
ct.OwnerID = UserInfo.getUserId();
ct.Email = 'someone@somehwere.com';
}

update newcontacts;

Test.stopTest();

System.AssertEquals(newcontacts.size(), ProgramFlowExperiment.EmailCounter);

}

public static List<Contact> initTestContacts(String prfix, Integer count){
List<Contact> results = new List<Contact>();
for(Integer x=1; x <count; x++){
results.add(new Contact(LastName = prefix + '_' + string.valueOf(x),
email = prefix + '_' + string.valueOf(x) + '@apexfundamentals.com' ));
}
return results;
}

public static User initTestUser(String username, String thealias){
User u = new User(Alias = thealias,
Email = username + '@apexfunadamentals.com',
FirstName = 'Joe', LastName = username,
TimeZoneSidKey = 'America/Los_Angeles',
UserName = username + '@apexfundamentals.com',
UserPermissionsMarketingUser=true, LocaleSidKey='en_US',
EmailEncoding='UTF-8', LanguageLocaleKey = 'en_US');
u.ProfileID = userinfo.getProfileId();
return u;

}
}

 

After adding a custom link to container in the Home Narrow Component and selecting "Display with side bar and hear" I still have the VF page only when I select the custom link - no header and side bar. I am just trying to populate the Home Wide Compenent with the VF page. 

The following code launches the new page inside the same window:

 

public

withsharingclass ContractingOpportunities {

public String Value2Pass { get; set; }

public PageReference generateContract() {

        PageReference newPage = page.ContractCreation;

        newPage.getParameters().put(

'MyVariable', Value2Pass);

       

return newPage;

    }

   

public String message { get; set; }

 

DisplayOpportunities[] opportunities;

publicclass DisplayOpportunities {

    

publicOpportunity opportunity { get; set; }

    

public Decimal count { get; set; }

    

public DisplayOpportunities(Opportunity item) {

       

this.opportunity = item;

    }

}

public

DisplayOpportunities[] getOpportunities() {     if (opportunities == null) {

         opportunities =

new DisplayOpportunities[]{};

        

for (Opportunity item :

                                [

SELECTName, Contract_Type__c, OrderNumber__c, TrackingNumber__c, CurrentGenerators__c                             

                                

FROMOpportunity

                                 ORDER

BY Contract_Type__c DESC

                                 ]) {       opportunities.add(

new DisplayOpportunities(item));       }     }

    

return opportunities;      }

}

 

Suggestions on how to make the newPage launch cleanly?

I am working alone at the moment and I only want to have 1 project perspective which is always synced with the server. I beleive I was editing or looking at the controller and created an out of sync edit with the Page editor. When I tried to sync the project copy of the class it seemed as if I could not resole the issue without creating the Team perspective. Now I am stuck manually syncing everything when I make a project/local change to code.

 

How do I delete the team perspective and sync only my local copy if this happens again? I do not plan to edit controllers in the Page Editor, but I do edit the page Apex code. This should not create sync issues, right?

I have created a custom object which I am unable to reference in side newly created class. The error I receive is:

 

Save error: Invalid type: Invoice_Statement_c

 

Is there a location where I need to modify permissions or object type that will make this object accessible in the code?

After having made changes in the edit window to the APEX code connected to the page, I attempted to return to the IDE to make changes to the controller class but updating the server failed. The instruction was to Synchronize the Perspective. Where is the command for this? I only see 'customize','save' and 'reset Perspective in the 'Window' drop down menu.

I created the Warehouse application according to the tutorial, but the custom fields Unit Price and Units Sold are uneditable when using the 'Basic User' profile. The object is totally enabled for that profile and those fields are not associated with the Merchandise or Line Item object. How do I get at these fields to change the permissions associated with those fields so that the Basic User can edit them?

 

 

I have created the Invoice Statement object from the tutorials and created Line Items with the Master-detail realtionship. I am able to create Line Items in the Invoice statement, but after created a user with Standard User profile and logging in, I cannot see the Line Item detail in the Invoice Statement. Where do I go to make that detail visible to the Standard User?

The code below creates this error:

Error: Attribute value in <apex:inputField> must contain only a formula expression that resolves to a single controller variable or method in accountDetail at line 5 column 44

------

<apex:page standardController="Account">
<apex:form>
<apex:pageBlock>
Change Account Name: <p>
<apex:inputField Value="{ !Account.Name}"/> <p/>
<apex:commandButton action="{ !save}" value="Save New Account" />
</apex:pageBlock>
</apex:form>
<apex:detail relatedList="false"/>
<apex:relatedList list="Contacts" />
<apex:relatedList list="Opportunities"/>
</apex:page>

-----

Since 'Name' clearly exists as a field, is there something wrong with the syntax of that line?

 

Also, how can you have a list of all the field names or variable names for a specific object in a window while coding, instead of navigating to the 'Customize' menu?

 

Error at run time: Variable does not exist: ProgramFlowExperiment.EmailCounter

----------------------------

 

Running this example of a test class using a trigger fails when I get to the TestContactOwnerChange class. The EmailCounter variable is not visible and the System.assertEquals does not see the variable EmailCounter created in the ProgramFlowExperiment class. 

 

------------------------------------
public class ProgramFlowExperiment {

public static Integer EmailCounter = 0;

private void SendEmail(){
EmailCounter++;
System.Debug('Queueing the email to send');
}

private void SendQueuedEmails(){
System.Debug('Sending queued emails');
}

public void HandleContactUpdateTrigger(List<Contact> newlist, Map<Id, Contact> oldmap){
for(Contact ct: newlist){
if(ct.OwnerId != oldmap.get(ct.Id).OwnerId){
SendEmail();
}
}
SendQueuedEmails();
}
}

------

trigger ContactOwnerChangeTrigger on Contact (after update) {
ProgramFlowExpermient pf = new ProgramFlowExperiment();
pf.HandleContactUpdateTrigger(trigger.new, trigger.oldmap);
}

-------


@isTest
private class TestContactOwnerChange {

static testMethod void TestOwnerChange() {
// Create some tests
List<Contact> newcontacts = initTextContacts('c', 5);

user u = initTestUser('myname', 'myname');

System.runAs(u){
//These contacts will be created with the fake user as owner
insert newcontacts;
}

Test.StartTest();
for(Contact ct: newcontacts){
ct.OwnerID = UserInfo.getUserId();
ct.Email = 'someone@somehwere.com';
}

update newcontacts;

Test.stopTest();

System.AssertEquals(newcontacts.size(), ProgramFlowExperiment.EmailCounter);

}

public static List<Contact> initTestContacts(String prfix, Integer count){
List<Contact> results = new List<Contact>();
for(Integer x=1; x <count; x++){
results.add(new Contact(LastName = prefix + '_' + string.valueOf(x),
email = prefix + '_' + string.valueOf(x) + '@apexfundamentals.com' ));
}
return results;
}

public static User initTestUser(String username, String thealias){
User u = new User(Alias = thealias,
Email = username + '@apexfunadamentals.com',
FirstName = 'Joe', LastName = username,
TimeZoneSidKey = 'America/Los_Angeles',
UserName = username + '@apexfundamentals.com',
UserPermissionsMarketingUser=true, LocaleSidKey='en_US',
EmailEncoding='UTF-8', LanguageLocaleKey = 'en_US');
u.ProfileID = userinfo.getProfileId();
return u;

}
}

 

The following code launches the new page inside the same window:

 

public

withsharingclass ContractingOpportunities {

public String Value2Pass { get; set; }

public PageReference generateContract() {

        PageReference newPage = page.ContractCreation;

        newPage.getParameters().put(

'MyVariable', Value2Pass);

       

return newPage;

    }

   

public String message { get; set; }

 

DisplayOpportunities[] opportunities;

publicclass DisplayOpportunities {

    

publicOpportunity opportunity { get; set; }

    

public Decimal count { get; set; }

    

public DisplayOpportunities(Opportunity item) {

       

this.opportunity = item;

    }

}

public

DisplayOpportunities[] getOpportunities() {     if (opportunities == null) {

         opportunities =

new DisplayOpportunities[]{};

        

for (Opportunity item :

                                [

SELECTName, Contract_Type__c, OrderNumber__c, TrackingNumber__c, CurrentGenerators__c                             

                                

FROMOpportunity

                                 ORDER

BY Contract_Type__c DESC

                                 ]) {       opportunities.add(

new DisplayOpportunities(item));       }     }

    

return opportunities;      }

}

 

Suggestions on how to make the newPage launch cleanly?

I am working alone at the moment and I only want to have 1 project perspective which is always synced with the server. I beleive I was editing or looking at the controller and created an out of sync edit with the Page editor. When I tried to sync the project copy of the class it seemed as if I could not resole the issue without creating the Team perspective. Now I am stuck manually syncing everything when I make a project/local change to code.

 

How do I delete the team perspective and sync only my local copy if this happens again? I do not plan to edit controllers in the Page Editor, but I do edit the page Apex code. This should not create sync issues, right?

I have created the Invoice Statement object from the tutorials and created Line Items with the Master-detail realtionship. I am able to create Line Items in the Invoice statement, but after created a user with Standard User profile and logging in, I cannot see the Line Item detail in the Invoice Statement. Where do I go to make that detail visible to the Standard User?

The code below creates this error:

Error: Attribute value in <apex:inputField> must contain only a formula expression that resolves to a single controller variable or method in accountDetail at line 5 column 44

------

<apex:page standardController="Account">
<apex:form>
<apex:pageBlock>
Change Account Name: <p>
<apex:inputField Value="{ !Account.Name}"/> <p/>
<apex:commandButton action="{ !save}" value="Save New Account" />
</apex:pageBlock>
</apex:form>
<apex:detail relatedList="false"/>
<apex:relatedList list="Contacts" />
<apex:relatedList list="Opportunities"/>
</apex:page>

-----

Since 'Name' clearly exists as a field, is there something wrong with the syntax of that line?

 

Also, how can you have a list of all the field names or variable names for a specific object in a window while coding, instead of navigating to the 'Customize' menu?