• Will Lyles
  • NEWBIE
  • 40 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 8
    Replies
I am trying to get some information about a specific user in order to run a test against my code.  The first query runs fine and I can get the associated Contact Id for the user, but when I try to get the Oracle_Account_Number__c for the contact in the second query it returns 0 rows.  If I copy the SOQL select statement from the debug logs and run it manually it returns the correct information, so the syntax seems to be correct.

Does anyone see any issues or know why I'm getting no results on the second query?
@isTest
public class myTestMethod {

    static testmethod void testupdateLineItem()
    {     
        User u = [SELECT Id FROM User WHERE UserName='community.test1@example.com'];
        System.runAs(u)
        {
            ApexPages.StandardController sc = new ApexPages.StandardController(new Case());
  			m_Case_Details_Apex test = new m_Case_Details_Apex(sc); 
     
            //get the contact ID based on the named user
            string curUserNameQry = 'SELECT ContactId FROM User where username = \'' + userinfo.getusername() + '\'';
            User curContactId = Database.query(curUserNameQry);
            
            //get the Oracle Account number associated with the Contact ID
            string oracleAcctNumQry = 'SELECT Id,Oracle_Account_Number__c from Contact where Id = \'' + curContactId.ContactId + '\'';
            Contact oracleAcct = Database.query(oracleAcctNumQry);
            string oracleAcctNum = oracleAcct.Oracle_Account_Number__c;  
        }        
    }

 
I have the following code.  I would like to replace the CreatedBy.Name field with some text when it matches and automated account we have.

What would be the best way to replace this, send it to a list so I can then use that list in my pageBlockTable.
 
public my_Test_Apex(ApexPages.StandardController stdController)
{
       this.myCase = (Case)stdController.getRecord();
        
        //get case comments
        Case com = [select Id, CaseNumber,(select ParentId,CommentBody,CreatedDate,CreatedBy.Name from CaseComments ORDER BY CreatedDate DESC) from Case where Id =: ApexPages.CurrentPage().getParameters().get('Id') ];
        caseCommentList = new List<CaseComment>();
        for(CaseComment cs : com.CaseComments)
        {
           if(cs.CreatedBy.Name.contains('NameToReplace'))
           {
               //replace 'NameToReplace' with 'Support Representative'
           }
           else
           {
               caseCommentList.add(cs);
           }
            
        }       
}

Thanks.
I am trying to format my date fields to a MM/dd/yyyy format.  I had this working until I had to use sorting in my VF page.  Now I can't figure out how to format the date and still retain the sorting feature I have on my page.

*****I was using something like this*****
<apex:outputText value="{0,date,MM/dd/yyyy}"> 
  <apex:param value="{!a.CreatedDate}" />
 </apex:outputText>


*****But had to switch to this for sorting*****
                <apex:column >
                    <apex:facet name="header">   
                        <apex:commandLink action="{!ViewData}" value="Created Date{!IF(sortExpression=='CreatedDate',IF(sortDirection='ASC','▼','▲'),'')}" id="CreatedDateSort">
                            <apex:param value="CreatedDate" name="column" assignTo="{!sortExpression}" ></apex:param>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputLink value="/{!a.Id}" target="_blank">{!a.CreatedDate}</apex:outputLink>
                </apex:column>

**** My controller method *****
public PageReference ViewData()
    {
        //build the full sort expression
        string sortFullExp = sortExpression  + ' ' + sortDirection;

        //query the database based on the sort expression
        myCases = Database.query('SELECT ID, '
                                 + 'casenumber, '
                                 + 'subject, '
                                 + 'Severity__c, '
                                 + 'Case_Type__c, '
                                 + 'CreatedDate, '
                                 + 'ClosedDate, '
                                 + 'FROM Case  '
                                 + 'WHERE OwnerId= \'' + UserInfo.getUserID() + '\''
                                 + 'ORDER BY ' + sortFullExp + ' limit 1000');
        return null;
    }

It was suggested that I create some type of wrapper, but I don't know how to do this.  Has anyone done something like this before?
I have the following SOQL query in my custom controller.  I would like to build a page that shows all the parent (case) records and related child (RMA) records in one single table.  I've been able to do this with a single case, but can't seem to figure out how to do it when I want to display all cases.

How would one go about doing this?
 
string searchquery = 'SELECT ID, '
                   + 'casenumber, '
                   + 'subject, '
                   + 'Severity__c, '
                   + 'Case_Type__c, '
                   + 'CreatedDate, '
                   + 'ClosedDate, '
            	   + 'Status, '
                   + 'Status_Comment__c, '
                    + '(select  '
                         + 'Customer_Asset_Type__c, '
                         + ' RMA_Customer_Reported_PO__c, '
                         + ' Date_Received__c, '
                         + 'PO_Contract_Date__c, '
                         + 'RMA_Actual_SN_Returned__c, '
                         + 'RMA_Customer_Reported_Failure_Inform__c, '
                         + 'RMA_Customer_Reported_Part_Number__c, '
                         + 'RMA_Customer_Reported_Qty__c, '
                         + 'RMA_Customer_Reported_SN__c, '
                         + 'Warranty_Status__c '
                         + 'from RMA_Products__r) '
                   + 'FROM Case  '
                   + 'WHERE OwnerId= \'' + UserInfo.getUserID() + '\''
                   + 'ORDER BY casenumber DESC '
                   ;

        caseResults = Database.query(searchquery);

 
I am trying to use a custom controller to get back case comments for a particular case (case id will be in URL).  I need to do this so I can sort columns (very annoying that Salesforce doesn't allow this with dataTables).  Right now I'm just trying to get some data back from my controller and failing miserably.

How can I do this?

So far this doesn't work....
****My test VF page****
<apex:page standardController="Case" extensions="TestController"> 
    <apex:form >   
        <apex:pageBlock title="{!Case.CaseNumber}"> 
			TEST:{!caseComm[0].CommentBody}
        </apex:pageBlock>   
    </apex:form>  
</apex:page>
***My test controller***
public class TestController {
    public List<Case> caseComm {get;set;}
    
    public TestController(ApexPages.StandardController controller) {
		
    }
    
    public List<Case> caseComm() {   
		List<Case> comments = [Select (Select Id, 
                            ParentId,  
                            IsPublished, 
                            CommentBody, 
                            CreatedById, 
                            CreatedDate,                  
                            LastModifiedDate, 
                            LastModifiedById, 
                            From CaseComments) From Case ];
        return comments;
    }
    
    
}


 
I am trying to get some information about a specific user in order to run a test against my code.  The first query runs fine and I can get the associated Contact Id for the user, but when I try to get the Oracle_Account_Number__c for the contact in the second query it returns 0 rows.  If I copy the SOQL select statement from the debug logs and run it manually it returns the correct information, so the syntax seems to be correct.

Does anyone see any issues or know why I'm getting no results on the second query?
@isTest
public class myTestMethod {

    static testmethod void testupdateLineItem()
    {     
        User u = [SELECT Id FROM User WHERE UserName='community.test1@example.com'];
        System.runAs(u)
        {
            ApexPages.StandardController sc = new ApexPages.StandardController(new Case());
  			m_Case_Details_Apex test = new m_Case_Details_Apex(sc); 
     
            //get the contact ID based on the named user
            string curUserNameQry = 'SELECT ContactId FROM User where username = \'' + userinfo.getusername() + '\'';
            User curContactId = Database.query(curUserNameQry);
            
            //get the Oracle Account number associated with the Contact ID
            string oracleAcctNumQry = 'SELECT Id,Oracle_Account_Number__c from Contact where Id = \'' + curContactId.ContactId + '\'';
            Contact oracleAcct = Database.query(oracleAcctNumQry);
            string oracleAcctNum = oracleAcct.Oracle_Account_Number__c;  
        }        
    }

 
I have the following code.  I would like to replace the CreatedBy.Name field with some text when it matches and automated account we have.

What would be the best way to replace this, send it to a list so I can then use that list in my pageBlockTable.
 
public my_Test_Apex(ApexPages.StandardController stdController)
{
       this.myCase = (Case)stdController.getRecord();
        
        //get case comments
        Case com = [select Id, CaseNumber,(select ParentId,CommentBody,CreatedDate,CreatedBy.Name from CaseComments ORDER BY CreatedDate DESC) from Case where Id =: ApexPages.CurrentPage().getParameters().get('Id') ];
        caseCommentList = new List<CaseComment>();
        for(CaseComment cs : com.CaseComments)
        {
           if(cs.CreatedBy.Name.contains('NameToReplace'))
           {
               //replace 'NameToReplace' with 'Support Representative'
           }
           else
           {
               caseCommentList.add(cs);
           }
            
        }       
}

Thanks.
I have the following SOQL query in my custom controller.  I would like to build a page that shows all the parent (case) records and related child (RMA) records in one single table.  I've been able to do this with a single case, but can't seem to figure out how to do it when I want to display all cases.

How would one go about doing this?
 
string searchquery = 'SELECT ID, '
                   + 'casenumber, '
                   + 'subject, '
                   + 'Severity__c, '
                   + 'Case_Type__c, '
                   + 'CreatedDate, '
                   + 'ClosedDate, '
            	   + 'Status, '
                   + 'Status_Comment__c, '
                    + '(select  '
                         + 'Customer_Asset_Type__c, '
                         + ' RMA_Customer_Reported_PO__c, '
                         + ' Date_Received__c, '
                         + 'PO_Contract_Date__c, '
                         + 'RMA_Actual_SN_Returned__c, '
                         + 'RMA_Customer_Reported_Failure_Inform__c, '
                         + 'RMA_Customer_Reported_Part_Number__c, '
                         + 'RMA_Customer_Reported_Qty__c, '
                         + 'RMA_Customer_Reported_SN__c, '
                         + 'Warranty_Status__c '
                         + 'from RMA_Products__r) '
                   + 'FROM Case  '
                   + 'WHERE OwnerId= \'' + UserInfo.getUserID() + '\''
                   + 'ORDER BY casenumber DESC '
                   ;

        caseResults = Database.query(searchquery);

 
I am trying to use a custom controller to get back case comments for a particular case (case id will be in URL).  I need to do this so I can sort columns (very annoying that Salesforce doesn't allow this with dataTables).  Right now I'm just trying to get some data back from my controller and failing miserably.

How can I do this?

So far this doesn't work....
****My test VF page****
<apex:page standardController="Case" extensions="TestController"> 
    <apex:form >   
        <apex:pageBlock title="{!Case.CaseNumber}"> 
			TEST:{!caseComm[0].CommentBody}
        </apex:pageBlock>   
    </apex:form>  
</apex:page>
***My test controller***
public class TestController {
    public List<Case> caseComm {get;set;}
    
    public TestController(ApexPages.StandardController controller) {
		
    }
    
    public List<Case> caseComm() {   
		List<Case> comments = [Select (Select Id, 
                            ParentId,  
                            IsPublished, 
                            CommentBody, 
                            CreatedById, 
                            CreatedDate,                  
                            LastModifiedDate, 
                            LastModifiedById, 
                            From CaseComments) From Case ];
        return comments;
    }
    
    
}