0

I have this component that is available from a Community, where an object gets populated and passed to Apex controller in a JSON String. From the server side, it should show via debug what I ask, but nothing happens.

Component markup:

<aura:attribute name="contactInfo" type="Contact"
                default="{
                'Id': '',
                'MailingStreet': '', 'MailingCity': '',
                'MailingState': '', 'MailingPostalCode': '',
                'MailingCountry': 'US', 'MobilePhone': '',
                'Secondary_Email__c': '',
                'Birthdate': '',
                --- ETC ---
                "/>

Component controller.js:

updateContactInfo : function(component, event, helper) {
    var cId = component.get("v.contactId"); // Updated from the doInit method
    component.set("v.contactInfo.Id",cId);
    // console.log(cId);
    var contact = component.get("v.contactInfo");
    // console.log('Contact: ' + JSON.stringify(contact));
    var action = component.get("c.updateContact");
    action.setParams({
        jsonContact : JSON.stringify(contact)
    });
    var self = this;
    // console.log('Params ' + JSON.stringify(action.getParams()));
    action.setCallback(this, function(response){
        var state = response.getState();
        if(state === "SUCCESS") {
            console.log(response.getReturnValue());
        } else {
            console.error(JSON.stringify(response.getError()));
        }
    });
    $A.enqueueAction(action);
}

Server-side Apex controller:

@AuraEnabled
public static String updateContact(String jsonContact) {
    System.debug(jsonContact);
    if (!String.isBlank(jsonContact)) {
        try {
            Contact con = (Contact) JSON.deserialize(jsonContact, Contact.class);
            System.debug('Contact from Client Controller: ' + con);
            if (con != null) {
                try {
                    update con;
                    System.debug(con.Birthdate);
                } catch (DmlException e) {
                    System.debug('Exception' + e.getMessage());
                }
            }
        } catch (Exception e) {
            System.debug('Exception' + e.getMessage());
            throw new AuraHandledException('There was an error in the Operation: ' + e.getMessage());
        }
    }
    return 'Ok';
}

This is the console log:

Console Log

And here is where I should see the debug log from the Apex controller but I see nothing.

No debug logs :'(

So, is returning me the 'Ok' String, that means that is accessing the controller method, but what's wrong here? Why I don't see the debugs? Furthermore, why is not executing what is inside the method?

Background:

I'm logged into the community from a Community User with Custom Profile (Apex permission on all classes). The information that I'm trying to edit belongs to that User's contact record (permissions to CRUD on objects) which I have already tested in order to edit a record (does works), so permission should not be the issue I believe (not 100% sure).

I don't know where else to look to troubleshoot this, so thanks in advance for your help.

2

If you are logged as diffrent user, you have to enable debug log tracking for that user. Go to Setup -> Logs -> Debug Logs, then new and select user that you would like to see debug log. More informations here: https://help.salesforce.com/articleView?id=code_add_users_debug_log.htm&type=5

Also in developer console you have to uncheck Debug->Show my current logs only.

1

Dev console would show logs generated by you such as you update some record from your user. If you are using community user to test your code, then you have to setup debug log for that particular community user. Refer here to understand more on how debugging works and how to set debug logs for any user: https://help.salesforce.com/articleView?id=code_add_users_debug_log.htm&type=5&sfdcIFrameOrigin=null

If you want to see all logs in Dev console directly then you have to uncheck show my current logs under debug menu. But it is not recommended because you will end up seeing multiple logs from all other traced users if you are using a sandbox which is used by other developers as well.

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.