• Nehashri
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies
Hi all,
I have been struggling this for a while. I have a simple component using Lightning Data Service which basically lists out accounts with Similar ratings on the Current Account page. It loads fine but when I edit the Account Rating on the same page, it doesnt update/refresh the Lightning Component. I tried using force:refresh event. It didnt work. I am not sure how can I use Custom events for this since the Save is standard. May be I am not handling the recordUpdated correctly.
here is my code:

SimilarRatingsController.js
({
	doInit : function(component, event, helper) {
        var eventParams = event.getParams();
        if(eventParams.changeType === "LOADED"){
            console.log('Record loaded');
        //get a list of accounts
        var action = component.get("c.getSimilarRatings");
        action.setParams({
            accrating: component.get("v.account.fields.Rating.value")
            
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if(component.isValid() && state === "SUCCESS"){
                var similarRatings = response.getReturnValue();
                console.log("Accounts "+similarRatings);
                var lenAccts = similarRatings.length;
                for(var i=0; i<lenAccts; i++){
                    console.log(similarRatings[i].Rating);
                }
            	component.set("v.similarRatings", similarRatings);
            }else{
                console.log("Failed with state :"+state);
				console.log("Component is :"+component);
            }
            
            
        });
        $A.enqueueAction(action);
        }else if(eventParams.changeType === "CHANGED"){
            console.log('Record updated');
            
        }
	}
})

SimilarRatings.cmp
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickActionWithoutHeader" access="global" controller="NearByAccount">
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="account" type="Account"/>
    <aura:attribute name="similarRatings" type="Object[]"/>


    
    <!--<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>-->
    <!--<aura:handler event="c:recordUpdated" action="{!c.doInit}"/>-->
    <force:recordData recordId="{!v.recordId}"
                      targetRecord="{!v.account}"
                      targetFields="{!v.simpleAccount}"
                      fields="Id, Name, Rating"
                      
                      recordUpdated="{!c.doInit}"/>
    <lightning:card iconName="standard:account" title="Similar Accounts" class="slds-is-relative">
        <div class="slds-p-left_medium slds-p-right_medium">
            <ul>
            <aura:if isTrue="{!v.nearbyAccounts.length &gt; 0}">
     			<aura:iteration items="{!v.similarRatings}" var="acc">
         			<li class="slds-list__item">
             			<c:NearByAccount account="{!acc}"/>
         			</li>
    	
    			</aura:iteration>
                <aura:set attribute="else">
                	<li class="slds-list__item">
                        <h3 class="slds-text-small slds-text-color_error">No nearby Accounts found.</h3>
                    </li>
                </aura:set>
            </aura:if>
            </ul>
        </div>
    </lightning:card>
</aura:component>
SimilarAccount.cmp
<aura:component >
    <aura:attribute name="account" type="Account"/>
    <!--<aura:registerEvent name="recordUpdated" type="c:recordUpdated"/>-->
    <lightning:recordViewForm aura:id="viewForm" recordId="{!v.account.Id}" objectApiName="Account">
        <div class="slds-tile__detail">
        <div class="slds-grid slds-grid_align-spread slds-has-flexi-truncate">
        	<a onclick="{!c.navToRecord}" >
            	<h3  class="slds-tile__title slds-truncate" title="Salesforce UX">
                
                    {!v.account.Name} 
                   
               
            	</h3>
            </a>
        </div>
    
    </div>
    </lightning:recordViewForm>
    
	
</aura:component>

SimilarAccount.js
({
	 navToRecord : function (component, event, helper) {
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": component.get("v.account.Id")
        });
        navEvt.fire();
	},
})
SimilarAccount
public with sharing class SimilarAccount {
   
    
    @AuraEnabled
    public static List<Account> getSimilarRatings(String accrating){
        System.debug('Rating '+accrating);
        List<Account> accList = [SELECT Id, Name, Rating FROM Account
                                WHERE Rating = :accrating];
        System.debug('Account '+accList);
        return accList;
    }

}





 
Hi all,
Here is my scenario. I need to give access to the users to children records B if they have access to the parent record A. A and B are in lookup relation. and the owner of A is not this user. Its an admin user. Does anyone have any code sample or starting point I can refer to(other than documentation)? I know it will be a trigger but the problem is the child record won't even exist when they have access to the parent record. The child records are created later,So  I can give access to child record on creation of child records but I am trying to figure out what happens when the user looses access to parent record, they shouldnt see child records either. 
Any help is highly appreciated.

Thank you
Hi,
I have a trigger on Attachment which prevents the user from deletingior updating the attachment if the parent custom Object Inventory status is marked as 'Final'. we are switching to lightning so I cant use Attachment anymore since they cant add attachments from the page. how can i write the same logic using Content file, how do i get the parent id?
Here is the logic of Attachment trigger:

Schema.DescribeSObjectResult inv = Inventory_Exception__c.sObjectType.getDescribe();
String invKeyPrefix = inv.getKeyPrefix();
if(trigger.isUpdate){
        for(Attachment a :trigger.new){
            if(invKeyPrefix == String.valueOf(a.parentId).left(3) &&
               [select status__c from Inventory_Exception__c where id = :a.parentId].status__c =='Final'){
                   a.adderror('This attachment could not be modified because this exception record is marked as Final.');
               }
        }


    if(trigger.isDelete){
        for(Attachment a :trigger.old){
            if(invKeyPrefix == String.valueOf(a.parentId).left(3) &&
               [select status__c from Inventory_Exception__c where id = :a.parentId].status__c =='Final'){
                   a.adderror('This attachment could not be deleted because this exception record is marked as Final.');
               }
        }
Hi all,
I have been struggling this for a while. I have a simple component using Lightning Data Service which basically lists out accounts with Similar ratings on the Current Account page. It loads fine but when I edit the Account Rating on the same page, it doesnt update/refresh the Lightning Component. I tried using force:refresh event. It didnt work. I am not sure how can I use Custom events for this since the Save is standard. May be I am not handling the recordUpdated correctly.
here is my code:

SimilarRatingsController.js
({
	doInit : function(component, event, helper) {
        var eventParams = event.getParams();
        if(eventParams.changeType === "LOADED"){
            console.log('Record loaded');
        //get a list of accounts
        var action = component.get("c.getSimilarRatings");
        action.setParams({
            accrating: component.get("v.account.fields.Rating.value")
            
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if(component.isValid() && state === "SUCCESS"){
                var similarRatings = response.getReturnValue();
                console.log("Accounts "+similarRatings);
                var lenAccts = similarRatings.length;
                for(var i=0; i<lenAccts; i++){
                    console.log(similarRatings[i].Rating);
                }
            	component.set("v.similarRatings", similarRatings);
            }else{
                console.log("Failed with state :"+state);
				console.log("Component is :"+component);
            }
            
            
        });
        $A.enqueueAction(action);
        }else if(eventParams.changeType === "CHANGED"){
            console.log('Record updated');
            
        }
	}
})

SimilarRatings.cmp
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickActionWithoutHeader" access="global" controller="NearByAccount">
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="account" type="Account"/>
    <aura:attribute name="similarRatings" type="Object[]"/>


    
    <!--<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>-->
    <!--<aura:handler event="c:recordUpdated" action="{!c.doInit}"/>-->
    <force:recordData recordId="{!v.recordId}"
                      targetRecord="{!v.account}"
                      targetFields="{!v.simpleAccount}"
                      fields="Id, Name, Rating"
                      
                      recordUpdated="{!c.doInit}"/>
    <lightning:card iconName="standard:account" title="Similar Accounts" class="slds-is-relative">
        <div class="slds-p-left_medium slds-p-right_medium">
            <ul>
            <aura:if isTrue="{!v.nearbyAccounts.length &gt; 0}">
     			<aura:iteration items="{!v.similarRatings}" var="acc">
         			<li class="slds-list__item">
             			<c:NearByAccount account="{!acc}"/>
         			</li>
    	
    			</aura:iteration>
                <aura:set attribute="else">
                	<li class="slds-list__item">
                        <h3 class="slds-text-small slds-text-color_error">No nearby Accounts found.</h3>
                    </li>
                </aura:set>
            </aura:if>
            </ul>
        </div>
    </lightning:card>
</aura:component>
SimilarAccount.cmp
<aura:component >
    <aura:attribute name="account" type="Account"/>
    <!--<aura:registerEvent name="recordUpdated" type="c:recordUpdated"/>-->
    <lightning:recordViewForm aura:id="viewForm" recordId="{!v.account.Id}" objectApiName="Account">
        <div class="slds-tile__detail">
        <div class="slds-grid slds-grid_align-spread slds-has-flexi-truncate">
        	<a onclick="{!c.navToRecord}" >
            	<h3  class="slds-tile__title slds-truncate" title="Salesforce UX">
                
                    {!v.account.Name} 
                   
               
            	</h3>
            </a>
        </div>
    
    </div>
    </lightning:recordViewForm>
    
	
</aura:component>

SimilarAccount.js
({
	 navToRecord : function (component, event, helper) {
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": component.get("v.account.Id")
        });
        navEvt.fire();
	},
})
SimilarAccount
public with sharing class SimilarAccount {
   
    
    @AuraEnabled
    public static List<Account> getSimilarRatings(String accrating){
        System.debug('Rating '+accrating);
        List<Account> accList = [SELECT Id, Name, Rating FROM Account
                                WHERE Rating = :accrating];
        System.debug('Account '+accList);
        return accList;
    }

}





 
Hi all,
Here is my scenario. I need to give access to the users to children records B if they have access to the parent record A. A and B are in lookup relation. and the owner of A is not this user. Its an admin user. Does anyone have any code sample or starting point I can refer to(other than documentation)? I know it will be a trigger but the problem is the child record won't even exist when they have access to the parent record. The child records are created later,So  I can give access to child record on creation of child records but I am trying to figure out what happens when the user looses access to parent record, they shouldnt see child records either. 
Any help is highly appreciated.

Thank you
I'm stuck on step #2 of Einstein Analytics and Discovery Insights Specialist superbadge.  I'm getting this warning while checking the challenge:
Challenge #2 Not complete
The step "Churn Tenure' is in compact form, so the filter values need to be specifed as a minimum and maximum
The static step that feeds has the following the value:
 
"Tenure_Length": {
                "broadcastFacet": false,
                "label": "Tenure Length",
                "selectMode": "single",
                "type": "staticflex",
                "values": [
                    {
                        "display": "High Risk",
                        "value": "1 to 12 months",
                        "min": 1,
                        "max": 12
                    },
                    ...
                ]
            }


I'm using selection binding for min and max values.  The dashboard is correctly filtering:
User-added image
User-added image
Any ideas? 
I've tried a non-compact form step where I inject a saql fragment into the query, as well as where I inject min/max values using a range filter serialization...All these efforts end in the same challenge failure message.

Any help/suggesitions are welcome!
Hi all,
I have been struggling this for a while. I have a simple component using Lightning Data Service which basically lists out accounts with Similar ratings on the Current Account page. It loads fine but when I edit the Account Rating on the same page, it doesnt update/refresh the Lightning Component. I tried using force:refresh event. It didnt work. I am not sure how can I use Custom events for this since the Save is standard. May be I am not handling the recordUpdated correctly.
here is my code:

SimilarRatingsController.js
({
	doInit : function(component, event, helper) {
        var eventParams = event.getParams();
        if(eventParams.changeType === "LOADED"){
            console.log('Record loaded');
        //get a list of accounts
        var action = component.get("c.getSimilarRatings");
        action.setParams({
            accrating: component.get("v.account.fields.Rating.value")
            
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if(component.isValid() && state === "SUCCESS"){
                var similarRatings = response.getReturnValue();
                console.log("Accounts "+similarRatings);
                var lenAccts = similarRatings.length;
                for(var i=0; i<lenAccts; i++){
                    console.log(similarRatings[i].Rating);
                }
            	component.set("v.similarRatings", similarRatings);
            }else{
                console.log("Failed with state :"+state);
				console.log("Component is :"+component);
            }
            
            
        });
        $A.enqueueAction(action);
        }else if(eventParams.changeType === "CHANGED"){
            console.log('Record updated');
            
        }
	}
})

SimilarRatings.cmp
<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickActionWithoutHeader" access="global" controller="NearByAccount">
    <aura:attribute name="recordId" type="Id"/>
    <aura:attribute name="account" type="Account"/>
    <aura:attribute name="similarRatings" type="Object[]"/>


    
    <!--<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>-->
    <!--<aura:handler event="c:recordUpdated" action="{!c.doInit}"/>-->
    <force:recordData recordId="{!v.recordId}"
                      targetRecord="{!v.account}"
                      targetFields="{!v.simpleAccount}"
                      fields="Id, Name, Rating"
                      
                      recordUpdated="{!c.doInit}"/>
    <lightning:card iconName="standard:account" title="Similar Accounts" class="slds-is-relative">
        <div class="slds-p-left_medium slds-p-right_medium">
            <ul>
            <aura:if isTrue="{!v.nearbyAccounts.length &gt; 0}">
     			<aura:iteration items="{!v.similarRatings}" var="acc">
         			<li class="slds-list__item">
             			<c:NearByAccount account="{!acc}"/>
         			</li>
    	
    			</aura:iteration>
                <aura:set attribute="else">
                	<li class="slds-list__item">
                        <h3 class="slds-text-small slds-text-color_error">No nearby Accounts found.</h3>
                    </li>
                </aura:set>
            </aura:if>
            </ul>
        </div>
    </lightning:card>
</aura:component>
SimilarAccount.cmp
<aura:component >
    <aura:attribute name="account" type="Account"/>
    <!--<aura:registerEvent name="recordUpdated" type="c:recordUpdated"/>-->
    <lightning:recordViewForm aura:id="viewForm" recordId="{!v.account.Id}" objectApiName="Account">
        <div class="slds-tile__detail">
        <div class="slds-grid slds-grid_align-spread slds-has-flexi-truncate">
        	<a onclick="{!c.navToRecord}" >
            	<h3  class="slds-tile__title slds-truncate" title="Salesforce UX">
                
                    {!v.account.Name} 
                   
               
            	</h3>
            </a>
        </div>
    
    </div>
    </lightning:recordViewForm>
    
	
</aura:component>

SimilarAccount.js
({
	 navToRecord : function (component, event, helper) {
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId": component.get("v.account.Id")
        });
        navEvt.fire();
	},
})
SimilarAccount
public with sharing class SimilarAccount {
   
    
    @AuraEnabled
    public static List<Account> getSimilarRatings(String accrating){
        System.debug('Rating '+accrating);
        List<Account> accList = [SELECT Id, Name, Rating FROM Account
                                WHERE Rating = :accrating];
        System.debug('Account '+accList);
        return accList;
    }

}





 
Hi,
I have a trigger on Attachment which prevents the user from deletingior updating the attachment if the parent custom Object Inventory status is marked as 'Final'. we are switching to lightning so I cant use Attachment anymore since they cant add attachments from the page. how can i write the same logic using Content file, how do i get the parent id?
Here is the logic of Attachment trigger:

Schema.DescribeSObjectResult inv = Inventory_Exception__c.sObjectType.getDescribe();
String invKeyPrefix = inv.getKeyPrefix();
if(trigger.isUpdate){
        for(Attachment a :trigger.new){
            if(invKeyPrefix == String.valueOf(a.parentId).left(3) &&
               [select status__c from Inventory_Exception__c where id = :a.parentId].status__c =='Final'){
                   a.adderror('This attachment could not be modified because this exception record is marked as Final.');
               }
        }


    if(trigger.isDelete){
        for(Attachment a :trigger.old){
            if(invKeyPrefix == String.valueOf(a.parentId).left(3) &&
               [select status__c from Inventory_Exception__c where id = :a.parentId].status__c =='Final'){
                   a.adderror('This attachment could not be deleted because this exception record is marked as Final.');
               }
        }
I am implementing lightning design system and bootstrap at the same time in lightning component, But unable to get the desired UI in responsive mode. 
Can i use both in lightning component.