• sfdcJon
  • NEWBIE
  • 0 Points
  • Member since 2012

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

Hey guys,

 

Does anyone have good examples of documentation they've written for custom Apex/VF? I basically have a handful of new classes, and I want to document what they do, testing procedures, what they affect, etc.

 

Any examples out there would be great!

 

Cheers,

Jon

  • September 13, 2012
  • Like
  • 0

Hi Guys! I have an issue where a Try/Catch ALWAYS goes to the Catch when invoked from a test method. When invoked from Visualforce as normal this doesn't happen, so it has to be something in the test scenario.

 

It's the second SOQL statement below, which uses a field 'User_Contact_Link__c from the User. This is just a text field containing a Contact ID that matches a Contact record in the system.

 

Any ideas?????

 

Snippet below:

 

u = [SELECT SAG_Account_Creator__c,
                    SAG_Organization__c,
                    SAG_License_Country__c,
                    User_Contact_Link__c
             FROM User
             WHERE id = :UserInfo.getUserId()
             LIMIT 1];

ID convertToLong = u.User_Contact_Link__c;
        String longId = convertToLong;
 
        system.debug('++++UserCon'+u.User_Contact_Link__c);
        system.debug('++++Long'+longId);
        
        try{
            c = [SELECT Id
                        FROM Contact
                        WHERE id = :longId
                        LIMIT 1];system.debug('++++cid'+c.id);}
        catch(QueryException e2){error=TRUE;}

 

  • September 11, 2012
  • Like
  • 0

Hey guys-

 

I have the following which has been driving me crazy:

 

I'm writing a test method for a custom controller, and the second try/catch always fails when I run the test.

 

The code works perfectly when invoked through VF, but the test method fails on the second try/catch every time...

 

Any ideas out there??

 

 

//Record Type could throw an error if the 'Name' has changed
        try{
            rt = [SELECT Id 
                         FROM RecordType 
                         WHERE Name = 'Standard Request'
                         AND SobjectType = 'Case' 
                         LIMIT 1];}
        catch(QueryException e1){error=TRUE;}
        
        //Contact record which matches the current user. Text field could be incorrect on User and throw an error
        //Cast to ID, then back to string, to get full 18 characters
        ID convertToLong = u.User_Contact_Link__c;
        String longId = convertToLong;
 
        system.debug('++++UserCon'+u.User_Contact_Link__c);
        system.debug('++++Long'+longId);
        
        try{
            c = [SELECT Id
                        FROM Contact
                        WHERE id = :longId
                        LIMIT 1];}
        catch(QueryException e2){error=TRUE;}
                  
        //If either exception occurs, then exit and throw a generic error.
        if(error == TRUE){
        
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'An error has occurred. Please open this ticket from the Change Request tab.'));    
            return null;
        }       

Hi Guys! I have an issue where a Try/Catch ALWAYS goes to the Catch when invoked from a test method. When invoked from Visualforce as normal this doesn't happen, so it has to be something in the test scenario.

 

It's the second SOQL statement below, which uses a field 'User_Contact_Link__c from the User. This is just a text field containing a Contact ID that matches a Contact record in the system.

 

Any ideas?????

 

Snippet below:

 

u = [SELECT SAG_Account_Creator__c,
                    SAG_Organization__c,
                    SAG_License_Country__c,
                    User_Contact_Link__c
             FROM User
             WHERE id = :UserInfo.getUserId()
             LIMIT 1];

ID convertToLong = u.User_Contact_Link__c;
        String longId = convertToLong;
 
        system.debug('++++UserCon'+u.User_Contact_Link__c);
        system.debug('++++Long'+longId);
        
        try{
            c = [SELECT Id
                        FROM Contact
                        WHERE id = :longId
                        LIMIT 1];system.debug('++++cid'+c.id);}
        catch(QueryException e2){error=TRUE;}

 

  • September 11, 2012
  • Like
  • 0

Hey guys-

 

I have the following which has been driving me crazy:

 

I'm writing a test method for a custom controller, and the second try/catch always fails when I run the test.

 

The code works perfectly when invoked through VF, but the test method fails on the second try/catch every time...

 

Any ideas out there??

 

 

//Record Type could throw an error if the 'Name' has changed
        try{
            rt = [SELECT Id 
                         FROM RecordType 
                         WHERE Name = 'Standard Request'
                         AND SobjectType = 'Case' 
                         LIMIT 1];}
        catch(QueryException e1){error=TRUE;}
        
        //Contact record which matches the current user. Text field could be incorrect on User and throw an error
        //Cast to ID, then back to string, to get full 18 characters
        ID convertToLong = u.User_Contact_Link__c;
        String longId = convertToLong;
 
        system.debug('++++UserCon'+u.User_Contact_Link__c);
        system.debug('++++Long'+longId);
        
        try{
            c = [SELECT Id
                        FROM Contact
                        WHERE id = :longId
                        LIMIT 1];}
        catch(QueryException e2){error=TRUE;}
                  
        //If either exception occurs, then exit and throw a generic error.
        if(error == TRUE){
        
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'An error has occurred. Please open this ticket from the Change Request tab.'));    
            return null;
        }       

I am using custom controller to handle data in visualforce page.Now there is a requirement for me to display  relatedlist of notes and attachments in vf page.

How to display the related list of perticular contact  using apex controller?

 

Please help me to achieve  this..thanks in advance