• Tom Dawson
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 6
    Replies
Hi All

I'm tyring to pass a variable through a URL, however whenever i append my variable onto the end of my URL and hit enter, it removes the variable from the end. For example:

This is the URL i would like to use:
https://my-org.force.com/lightning/n/Create_New_SNP_Record?recordId=12345
Here, the variable is recordId and the value is 12345

After hitting enter, the URL becomes this:
https://my-org.force.com/lightning/n/Create_New_SNP_Record

Has anyone had this happen to them before? If so, any help would be appreciated!

Thanks

Tom
Hi All

I'm trying to access field values from an object related to the initial one in the call. Our relationship is as follows:

Contact --> Post Fulfillment --> Post

I am trying to use an iteration to get values from Post when the initial call is to Contact. See code below:

Apex:
@AuraEnabled
    public static List<Contact> getHSList(){
        List<Contact> myHSList = new List<Contact>();
        myHSList = [Select Id, 
                    Name, 
                    Fire_Warden__c,
                    Phone,
                    (SELECT id, Post__c,Post__r.Area__c, Post__r.Floor__c, Post__r.Section__c
                     FROM Contact.Post_Fulfillments__r)
                    From Contact
                    Where Fire_Warden__c = true];
        return myHSList;
    }
Controller
({
    onInit : function(component, event, helper) {
        
        console.log('onInit');
        
        var action = component.get("c.getHSList");
        
        action.setCallback(this, function(a) {
            
            var HandSData = a.getReturnValue();
            console.log(HandSData);
            component.set("v.contactList",HandSData);
            console.log(HandSData.length);
            
        });
        $A.enqueueAction(action);
    }
    
})
Component
<aura:Iteration items="{!v.contactList}" var="con" >
                <tr class="slds-hint-parent">
                    <th data-label="Name" scope="row">
                        <div class="slds-truncate" title="Cloudhub">{!con.Name}</div>
                    </th>
                    <td data-label="Phone">
                        <div class="slds-truncate" title="Cloudhub">{!con.Phone}</div>
                    </td>
                    <td data-label="Close Date">
                        <div class="slds-truncate" title="4/14/2015">{!con.Post_Fulfillments__r.Post__r.Floor__c} place</div>
                    </td>
                </tr>
            </aura:Iteration>

I am able to access both Name and Phone from the contact. I can also see from the Chrome inspector that the field values for Location are coming through, I just cannot access them. 

As you can see i have tried 
{!con.Post_Fulfillments__r.Post__r.Floor__c}
But it doesnt seem to work.

Any help would be great.

Thanks

Tom 


 
Hi All

I have wirrten a small Apex trigger to stop chatter group members from leaving a group, based on the permissions of the gorup which are set in a record in the custom object Chatter_Groups__c. Whenever a new chatter group is created, a record is automatically created in this custom object with the necessary fields. 

My trigger is working as intended:
trigger disableChatterDelete on CollaborationGroupMember (before delete) {
    
    List<Chatter__c> chatterGroups = [SELECT Id,
                                      Name, 
                                      Chatter_Group_Id__c,
                                      Allowed_to_leave__c
                                      FROM Chatter__c];
    
    Id userProfileId = userinfo.getProfileId();
    String userProfileName = [SELECT ID, Name from Profile Where Id = : userProfileId].Name;
    
    for(CollaborationGroupMember collab : Trigger.Old){
        
        integer index;
        for(integer i = 0; i < chatterGroups.size();i++){
            if(collab.CollaborationGroupId == chatterGroups[i].Chatter_Group_Id__c) index = i;
        }
        
        if(chatterGroups[index].Allowed_to_leave__c == false){
            
            if(chatterGroups[index].Chatter_Group_Id__c == collab.CollaborationGroupId){
                
                if(userProfileName != 'System Administrator'){
                    
                    if(Trigger.isBefore){
                        
                        if(Trigger.isDelete){
                            
                            collab.adderror('This Group is mandatory for all staff');
                        }
                    }
                }
            }
        }
    }
}
This is my test class:
@isTest
public class disableChatterDeleteTest {
    
    static testMethod void testDisableChatterDeleter(){
        
        // Create a unique UserName
        String uniqueUserName = 'salesuser' + DateTime.now().getTime() + '@testorg.com';
        // This code runs as the system user
        Profile p = [SELECT Id FROM Profile WHERE Name='SADC Employee'];
        
        Test.startTest(); 
        User usr = new User(Alias = 'suser', Email='user@testorg.com',
                            EmailEncodingKey='UTF-8', LastName='SalesTesting', LanguageLocaleKey='en_US',
                            LocaleSidKey='en_US', ProfileId = p.Id,
                            TimeZoneSidKey='America/New_York',
                            UserName=uniqueUserName);
        
        // Create new Chatter Group
        CollaborationGroup grp = new CollaborationGroup();
        grp.Name = 'Test Group';
        grp.CollaborationType = 'Public';
        insert grp;
        
        //Create new Chatter Group record
        Chatter__c grpRec = new Chatter__c();
        grpRec.Name = 'Test Group Record';
        grpRec.Chatter_Group_Id__c = grp.Id;
        grpRec.Allowed_to_leave__c = false;
        
        // Create new group member
        CollaborationGroupMember grpMem = new CollaborationGroupMember();
        grpMem.MemberId = usr.Id;
        grpMem.CollaborationGroupId = grp.Id;
        
        System.runAs(usr){
            
            try{
                delete grpMem;
            }catch(Exception ex){
                system.debug('Exception');
            }
            Test.stopTest(); 
            
            List<CollaborationGroup> groupList = [SELECT Id, MemberCount
                                                  FROM CollaborationGroup 
                                                 Where Id = : grp.Id];
            System.assertEquals(groupList[0].MemberCount, 1 );
        }
    }
}

Running this test class does not result in an error, but i have 0 code coverage. If anyone could tell me where i am going wrong it would be much appreciated!

Thanks

Tom 
 
Hi All

I have a problem at the moment where i am trying to access a variable in the controller which i am creating in APEX but i cannot pull it through. Any suggestions would be great!

APEX
@AuraEnabled
    public static Senior_Parking_Permit__c checkPermit(String permitNumber){
        system.debug('Hit the server');
        system.debug(permitNumber);
        
        User currUser = getCurrPortalUser();
        system.debug('currUser =  ' + currUser );
         
        if (currUser.ContactId == null ) return null;
        
        List<Senior_Parking_Permit__c> foundPermits = [SELECT Id, Name, Permit_Number__c, Claimed__c FROM Senior_Parking_Permit__c 
                                                               WHERE Permit_Number__c = :permitNumber
                                                               LIMIT 1];
        
        if(foundPermits.size() == 0) {
            system.debug('Could not find any matching Senior_Parking_Permit__c rec, do nothing ');
            
            return null;
        }
        else{
            Senior_Parking_Permit__c foundPermit = foundPermits[0];
            
            if(foundPermit.Claimed__c == true){
                
                Boolean Claimed = true;
            }
            else {
                Boolean Claimed = false;
            }
            
            system.debug('Found a Senior_Parking_Permit__c record - ' + foundPermit);
            system.debug('... and it hasnt been claimed yet, lets claim it. ');
            
            foundPermit.Claimed__c = true;
            system.debug('Before update foundPermit  - ' + foundPermit);
            
            update foundPermit;
            return foundPermit;
        }
    }

Controller
permitClaim : function(component, event, helper){
        var action = component.get("c.checkPermit");
        var permitNumber = component.get("v.simpleNewCase.Permit_Number__c");
        
        console.log("permitNumber",permitNumber);
        
        action.setParams({
            permitNumber : permitNumber
        });
        
        action.setCallback(this, function(a) {
            
            var state = a.getState();
            console.log("State",state);
            var permitData = a.getReturnValue(); 
            console.log("permitData",permitData);
            
            if(permitData === null){
                debugger;
                var permitNotFound = true;
                component.set("v.permitNotFound",true);
                console.log(permitNotFound);
            }
            
            if(a.getState() === 'SUCCESS'){
                
                if(permitData != null){
                    debugger;
                component.set("v.foundPermit",permitData.Permit_Number__c);
                component.set("v.permitClaimed",permitData.Claimed);
                    
                var permitFound = component.get("v.foundPermit");
                console.log("permitNumber",permitNumber);
                    
                var permitClaimed = component.get("v.permitClaimed");
                console.log("permitClaimed",permitClaimed);
                    
                var permitNotFound = false;
                component.set("v.permitNotFound",false);
                console.log(permitNotFound);
                    
                }
                
                if((permitFound == permitNumber) && (permitClaimed === false)){
                    var showToast = $A.get("e.force:showToast");
                    console.log("showToast")
                    showToast.setParams({
                        "title": "Permit Found",
                        "type" :"Success",
                        "message": "Your existing parking permit has been found."
                    });
                    showToast.fire();
                } else if ((permitFound == permitNumber) && (permitClaimed === true)){
                    
                    var showToast = $A.get("e.force:showToast");
                    console.log("showToast")
                    showToast.setParams({
                        "title": "Permit Already Claimed",
                        "type" :"error",
                        "message": "The parking permit number you have selected has already been claimed. If this has been claimed incorrectly, please contact Customer Services."
                    });
                    showToast.fire();
                } else if(permitNotFound === true){
                    var showToast = $A.get("e.force:showToast");
                    console.log("showToast")
                    showToast.setParams({
                        "title": "Permit Not Found",
                        "type" :"error",
                        "message": "The parking permit number you have entered has not been recognised. Please try again."
                    });
                    showToast.fire();
                }
            }
            
        });
        $A.enqueueAction(action);
    }
I am trying to get the attribute 'Claimed' to appear with a simple true or false but cant get it to work. 

Thanks for your help!

Tom 
 
Hi,

We are trying to use the lightning:map component in the context of a case. For example, a member of our community can currently drop a pin on a map when reporting something, but we would like to display the location of that report on a case/record detail page that can be viewed after the customer has submitted their report. 

We are trying to use the force record data function to pull in the information about the case, but when we do the map does not display. 

Is anyone able to help us get this working?

Thanks,

Tom 
Hi All

I'm trying to access field values from an object related to the initial one in the call. Our relationship is as follows:

Contact --> Post Fulfillment --> Post

I am trying to use an iteration to get values from Post when the initial call is to Contact. See code below:

Apex:
@AuraEnabled
    public static List<Contact> getHSList(){
        List<Contact> myHSList = new List<Contact>();
        myHSList = [Select Id, 
                    Name, 
                    Fire_Warden__c,
                    Phone,
                    (SELECT id, Post__c,Post__r.Area__c, Post__r.Floor__c, Post__r.Section__c
                     FROM Contact.Post_Fulfillments__r)
                    From Contact
                    Where Fire_Warden__c = true];
        return myHSList;
    }
Controller
({
    onInit : function(component, event, helper) {
        
        console.log('onInit');
        
        var action = component.get("c.getHSList");
        
        action.setCallback(this, function(a) {
            
            var HandSData = a.getReturnValue();
            console.log(HandSData);
            component.set("v.contactList",HandSData);
            console.log(HandSData.length);
            
        });
        $A.enqueueAction(action);
    }
    
})
Component
<aura:Iteration items="{!v.contactList}" var="con" >
                <tr class="slds-hint-parent">
                    <th data-label="Name" scope="row">
                        <div class="slds-truncate" title="Cloudhub">{!con.Name}</div>
                    </th>
                    <td data-label="Phone">
                        <div class="slds-truncate" title="Cloudhub">{!con.Phone}</div>
                    </td>
                    <td data-label="Close Date">
                        <div class="slds-truncate" title="4/14/2015">{!con.Post_Fulfillments__r.Post__r.Floor__c} place</div>
                    </td>
                </tr>
            </aura:Iteration>

I am able to access both Name and Phone from the contact. I can also see from the Chrome inspector that the field values for Location are coming through, I just cannot access them. 

As you can see i have tried 
{!con.Post_Fulfillments__r.Post__r.Floor__c}
But it doesnt seem to work.

Any help would be great.

Thanks

Tom 


 
Hi All

I have wirrten a small Apex trigger to stop chatter group members from leaving a group, based on the permissions of the gorup which are set in a record in the custom object Chatter_Groups__c. Whenever a new chatter group is created, a record is automatically created in this custom object with the necessary fields. 

My trigger is working as intended:
trigger disableChatterDelete on CollaborationGroupMember (before delete) {
    
    List<Chatter__c> chatterGroups = [SELECT Id,
                                      Name, 
                                      Chatter_Group_Id__c,
                                      Allowed_to_leave__c
                                      FROM Chatter__c];
    
    Id userProfileId = userinfo.getProfileId();
    String userProfileName = [SELECT ID, Name from Profile Where Id = : userProfileId].Name;
    
    for(CollaborationGroupMember collab : Trigger.Old){
        
        integer index;
        for(integer i = 0; i < chatterGroups.size();i++){
            if(collab.CollaborationGroupId == chatterGroups[i].Chatter_Group_Id__c) index = i;
        }
        
        if(chatterGroups[index].Allowed_to_leave__c == false){
            
            if(chatterGroups[index].Chatter_Group_Id__c == collab.CollaborationGroupId){
                
                if(userProfileName != 'System Administrator'){
                    
                    if(Trigger.isBefore){
                        
                        if(Trigger.isDelete){
                            
                            collab.adderror('This Group is mandatory for all staff');
                        }
                    }
                }
            }
        }
    }
}
This is my test class:
@isTest
public class disableChatterDeleteTest {
    
    static testMethod void testDisableChatterDeleter(){
        
        // Create a unique UserName
        String uniqueUserName = 'salesuser' + DateTime.now().getTime() + '@testorg.com';
        // This code runs as the system user
        Profile p = [SELECT Id FROM Profile WHERE Name='SADC Employee'];
        
        Test.startTest(); 
        User usr = new User(Alias = 'suser', Email='user@testorg.com',
                            EmailEncodingKey='UTF-8', LastName='SalesTesting', LanguageLocaleKey='en_US',
                            LocaleSidKey='en_US', ProfileId = p.Id,
                            TimeZoneSidKey='America/New_York',
                            UserName=uniqueUserName);
        
        // Create new Chatter Group
        CollaborationGroup grp = new CollaborationGroup();
        grp.Name = 'Test Group';
        grp.CollaborationType = 'Public';
        insert grp;
        
        //Create new Chatter Group record
        Chatter__c grpRec = new Chatter__c();
        grpRec.Name = 'Test Group Record';
        grpRec.Chatter_Group_Id__c = grp.Id;
        grpRec.Allowed_to_leave__c = false;
        
        // Create new group member
        CollaborationGroupMember grpMem = new CollaborationGroupMember();
        grpMem.MemberId = usr.Id;
        grpMem.CollaborationGroupId = grp.Id;
        
        System.runAs(usr){
            
            try{
                delete grpMem;
            }catch(Exception ex){
                system.debug('Exception');
            }
            Test.stopTest(); 
            
            List<CollaborationGroup> groupList = [SELECT Id, MemberCount
                                                  FROM CollaborationGroup 
                                                 Where Id = : grp.Id];
            System.assertEquals(groupList[0].MemberCount, 1 );
        }
    }
}

Running this test class does not result in an error, but i have 0 code coverage. If anyone could tell me where i am going wrong it would be much appreciated!

Thanks

Tom 
 
Hi All

I have a problem at the moment where i am trying to access a variable in the controller which i am creating in APEX but i cannot pull it through. Any suggestions would be great!

APEX
@AuraEnabled
    public static Senior_Parking_Permit__c checkPermit(String permitNumber){
        system.debug('Hit the server');
        system.debug(permitNumber);
        
        User currUser = getCurrPortalUser();
        system.debug('currUser =  ' + currUser );
         
        if (currUser.ContactId == null ) return null;
        
        List<Senior_Parking_Permit__c> foundPermits = [SELECT Id, Name, Permit_Number__c, Claimed__c FROM Senior_Parking_Permit__c 
                                                               WHERE Permit_Number__c = :permitNumber
                                                               LIMIT 1];
        
        if(foundPermits.size() == 0) {
            system.debug('Could not find any matching Senior_Parking_Permit__c rec, do nothing ');
            
            return null;
        }
        else{
            Senior_Parking_Permit__c foundPermit = foundPermits[0];
            
            if(foundPermit.Claimed__c == true){
                
                Boolean Claimed = true;
            }
            else {
                Boolean Claimed = false;
            }
            
            system.debug('Found a Senior_Parking_Permit__c record - ' + foundPermit);
            system.debug('... and it hasnt been claimed yet, lets claim it. ');
            
            foundPermit.Claimed__c = true;
            system.debug('Before update foundPermit  - ' + foundPermit);
            
            update foundPermit;
            return foundPermit;
        }
    }

Controller
permitClaim : function(component, event, helper){
        var action = component.get("c.checkPermit");
        var permitNumber = component.get("v.simpleNewCase.Permit_Number__c");
        
        console.log("permitNumber",permitNumber);
        
        action.setParams({
            permitNumber : permitNumber
        });
        
        action.setCallback(this, function(a) {
            
            var state = a.getState();
            console.log("State",state);
            var permitData = a.getReturnValue(); 
            console.log("permitData",permitData);
            
            if(permitData === null){
                debugger;
                var permitNotFound = true;
                component.set("v.permitNotFound",true);
                console.log(permitNotFound);
            }
            
            if(a.getState() === 'SUCCESS'){
                
                if(permitData != null){
                    debugger;
                component.set("v.foundPermit",permitData.Permit_Number__c);
                component.set("v.permitClaimed",permitData.Claimed);
                    
                var permitFound = component.get("v.foundPermit");
                console.log("permitNumber",permitNumber);
                    
                var permitClaimed = component.get("v.permitClaimed");
                console.log("permitClaimed",permitClaimed);
                    
                var permitNotFound = false;
                component.set("v.permitNotFound",false);
                console.log(permitNotFound);
                    
                }
                
                if((permitFound == permitNumber) && (permitClaimed === false)){
                    var showToast = $A.get("e.force:showToast");
                    console.log("showToast")
                    showToast.setParams({
                        "title": "Permit Found",
                        "type" :"Success",
                        "message": "Your existing parking permit has been found."
                    });
                    showToast.fire();
                } else if ((permitFound == permitNumber) && (permitClaimed === true)){
                    
                    var showToast = $A.get("e.force:showToast");
                    console.log("showToast")
                    showToast.setParams({
                        "title": "Permit Already Claimed",
                        "type" :"error",
                        "message": "The parking permit number you have selected has already been claimed. If this has been claimed incorrectly, please contact Customer Services."
                    });
                    showToast.fire();
                } else if(permitNotFound === true){
                    var showToast = $A.get("e.force:showToast");
                    console.log("showToast")
                    showToast.setParams({
                        "title": "Permit Not Found",
                        "type" :"error",
                        "message": "The parking permit number you have entered has not been recognised. Please try again."
                    });
                    showToast.fire();
                }
            }
            
        });
        $A.enqueueAction(action);
    }
I am trying to get the attribute 'Claimed' to appear with a simple true or false but cant get it to work. 

Thanks for your help!

Tom