• Aryan_SFDC
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Hi,

I have a aura component and added it ti quick action button.
I want it to be accessible only to users having certain permission set or custom permission.
else when user click on it it should throw an error saying "you are not authorized".
I have written logic in apex class "createQuickContactController" method checkCustomPermission.
but not sure how to add this logic in aura component and controller.
any suggestions will be much appreciated.

component:
<aura:component controller="createQuickContactController"
                implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickActionWithoutHeader" 
                access="global">

    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="Name" type="String"/>
    <aura:attribute name="account" type="Account"/>
    <aura:attribute name="contact" type="Contact" 
   default="{ 'sobjectType': 'Contact','MailingCountry':'Brazil'}"/>
  
   <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <lightning:recordEditForm aura:id="recordEditForm"
                              objectApiName="Contact"
                             >
    <lightning:messages /> 
        <div class="slds-grid">
        <div class="slds-col slds-size_1-of-2">
        <lightning:inputField fieldName="LastName" value="{!v.contact.LastName}"/>
        <lightning:inputField fieldName="AccountId" value="{!v.recordId}"/>
        <lightning:inputField fieldName="MailingCountry" value="{!v.contact.MailingCountry}"/>
        <lightning:inputField fieldName="MailingState" value="{!v.contact.MailingState}"/>
        <lightning:inputField fieldName="MailingCity" value="{!v.contact.MailingCity}"/>
        <lightning:inputField fieldName="MailingStreet" value="{!v.contact.MailingStreet}"/>
        <lightning:inputField fieldName="MailingPostalCode" value="{!v.contact.MailingPostalCode}"/>
          </div>
        </div>
        </lightning:recordEditForm>
    
        
    <lightning:button class="slds-m-top_small" type="cancel" label="Cancel" onclick="{!c.handleCancel}"/> 
    <lightning:button aura:id="insert" label="Save" class="slds-m-top_small" onclick="{!c.InsertCont}"/>
</aura:component>


Controller:
({    
        doInit : function(component, event, helper) {
        var accid = component.get("v.recordId");
        component.set("v.contact.AccountId",component.get("v.recordId"));
        var action=component.get("c.getAccount");
        action.setParams({
            acid : component.get("v.recordId")            
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS"){
                component.set("v.account",response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
        
    },
    
    
    InsertCont: function(component) {
        var action=component.get("c.insertCon");
        action.setParams({ newcon: component.get("v.contact") });  
        action.setCallback(this, function(response) {
            
            let state = response.getState(); 
            console.log(response.getReturnValue());
            if ( state === "SUCCESS" ) {  
                
                $A.get("e.force:closeQuickAction").fire();  
                $A.get('e.force:refreshView').fire();   
                
            }  else {
                
                let showToast = $A.get( "e.force:showToast" );
                showToast.setParams({
                    title : 'Testing Toast!!!',
                    message : 'Record Not Saved due to error.' ,
                    type : 'error',
                    mode : 'sticky',
                    message : 'Some error occured'
                });
                showToast.fire();
                
            }
        });  
        $A.enqueueAction( action );         
        
    },
    handleCancel: function(cmp, event, helper) {
        $A.get("e.force:closeQuickAction").fire();
    }

})


Apex class:

public class createQuickContactController
{
@AuraEnabled
    public static contact insertCon(Contact newcon)
    {
        System.debug(newcon);
        insert newcon;
        return newcon;        
    }
    @AuraEnabled
    public static Account getAccount(string acid)
    {
        Account acc = [select id,BillingCity,BillingCountry,BillingStreet,BillingState,BillingPostalCode,name from Account where Id =:acid];
        return acc;
    }
    @AuraEnabled
    public static Boolean checkCustomPermission(Boolean custpermission){
    Boolean hasCustomPermission = FeatureManagement.checkPermission('Create_Quick_Contact');
    return hasCustomPermission;
    }
Hi,
I am trying to make conact creation easy by populating default field while creating the 
contact(not to insert default values after creation of the record) for 2 specific users.
Steps:
1.Open account.
2.go to related list named as contact.
3.Click on new contact.
4.On this screen,field should be populated by default while creating the contact.
Account name = It will display account name of related account.
mailing country(text field)= India (this should be visible to user by default but if he want then he should able to enter the another country name)
Mailing region(picklist) = Asia pacific(this should be visible to user by default but if he want then he should able to select another picklist value)
Language(picklist) = English (this should be visible to user by default but if he want then he should able to select another picklist value)
Please suggest me how to implement this change.
I need this changes for 2 users only having same profile.
I am trying this in salesforce lightning
Hi,

I am trying to auto populate default fields while creating the contact.
e.g Mailing region, country.
When users select new contact from account then default values should be populated.
also users should be able to chage the picklist values if they want.
Any suggestions how can I implement this logic.
I want to implement it for 2 users.
Thanks in advance
Hi,
I am trying to make conact creation easy by populating default field while creating the 
contact(not to insert default values after creation of the record) for 2 specific users.
Steps:
1.Open account.
2.go to related list named as contact.
3.Click on new contact.
4.On this screen,field should be populated by default while creating the contact.
Account name = It will display account name of related account.
mailing country(text field)= India (this should be visible to user by default but if he want then he should able to enter the another country name)
Mailing region(picklist) = Asia pacific(this should be visible to user by default but if he want then he should able to select another picklist value)
Language(picklist) = English (this should be visible to user by default but if he want then he should able to select another picklist value)
Please suggest me how to implement this change.
I need this changes for 2 users only having same profile.
I am trying this in salesforce lightning
Hi,

I am trying to auto populate default fields while creating the contact.
e.g Mailing region, country.
When users select new contact from account then default values should be populated.
also users should be able to chage the picklist values if they want.
Any suggestions how can I implement this logic.
I want to implement it for 2 users.
Thanks in advance