1

We have an external site for our clients, and in that site faq section, when we try to use apex ActionFunction the site return unauthorized page.

We have tried everything here: ActionFunction on a Sites page with a guest login.

But it didn't work if we remove the actionfunctions and use remoteaction it works. The point is, we need the actionfunction due to context.

Some other things we've tried: in any page, we try to add the actionfunction it fails, even if the actionfunction is empty on salesforce controller.

The main difference is that the actionfunction is a component with it's own controller.

About profile: We gave permission on classes and pages alike on the site public profile.

Edit1: All our classes are global, all our pages and components have allowdml and also, the actionfunctions have the rerender. We tried without action region, with actionregion. As i said, it happens with any component we try to use apex:actionFunction

our current code:

<apex:component controller="Site_Suporte_Tecnico" allowdml="true">



    <div class="col-xs-12 no-padding suporte-tecnico-form">
        <div class="col-xs-5 padding-pattern text-content">
            <h2>Entre em contato</h2>
            <h3>Lorem ipsum dolor sit</h3>
            <p class="col-xs-12 no-padding">Lorem ipsum dolor sit amet, consectetur adipiscing elit. raesent nec turpis placerat, cursus purus sed, auctor dolor. Sed at luctus nunc. Sed vulputate porta nunc, sed maximus sapien posuere pellentesque. Aenean sed nulla enim.</p>
        </div>
        <div class="col-xs-7 padding-pattern text-content site-form">
            <apex:form id="theform">
                <apex:outputPanel id="chamado">
                    <input type="hidden" value="{!casoTratado.Id}" id="chamadoId" />
                    <span>
                        <apex:inputField id="tipo_objeto" value="{!casoTratado.Tipo_objeto__c}" styleClass="input-block-level col-xs-12"  >
                            <apex:actionSupport event="onchange" reRender="chamado"/>
                        </apex:inputField>
                    </span>
                    <apex:outputPanel rendered="{!(casoTratado.Tipo_objeto__c == 'Acessórios')}">

                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control" value="{!casoTratado.SuppliedCompany}" label="{!'Empresa'}" html-placeholder="Empresa" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.SuppliedName}" label="{!'Nome'}" html-placeholder="Nome do contato" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.SuppliedEmail}" label="{!'Empresa'}"  html-placeholder="Email" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.SuppliedPhone}" label="{!'Empresa'}"  html-placeholder="Telefone de contato (00 00000 00000)" required="true"/>
                        <apex:pageBlock>
                            <apex:variable value="{!0}" var="rowNum"/>

                        </apex:pageBlock>
                        <apex:inputTextarea  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.Description}" label="{!'Nome'}" html-placeholder="Descrição do problema" required="true"/>

                    </apex:outputPanel>
                    <apex:outputPanel rendered="{!(casoTratado.Tipo_objeto__c == 'Equipamentos')}">

                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control" value="{!casoTratado.SuppliedCompany}" label="{!'Empresa'}" html-placeholder="Empresa" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control" value="{!casoTratado.Endereco_fornecido__c}" label="{!'Empresa'}" html-placeholder="Endereço" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.SuppliedName}" label="{!'Nome'}" html-placeholder="Nome do contato" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.SuppliedEmail}" label="{!'Empresa'}"  html-placeholder="Email" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.SuppliedPhone}" label="{!'Empresa'}"  html-placeholder="Telefone de contato (00 00000 00000)" required="true"/>
                        <apex:pageBlock>
                            <apex:variable value="{!0}" var="rowNum"/>

                        </apex:pageBlock>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.Numero_NF__c}" label="{!'Nome'}" html-placeholder="Número da nota fiscal" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.Data_compra__c}" label="{!'Nome'}" html-placeholder="Data da compra" required="true"/>
                        <apex:inputTextarea  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.Description}" label="{!'Nome'}" html-placeholder="Descrição do problema" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.Rede_sistema_funcionamento__c}" label="{!'Nome'}" html-placeholder="Rede está funcionando?" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.Como_reproduzir_problema__c}" label="{!'Nome'}" html-placeholder="Como reproduzir o problema?" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.Versoes_HW_FW__c}" label="{!'Nome'}" html-placeholder="Versão do hardware e do firmware que reproduz o problema." required="true"/>

                    </apex:outputPanel>
                    <apex:outputPanel rendered="{!(casoTratado.Tipo_objeto__c == 'cabos')}">

                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control" value="{!casoTratado.SuppliedCompany}" label="{!'Empresa'}" html-placeholder="Empresa" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.SuppliedName}" label="{!'Nome'}" html-placeholder="Nome do contato" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.SuppliedEmail}" label="{!'Empresa'}"  html-placeholder="Email" required="true"/>
                        <apex:inputField  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.SuppliedPhone}" label="{!'Empresa'}"  html-placeholder="Telefone de contato (00 00000 00000)" required="true"/>
                        <apex:pageBlock>
                            <apex:variable value="{!0}" var="rowNum"/>

                        </apex:pageBlock>
                        <apex:inputTextarea  styleClass="col-xs-12 input-block-level telefone form-control"  value="{!casoTratado.Description}" label="{!'Nome'}" html-placeholder="Descrição do problema" required="true"/>

                    </apex:outputPanel>
                </apex:outputPanel>
                <apex:actionRegion>
                    <apex:actionFunction action="{!adicionaProduto}" name="addProduct"  reRender="chamado"/>
                    <apex:actionFunction action="{!renderPage}" name="renderPage" reRender="chamado" />
                    <apex:actionFunction action="{!removeProduto}" name="removeProduct" reRender="chamado" >
                        <apex:param name="index"   value="" assignTo="{!deletedIndex}" />
                    </apex:actionFunction>
                </apex:actionRegion>
                <input type="file" id="uploader" name="uploader" multiple="true" />
                <table id="table-upload" class="table table-striped">
                    <thead>
                        <tr>
                            <th>Arquivo</th>
                            <th>Tamanho</th>
                            <th>Status</th>
                        </tr>
                    </thead>
                    <tbody id="corpoFilesDescription">

                    </tbody>
                </table>
                <button type="button" onclick="saveTicket()" class="btn">Enviar</button>
                <div class="clear" />
            </apex:form>    

        </div>
    </div>
</div>

and our controller:

global class Site_Suporte_Tecnico {
global Case casoTratado { get; set;}
global List<Produto_chamado__c> produtos { get; set;}
global Integer deletedIndex {get; set;}
global Boolean saveSuccess {get; set;}

global Site_Suporte_Tecnico(){
    renderPage();
}

global void renderPage(){       
    casoTratado = new Case();
    produtos = new List<Produto_chamado__c>();
    produtos.add(new Produto_chamado__c());
    casoTratado.RecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByName().get('Suporte').getRecordTypeId();
}

global void adicionaProduto(){
    produtos.add(new Produto_chamado__c());
}

global void removeProduto(){
    produtos.remove(deletedIndex);
}

global void salvarChamado(){
    casoTratado.Origin = 'Web';
    upsert casoTratado;
    for(Produto_chamado__c p : produtos){
        p.Caso__c = casoTratado.Id;
    }
    if(produtos.size()>0) upsert produtos;
}
}
  • I could think of two things: 1. For the class, have you tried changing the sharing mode to without sharing. 2. And maybe try adding rerender to apex:actionFunction if its not added already. – Raul Jul 29 '17 at 1:45
  • thanks for your insight, we have both, and we seted the global keyword to the classes as well.. – Sergio Augusto Migueis - atile Jul 29 '17 at 14:13
  • For those of you who tries do this, the devil is in the details: Our case had a child relationship (products on the case) and this relationship is of type master detail. Any insert on a master-detail child, may count as a edit on the master. On our case it counted. I don't know why, through remote action it worked, but through action function, it seems the salesforce get the upsert and refuses access. – Sergio Augusto Migueis - atile Jul 30 '17 at 16:34

Your Answer

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

Browse other questions tagged or ask your own question.