1

When I am dragging the component into the layout I am getting the following pop up. Error

My code is as follows. I cannot seem to find the issue:

<aura:attribute name="recordId" type="String" />
<aura:attribute name="url" type="string"/>

<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <head>
    </head>
    <body>
        <div class="slds">
            <div class="slds-grid">
                <div class="slds-size--2-of-2 slds-p-around--small">
                    <div  class="slds-form-element">
                        <div class="slds-form-element__control">
                            <ui:button aura:id="button" class="button" label="Show Account Report" press="{!c.getAccountReport}"/>
                        </div>
                    </div>
                </div>
                <div class="slds-size--2-of-2 slds-p-around--small">
                    <div  class="slds-form-element">
                        <div class="slds-form-element__control">
                            <ui:button aura:id="button" class="button" label="Show Account Admin Report" press="{!c.getAccountAdminReport}"/>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
<iframe src="{!v.url}" width="100%" height="600px"/>

Component Controller:

({
getAccountReport : function(component, event, helper) {

    var action = component.get("c.getAccountReport");
    action.setParams({
      "AccountId": component.get("v.recordId");
    });
    action.setCallback(this, function(response){
      if(response.getState()=="SUCCESS"){
        component.set("v.url", response.getReturnValue());
      }
      else if (response.getState()=="ERROR"){
        $A.log("Errors", response.getError());
      }
    });
    $A.enqueAction(action);
},
getAccountAdminReport : function(component, event, helper) {

    var action = component.get("c.getAccountAdminReport");
    action.setParams({
      "AccountId": component.get("v.recordId");
    });
    action.setCallback(this, function(response){
      if(response.getState()=="SUCCESS"){
        component.set("v.url", response.getReturnValue());
      }
      else if (response.getState()=="ERROR"){
        $A.log("Errors", response.getError());
      }
    });
    $A.enqueAction(action);
}

})

Apex Controller:

public class CH_Account_Report_Viewer_Controller {

@AuraEnabled
public static string getAccountReport(Id AccountId)
{
    system.debug(AccountId);
    String userID = UserInfo.getUserName(); //getUserId();
    String baseUrl = system.label.baseReportUrl;
    String reportName = system.label.baseActReport;
    //Query the Account UCN for the record on the viewing page
    Account act =  [SELECT AccountNumber FROM Account WHERE Id=:AccountId LIMIT 1];
    User usr = [SELECT EmployeeNumber FROM User WHERE Username=:userID LIMIT 1];
    string Url = baseUrl+reportName+'account='+act.AccountNumber+'&salesrep='+usr.EmployeeNumber;
    //Return correct URL for presentation
    return url;
}

@AuraEnabled
public static string getAccountAdminReport(Id AccountId)
{
    system.debug(AccountId);
    String baseUrl = system.label.baseReportUrl;
    String reportName = system.label.baseActReport;
    //Query the Account UCN for the record on the viewing page
    Account act =  [SELECT AccountNumber FROM Account WHERE Id=:AccountId LIMIT 1];
    string Url = baseUrl+reportName+'account='+act.AccountNumber;
    //Return correct URL for presentation
    return url;
}

}

Likely easy issue that I just cannot seem to find.

Thank you for assistance.

  • are you still facing issues after fixing your code with suggested answers? – Rao Sep 20 '17 at 20:17
  • Yes, so far no change to the error status. – JP Blonshine Sep 20 '17 at 20:18
  • 1) You have a ; next to the component.get("v,recordId) params are seperated by , and not ; in this case you do not need anything. 2) This is lightning case sensitivity can cause any number of issues you have defined url typer= "string" change it to url type="String" – Rao Sep 20 '17 at 20:20
  • also what interfaces does the aura:component implement? do you have implement='force;hasRecordId"? – Rao Sep 20 '17 at 20:22
2

Sign up for a winter 18 org, you get code validation on save.

Starting winter 18 the compiler will point out all the code errors on save. You will not face these weird gotchas due to typos going forward.

https://releasenotes.docs.salesforce.com/en-us/winter18/release-notes/rn_lc_validation_on_save.htm

1) $A.enqueAction(action);

It should be ( you have typo on enqueue Action)

$A.enqueueAction(action);

2) Remove the ; at line 6 and 22

"AccountId": component.get("v.recordId")

3) Just to be safe and respect case sensitivity change the type for url attribute from string --> String

<aura:attribute name="url" type="String"/> 
| improve this answer | |
  • So first off FINALLY!!! Second, that seemed to solve all the issues. Thank you – JP Blonshine Sep 20 '17 at 20:37
  • :) its always tricky until you figure out, but seriously sign up for winter18 org, I am loving the code validation part already – Rao Sep 20 '17 at 20:38
0

You are using component.get("recordId") but you have declared aura:attribute as accountId.

Replace accountId with recordId

| improve this answer | |
  • While yes that is an issue, it did not eliminate the error. Thank you for catching that though. – JP Blonshine Sep 20 '17 at 19:28
  • Url attribute is also missing, js method name and apex method name should not be same – Himanshu Sep 20 '17 at 19:30
  • You need t refresh app builder to see updated component. It can be cache issue if you are not seeing updated code. – Himanshu Sep 20 '17 at 19:35
  • Update your question as well – Himanshu Sep 20 '17 at 19:52
  • added new code in above – JP Blonshine Sep 20 '17 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.