• Michael Webb 15
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 6
    Replies
I am trying to just add a sucess message when the user enters a case, I am obviously new to Apex and can't figure out how to do this. When I put this in I get the following error message on the success - ​Keep getting the error message - Non-void method might not return a value or might have statement after a return statement.

 // Insert the case
                INSERT c;
                if (objAttachment.Body != null) {
                    // Insert attachment if exists
                      objAttachment.ParentId = c.Id;
                    insert objAttachment;
                }
                
                 ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM, 'Success!'));
            } catch (Exception e) {
                ApexPages.addMessages(e);
                return null;
            }
        }
    }

Thank you very much for any information on how to do this. 
Hello All,

We have a test class that is causing errors when I try to move items into production. I know what is causing the error (I am not a developer and we do not have one here) it is the last line that when the developer created the test case would have been null, but since then there was a change. I just need to comment out one line.

I know how to comment out the line, I just don't know how to get that test class back into prod, when I try the test runs and errors out so it is basically a catch22 here. Thanks in advance for any assistance.
Hello,

I tried a few different times to create a attach file when creating a case with this page. I keep getting errors (I am new to Apex so thank you in advance).

Here is what I have the VF page and the controller.

Controller 

public class SubmitCaseController {     
    public Case c { get; set; }
    // public String acctNum { get; set; }
    public SelectOption[] caseTypes { get; set;}
    
    public List<Case> UserCaseList
    {
        get
        {
            return [Select Status, Origin, ClosedDate, CaseNumber, Subject
                    From Case
                    Where Contact.Email = :UserInfo.getUserEmail() AND Origin = 'SF' limit 10];
        }
    }
    
    public SubmitCaseController(ApexPages.StandardController controller) {
        c = new Case();
        this.caseTypes = new SelectOption[]{};
        this.caseTypes.add(new SelectOption('-', '-'));
        this.caseTypes.add(new SelectOption('Question','Question'));
        this.caseTypes.add(new SelectOption('Problem', 'Problem'));
        this.caseTypes.add(new SelectOption('Enhancement', 'Enhancement'));
        this.caseTypes.add(new SelectOption('Training', 'Training'));
   }
    
    public Contact userContact
    {
        get
        {
            
            Contact cnt = [SELECT Id FROM Contact WHERE Email = :c.SuppliedEmail LIMIT 1];
            if (cnt != null) return cnt;
            else return null;
        }
    }

    public PageReference submitCase() {
       // List<Account> accts = [SELECT Id FROM Account WHERE AccountNumber = :acctNum Limit 100];

        // if (accts.size() != 1) {
            //ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Invalid account number');
            //ApexPages.addMessage(msg);
            //return null;
      //  } else {
            try {
                if (c.Type == '-') 
                {
                     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Invalid Type Selected'));
                     return null;
                }

                // c.AccountId = accts.get(0).Id;  
                c.SuppliedEmail = UserInfo.getUserEmail();
                c.Origin = 'SF';
                //c.RecordTypeId = '012W00000000Xmb';
                c.RecordTypeId = '012000000004yTO';
                c.Product__c = 'Salesforce.com';
                c.OwnerId = '00500000007HkiF';
                if (c.Customer_Facing__c == TRUE) {
                c.Priority = 'High -2';
                } else {(c.Customer_Facing__c = FALSE);
                
                (c.Priority = 'Med - 3');
                 }
                
                // now look for an associated contact with the same email
                Contact cnt = userContact;
                if (cnt != null) c.ContactId = cnt.Id;
                
                // Specify DML options to ensure the assignment rules are executed
                // Database.DMLOptions dmlOpts = new Database.DMLOptions();
                // dmlOpts.assignmentRuleHeader.useDefaultRule = true;
                // c.setOptions(dmlOpts); 
                // Insert the case
                INSERT c;
                return new PageReference('/home/home.jsp');
            } catch (Exception e) {
                ApexPages.addMessages(e);
                return null;
            }
        }
    }

VF Page 

<apex:page standardController="Case" extensions="SubmitCaseController" tabStyle="CTSB_SF_Support__tab">
    <style>
        .tableheader{
        text-align:Center; 
        padding-bottom: 10px; 
        }
        .tablecell{
        text-align:left; 
        padding-bottom: 10px; 
        }
        .tablecustom
        {
        font-size:larger;
        }
    </style>
    <apex:relatedList list="CaseList" />
    <apex:form >
        
        <apex:pageBlock title="CTSB Salesforce.com Case">   
            <apex:pageMessages />
            <apex:pageBlockSection title="Contact Info">
                
                <table class="tablecustom">
                    <tr>
                        <th class="tableheader">Name:</th> 
                        <td class="tablecell">{!$User.FirstName} {!$User.LastName}</td>
                    </tr>
                    
                    <tr>
                        <th style="text-align:right">Email:</th>
                        <td class="tablecell">{!$User.Email}</td>
                    </tr>
                </table>
            </apex:pageBlockSection>
            <apex:pageBlockSection id="RedSection" columns="1" title="Issue Description">
                <apex:inputText required="true" value="{!c.Subject}"/>
                <apex:selectList size="1" value="{! c.Type}">
                    <apex:selectOptions value="{! caseTypes}" />
                </apex:selectList>
                <apex:inputField value="{!c.Area__c}"/>
                <apex:inputField value="{!c.Related_Record__c}"/>
                <apex:inputTextArea required="true" rows="3" value="{!c.Description}" />
                 <apex:inputField value="{!c.Customer_Facing__c}"/>
                                             
                <apex:commandButton value="Submit Case" action="{!submitCase}"/>
            </apex:pageBlockSection>
            <apex:pageBlockTable value="{!UserCaseList}" var="c">
                <apex:column >
                    <apex:facet name="header">
                        <apex:outputLabel value="{!$ObjectType.Case.Fields.CaseNumber.Label}" />
                    </apex:facet>
                    <apex:outputLink value="/{!c.id}" target="_blank">{!c.CaseNumber}</apex:outputLink>
                </apex:column>
                <apex:column value="{!c.Subject}" />
                <apex:column value="{!c.Status}" />
                <apex:column value="{!c.Origin}" />
                <apex:column value="{!c.ClosedDate}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
        
    </apex:form>
    
</apex:page>

Any help would be extremely helpful, I was able to do quite a bit for my first VF and Apex controller, I assumed this would be easy but I just can't get it.

Thank you in advance!

 
I am not sure what I am doing incorrectlly, I am pretty new.

Here is my query, I need to add a limit in there no matter what I try it is not working.

public PageReference submitCase() {
         List<Account> accts = [SELECT Id FROM Account WHERE AccountNumber = :acctNum];

I tried which I thought would work.

List<Account> accts = [SELECT Id FROM Account [Limit 100] WHERE AccountNumber = :acctNum limit 10];

But it is not.  Thanks in advance!
We use Cases for our internal IT support in addition to the various customer support departments in our company.  I would like to create a tab with a form for users to be able to submit a helpdesk case for Salesforce issues.  It would be great if it could take the users login ie email address and populate that. 

I was thinking web to case, however, another department is using that, and I don't want to have to find a place to host the one html page, plus I don't want to make it pretty :-) .. Just a quick form in SF that you click on and submit it goes right to the case assigned to the specific person or queue and that is it. I will use workflow to reply and can give the users a view that shows the cases submitted by them.  What would be really cool is if I could have the view of their cases below the form!  I am assuing I could do this with visualforce, however, I don't know VF. ill try though just need a start! thank you!
Hello, I have a trigger that I think someone deployed with a Salesforce Labs app, it is very basic (I do not know apex very well). When I run all the tests through the developer console it shows we are at 80% coverage and this specific trigger gets 100% coverage.  However, when I use a change set to deploy any Apex code I get the following error.

AttachmentTrigger, Details: Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

1
2
3 trigger AttachmentTrigger on Attachment (after insert) {
    TriggerUtility.updateCaseLastActivity(Trigger.New,'attachment');
}

I am not sure where to start if I need to write a test class for this, any suggestions and any idea why there is a difference? 

Thanks in advance
Michael
I have a custom object that has a State field on it, related to this custom object is a another custom object with Questions we ask depending on what state the first object is located. ie the Company Account is in New York, then the user clicks on New QA and then chooses NY for the record type and the page layout for NY and the questions shows up.  I would like to see if I could create a custom button to create a new object and when it see's New York as the state from the Object it is being created from, it automatically defaults to the record type of New York.  Same with California, Alabama and so on.  I know I can set the record type, not sure how to do that with a formula.

Thanks in Advance!
Michael
I am trying to just add a sucess message when the user enters a case, I am obviously new to Apex and can't figure out how to do this. When I put this in I get the following error message on the success - ​Keep getting the error message - Non-void method might not return a value or might have statement after a return statement.

 // Insert the case
                INSERT c;
                if (objAttachment.Body != null) {
                    // Insert attachment if exists
                      objAttachment.ParentId = c.Id;
                    insert objAttachment;
                }
                
                 ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.CONFIRM, 'Success!'));
            } catch (Exception e) {
                ApexPages.addMessages(e);
                return null;
            }
        }
    }

Thank you very much for any information on how to do this. 
Hello All,

We have a test class that is causing errors when I try to move items into production. I know what is causing the error (I am not a developer and we do not have one here) it is the last line that when the developer created the test case would have been null, but since then there was a change. I just need to comment out one line.

I know how to comment out the line, I just don't know how to get that test class back into prod, when I try the test runs and errors out so it is basically a catch22 here. Thanks in advance for any assistance.
Hello, I have a trigger that I think someone deployed with a Salesforce Labs app, it is very basic (I do not know apex very well). When I run all the tests through the developer console it shows we are at 80% coverage and this specific trigger gets 100% coverage.  However, when I use a change set to deploy any Apex code I get the following error.

AttachmentTrigger, Details: Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

1
2
3 trigger AttachmentTrigger on Attachment (after insert) {
    TriggerUtility.updateCaseLastActivity(Trigger.New,'attachment');
}

I am not sure where to start if I need to write a test class for this, any suggestions and any idea why there is a difference? 

Thanks in advance
Michael
I have a custom object that has a State field on it, related to this custom object is a another custom object with Questions we ask depending on what state the first object is located. ie the Company Account is in New York, then the user clicks on New QA and then chooses NY for the record type and the page layout for NY and the questions shows up.  I would like to see if I could create a custom button to create a new object and when it see's New York as the state from the Object it is being created from, it automatically defaults to the record type of New York.  Same with California, Alabama and so on.  I know I can set the record type, not sure how to do that with a formula.

Thanks in Advance!
Michael