• Alanistic
  • NEWBIE
  • 30 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 16
    Questions
  • 26
    Replies
I've written a test class for a custom object but the class fails with the error System.AssertException: Assertion Failed.  I'm guessing this is because the test data is not being written.

My full class and testing class is below.  Can anyone advise what I've missed?

 
public with sharing class ctr_LiveTraining {

    public List<Live_Training__c> lt { get; set;}
    public List<Live_Training__c> nlt { get; set;}
        
    public ctr_LiveTraining() {
        getTraining();
        getNextSession();
    } 
   
    public List<Live_Training__c> getTraining(){
        lt = [select Id, Name, Training_Date__c, Duration__c, Description__c
              from Live_Training__c where duration__c != null
              order by Training_Date__c DESC LIMIT 25];  
              return lt;
    }
    
    public void getNextSession(){
        nlt=[select Name, Training_Date__c, Description__c, Registration_Link__c
        from Live_Training__c
        where Duration__c = null 
        order by Training_Date__c DESC LIMIT 1];
    } 
    
    private static testMethod void test_ctr_LiveTraining() {
           
        ctr_LiveTraining ctrLT = new ctr_LiveTraining();
        
        // Insert with duration
        Live_Training__c testSession1 = new Live_Training__c(
            Title__c = 'Test Session',
            Description__c = 'Testing',
            Duration__c =  40,
            Training_Date__c = Date.today());
        insert testSession1;
        
        // Insert without duration
        Live_Training__c testSession2 = new Live_Training__c(
            Title__c = 'Test Session',
            Description__c = 'Testing',
            Training_Date__c = Date.today());
        insert testSession2;
        
         System.assert(ctrLT.lt.size() >0);
         System.assert(ctrLT.nlt.size() >0);
     } 
}
I have written my first (very basic) custom controller:
public with sharing class ctr_LiveTraining {

    public List<Live_Training__c> lt { get; set;}
    public List<Live_Training__c> nlt { get; set;}
    
    public ctr_LiveTraining() {
        getTraining();
        getNextSession();
    } 

    public List<Live_Training__c> getTraining(){
        lt = [select Id, Name, Training_Date__c, Duration__c, Description__c
              from Live_Training__c where duration__c != null
              order by Training_Date__c DESC LIMIT 25];  
              return lt;
    }
    
    public void getNextSession(){
        nlt=[select Name, Training_Date__c, Description__c, Registration_Link__c
        from Live_Training__c
        where Duration__c = null 
        order by Training_Date__c DESC LIMIT 1];
    } 
     
}

Could anyone provide me an example of a test class?  I've reviewed the documentation on Salesforce but there doesn't seem to be anything specific to checking a simple SOQL query. 

 
Hi have a new custom object called webinar__c.  I have a page that has a list of record names.

On my visualforce page, how can I display only the newest record for the webinar__c object?  The field names would be webinar__c.Name and webinar__c.Description__c   

This will give me a list of all of the previous entries and also a upcoming session.
I'm trying to have a controller extension that will pull back service contracts on an account:

The contacts pull through fine.  However the service contacts displays the error:

Error: Compile Error: sObject type 'ServiceContacts' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 30 column 29

My class is:


public class myAccountControllerExtension {

    public Account acct { get; set;}
    public List<Contact> cont { get; set;}
    public List<ServiceContracts> sc { get; set;}
   
    public myAccountControllerExtension(ApexPages.StandardController controller) {
        this.acct = (Account)controller.getRecord();
        getContacts(acct.id);
        getServiceContacts(acct.id);
    }

    public void getContacts(String aid){
        if(aid != null && aid instanceOf Id)
        {
            for(Account a : [select id,name,AccountNumber ,(SELECT Id, Name FROM Contacts WHERE Portal_User__c = true) FROM Account where id =:aid])
            { 
                if(a.contacts!=null && a.contacts.size()>0)
                {
                cont = a.contacts;
                system.debug('my contacts ' + cont);
                }
            }
        }
    }
   
    public void getServiceContracts(String aid){
        if(aid != null && aid instanceOf Id)
        {
            for(Account a : [select id,name,AccountId FROM ServiceContacts WHERE AccountId =:aid])
            { 
                if(a.servicecontracts!=null && a.servicecontracts.size()>0)
                {
                sc = a.servicecontracts;
                system.debug('my service contracts' + sc);
                }
            }
        }
    }
}
    
}


What is the reason for the error?  How would I resolve this?  My end goal is to have a VF page that displays specific contract fields and specific contacts.
I've added the following code to my VF page:

<analytics:reportChart reportId="00Oc0000000aXNS" size="small"></analytics:reportChart>

The report is on cases and displays a pie chart.

The VF page displays details on a single selected account.  The chart however pulls in all cases regardless of account.  How would I amend the above code so that it only filters on the cases associated with the account being displayed on the page?

Im new to controller extensions and I'm not finding the SF help pages particularly helpful in this area.

I have a VF page that shows account information.  I need to also include the contacts associated with the account.

My Extension is below:

public class myAccountControllerExtension {

    public Account account { get; }
    public Contact contact { get; }
   
    public myAccountControllerExtension(){
        contact = null;
        getContacts();
    }
   
    private void getContacts(){
        List<Account> accounts = new List<Account>([
            SELECT Id, Name, AccountNumber,          
                 (SELECT Id, Name FROM Contacts WHERE Portal_User__c = true)
            FROM Account]);
           
    }
}



When I reference the extension in my page I receive the error: 

Error: Unknown constructor 'myAccountControllerExtension.myAccountControllerExtension(ApexPages.StandardController controller)'

Can anyone advise why?

Hi,

I have portal users, chatter users and salesforce users.

When a user is created, I want a trigger that will check if the user is a portal user and then update the associated contact to show the contact has a portal account.  The contact object has a checkbox called "Portal_User__c" and I have put together the code below but I'm missing the section that updates the Contact field (shown below with the comment).  Can anyone suggest how I would update the contact?



trigger UpdateContactAsPortalUser on User (after insert, after update){

User uid =[select Contact from User where id=:UserInfo.getUserID()];

for (User newUser:Trigger.new){

if(uid.Contact !== null)

// Steps to set "Portal_User__c" field on Contact object to true

update uid;

}


Any assistance is appreciated.

I've just written my first custom controller.  It's very basic and returns data from a custom object and sorts it by a date field.

 

The data is returned and then displayed on my visualforce page.

 

public List<News__c> newsList {get; set;}

public ctr_News() { }

// Get news method to return data
public List<News__c> GetNews(){ // Creates new list of News
// Below creates a new String based on the SOQL query, ordered by sort date
String strSql = 'SELECT Id, Name, Preview_Text__c, NewsBody__c, CreatedDate, Sort_Date__c FROM News__c ORDER BY Sort_Date__c ASC';
return database.query(StrSql); // Returns the SOQL string
} // End of method

} // End of class

 

 How would I go about putting a test class into this to verify the data returned is not null?

I have a visualforce page that shows a variety of information.  I want the page to be able to get the userID, then go to the cases object and check for cases where that user is the main contact and where the case is a specific status.  

 

If the status is "More information needed" or "Solution sent" I want to display some text on the page to say 1 or more case needs attention.  If no cases are on those statuses I want to display there are no cases that need attention.

 

Can anyone advise me how I would get started with this?

Hi,

 

I have created a very basic custom object called "News".  It uses a standard controller.  I have a page that displays a headline, the owner and the created date.  My visualforce code is:

 

<apex:pageBlockTable value="{!News}" var="n">
    <apex:column headerValue="Recent Posts"><br/><font size="5"><apex:outputLink value="/apex/NewsItem?id={!n.id}">{!n.Name}</apex:outputLink></font><br/><font size="1"><i>Posted by {!n.Owner.Name on {!n.CreatedDate}.</i></font><br/><br/>{!n.Preview_Text__c}<br/><br/><apex:outputLink value="/apex/NewsItem?id={!n.id}">Read More >> </apex:outputLink><br/><br/></apex:column>
    </apex:pageBlockTable>

 

How would I change this to sort by the created date by default?  I don't want the users to be able to change the order, I just want to code it to sort so that the newest records appear first.

I have some java script that works fine in a standard HTML page.  

 

The script goes through a calculation to randomly select a number.  This number matches the elements of an array, with each element holding a URL to an image.  The script then displays the image on the screen.  

 

The idea is on every page refresh a different image is displayed.

 

How would I add this to visualforce?  I've tried adding the script to a visualforce page but it doesnt work.  I've looked at the developer notes which suggests I need to add the .JS file as a static resource and then reference it from the visualforce page.

 

Can anyone provide some guidance on how I would use this to have my visualforce page reference the javascript and return a link to a static resource (my javascript array elements all contain static resource paths).

I've created a custom object that has 3 fields: ID, Name (string text) and Body (rich text).

 

I want to create a visualforce page that simply displays a list of the names, with each name acting as a link.

 

The link should open a page showing the Name and the Body.  The body is rich text and will include formatting and images.

 

Can anyone help with some directions?  I've tried with standard controllers, custom controllers, and I'm having no luck getting anything to work.  I'm really new to APEX and Visualforce.

Hi,

I'm relative new to developing on Salesforce.

 

I've managed to create a visualforce page that pulls a specific chatter feed onto it. This displays the chatter message and who posted it.

 

My visual force code:

 

{!feedItem.body.text}<br/>
<i><b>Posted {!feedItem.relativeCreatedDate} by {!feedItem.actor.name}</b></i><br/>

 

 

The question I have is how can I handle URL's. Sometimes a post on chatter will include a link and so I want the address posted to appear on the visualforce as an actual URL.

 

Any suggestions?

 

Note: The code I'm using is heavily based on the quick start guide here

 

Thanks!

 

Alan

We have an object that allows users to upload files.  A lot of these files are XML files and so they will naturally open in the browser.  

 

I want to force these to offer a "save as" dialogue instead of opening in the browser.  Can anyone advise on the best way?

 

The code for the actual download link is below:

 

<a href="/servlet/servlet.FileDownload?file={!AttachmentId}" target="_blank" onclick="IncrementDL()">

 The attachmentid is quite straight forward:

 

public String AttachmentId
    {
        get
        {
            return currentChecklist.Attachments.get(0).Id;
        }
    }

 Any suggestions?

What I'm looking for sounds quite easy but the more I think about it the more complicated it gets.

 

I have 4 checkboxes and I want to assign a percentage based on how many are checked.  So for example, if 1 is checked a field will be set to 25.  If 2 are checked then 50.  If 3 are checked then 75 and if all 4 are checked the field should be 100.

 

The checkboxes will be automatically set using a trigger when 4 specific actions are performed so what I need is a check to see how many boxes are checked and then provide the percentage.

 

I was hoping to use some kind of case statement, but it looks like there is no case statements in salesforce.  Would a series of IF statements be the way forward? 

 

I was thinking something along the lines of the below running each time the update trigger runs.

 

if 1 = true;{
    if 2 = true;{
        if 3 = true;{
             if 4 = true;{
             percent = 100;
             }else{ percent = 75;}
        }else{ percent = 50}
   }else{ percent = 25}
} else {percent = 0 }

 However in order to cover all the options each else would need to lead into another series of if statements and the if structure would become huge.

 

Does anyone have any suggestions on the best way forward?  All checkboxes are on the user object.

 

Or would I be better using a formula field and skip the APEX altogether?

 

I'm looking to have a trigger update a checkbox on a contact page whenever an idea is posted to the idea section.  I've written the trigger below but I'm missing something.

 

I think I've been able to query the ID of the user logged in (saved as uid).  I need a way to say update the field for the contact with the same ID (I'm assuming the contact ID will be the same as the user ID?)

 

This is my first attempt at Apex coding.

 

trigger UpdateContact on Idea (after insert, after update){

for (Idea newIdea : Trigger.new){

//Gets the user id who posted the idea
id uid = UserInfo.getUserId();

//Need code to set the PortalUse_IdeaRaised__c field to true (this is a checkbox)

//Something along the lines of Contact.PortalUse_IdeaRaised__c = true;
}

}

 

I have written my first (very basic) custom controller:
public with sharing class ctr_LiveTraining {

    public List<Live_Training__c> lt { get; set;}
    public List<Live_Training__c> nlt { get; set;}
    
    public ctr_LiveTraining() {
        getTraining();
        getNextSession();
    } 

    public List<Live_Training__c> getTraining(){
        lt = [select Id, Name, Training_Date__c, Duration__c, Description__c
              from Live_Training__c where duration__c != null
              order by Training_Date__c DESC LIMIT 25];  
              return lt;
    }
    
    public void getNextSession(){
        nlt=[select Name, Training_Date__c, Description__c, Registration_Link__c
        from Live_Training__c
        where Duration__c = null 
        order by Training_Date__c DESC LIMIT 1];
    } 
     
}

Could anyone provide me an example of a test class?  I've reviewed the documentation on Salesforce but there doesn't seem to be anything specific to checking a simple SOQL query. 

 
I'm trying to have a controller extension that will pull back service contracts on an account:

The contacts pull through fine.  However the service contacts displays the error:

Error: Compile Error: sObject type 'ServiceContacts' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names. at line 30 column 29

My class is:


public class myAccountControllerExtension {

    public Account acct { get; set;}
    public List<Contact> cont { get; set;}
    public List<ServiceContracts> sc { get; set;}
   
    public myAccountControllerExtension(ApexPages.StandardController controller) {
        this.acct = (Account)controller.getRecord();
        getContacts(acct.id);
        getServiceContacts(acct.id);
    }

    public void getContacts(String aid){
        if(aid != null && aid instanceOf Id)
        {
            for(Account a : [select id,name,AccountNumber ,(SELECT Id, Name FROM Contacts WHERE Portal_User__c = true) FROM Account where id =:aid])
            { 
                if(a.contacts!=null && a.contacts.size()>0)
                {
                cont = a.contacts;
                system.debug('my contacts ' + cont);
                }
            }
        }
    }
   
    public void getServiceContracts(String aid){
        if(aid != null && aid instanceOf Id)
        {
            for(Account a : [select id,name,AccountId FROM ServiceContacts WHERE AccountId =:aid])
            { 
                if(a.servicecontracts!=null && a.servicecontracts.size()>0)
                {
                sc = a.servicecontracts;
                system.debug('my service contracts' + sc);
                }
            }
        }
    }
}
    
}


What is the reason for the error?  How would I resolve this?  My end goal is to have a VF page that displays specific contract fields and specific contacts.
I've added the following code to my VF page:

<analytics:reportChart reportId="00Oc0000000aXNS" size="small"></analytics:reportChart>

The report is on cases and displays a pie chart.

The VF page displays details on a single selected account.  The chart however pulls in all cases regardless of account.  How would I amend the above code so that it only filters on the cases associated with the account being displayed on the page?

Im new to controller extensions and I'm not finding the SF help pages particularly helpful in this area.

I have a VF page that shows account information.  I need to also include the contacts associated with the account.

My Extension is below:

public class myAccountControllerExtension {

    public Account account { get; }
    public Contact contact { get; }
   
    public myAccountControllerExtension(){
        contact = null;
        getContacts();
    }
   
    private void getContacts(){
        List<Account> accounts = new List<Account>([
            SELECT Id, Name, AccountNumber,          
                 (SELECT Id, Name FROM Contacts WHERE Portal_User__c = true)
            FROM Account]);
           
    }
}



When I reference the extension in my page I receive the error: 

Error: Unknown constructor 'myAccountControllerExtension.myAccountControllerExtension(ApexPages.StandardController controller)'

Can anyone advise why?

Hi,

I have portal users, chatter users and salesforce users.

When a user is created, I want a trigger that will check if the user is a portal user and then update the associated contact to show the contact has a portal account.  The contact object has a checkbox called "Portal_User__c" and I have put together the code below but I'm missing the section that updates the Contact field (shown below with the comment).  Can anyone suggest how I would update the contact?



trigger UpdateContactAsPortalUser on User (after insert, after update){

User uid =[select Contact from User where id=:UserInfo.getUserID()];

for (User newUser:Trigger.new){

if(uid.Contact !== null)

// Steps to set "Portal_User__c" field on Contact object to true

update uid;

}


Any assistance is appreciated.

I've just written my first custom controller.  It's very basic and returns data from a custom object and sorts it by a date field.

 

The data is returned and then displayed on my visualforce page.

 

public List<News__c> newsList {get; set;}

public ctr_News() { }

// Get news method to return data
public List<News__c> GetNews(){ // Creates new list of News
// Below creates a new String based on the SOQL query, ordered by sort date
String strSql = 'SELECT Id, Name, Preview_Text__c, NewsBody__c, CreatedDate, Sort_Date__c FROM News__c ORDER BY Sort_Date__c ASC';
return database.query(StrSql); // Returns the SOQL string
} // End of method

} // End of class

 

 How would I go about putting a test class into this to verify the data returned is not null?

Hi,

 

I have created a very basic custom object called "News".  It uses a standard controller.  I have a page that displays a headline, the owner and the created date.  My visualforce code is:

 

<apex:pageBlockTable value="{!News}" var="n">
    <apex:column headerValue="Recent Posts"><br/><font size="5"><apex:outputLink value="/apex/NewsItem?id={!n.id}">{!n.Name}</apex:outputLink></font><br/><font size="1"><i>Posted by {!n.Owner.Name on {!n.CreatedDate}.</i></font><br/><br/>{!n.Preview_Text__c}<br/><br/><apex:outputLink value="/apex/NewsItem?id={!n.id}">Read More >> </apex:outputLink><br/><br/></apex:column>
    </apex:pageBlockTable>

 

How would I change this to sort by the created date by default?  I don't want the users to be able to change the order, I just want to code it to sort so that the newest records appear first.

I have some java script that works fine in a standard HTML page.  

 

The script goes through a calculation to randomly select a number.  This number matches the elements of an array, with each element holding a URL to an image.  The script then displays the image on the screen.  

 

The idea is on every page refresh a different image is displayed.

 

How would I add this to visualforce?  I've tried adding the script to a visualforce page but it doesnt work.  I've looked at the developer notes which suggests I need to add the .JS file as a static resource and then reference it from the visualforce page.

 

Can anyone provide some guidance on how I would use this to have my visualforce page reference the javascript and return a link to a static resource (my javascript array elements all contain static resource paths).

Hi,

I'm relative new to developing on Salesforce.

 

I've managed to create a visualforce page that pulls a specific chatter feed onto it. This displays the chatter message and who posted it.

 

My visual force code:

 

{!feedItem.body.text}<br/>
<i><b>Posted {!feedItem.relativeCreatedDate} by {!feedItem.actor.name}</b></i><br/>

 

 

The question I have is how can I handle URL's. Sometimes a post on chatter will include a link and so I want the address posted to appear on the visualforce as an actual URL.

 

Any suggestions?

 

Note: The code I'm using is heavily based on the quick start guide here

 

Thanks!

 

Alan

I'm looking to have a trigger update a checkbox on a contact page whenever an idea is posted to the idea section.  I've written the trigger below but I'm missing something.

 

I think I've been able to query the ID of the user logged in (saved as uid).  I need a way to say update the field for the contact with the same ID (I'm assuming the contact ID will be the same as the user ID?)

 

This is my first attempt at Apex coding.

 

trigger UpdateContact on Idea (after insert, after update){

for (Idea newIdea : Trigger.new){

//Gets the user id who posted the idea
id uid = UserInfo.getUserId();

//Need code to set the PortalUse_IdeaRaised__c field to true (this is a checkbox)

//Something along the lines of Contact.PortalUse_IdeaRaised__c = true;
}

}