• simon chao
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 4
    Likes Received
  • 0
    Likes Given
  • 19
    Questions
  • 34
    Replies
Hi,

I am having trouble populating the value of a lookup field. I have objects A, B and C. 

B have a master deatil relationship with A and a regular lookup to C.
the master-detail field automatically populates, so I don't have to worry about that. However, I am having trouble populating the regular lookup field on object B.

I tried setting the Id to that field but it comes up as blank. Inserting the name will return a error as the field only takes in Id. Any idea as in why it returns blank even though I set a Id to the lookup field? 

Thanks. 
Hi,

I currently have a community. When a user signs up, a contact is created. All new user gets put into the same Account and uses the same Profile. 

I have a criteria, where a user can ONLY view applications that they create. Currently, a new user can see applications previously made by another user. 

How can I restrict this? Do I do this within the controller? Or within the lightning component? Any help is greatly appreaciated. 
This is a follow up question to my previous question
https://developer.salesforce.com/forums/ForumsMain?id=9062I000000g59RQAQ

I figured out how to download a text via an text file with a button. 

Instead of pressing a button and download the file, I want to press the button and have it automatically attach it to my current records Files (AttachedContentDocuments) within my Related List.

Is this possible? I am doing this in lightning. So far I haven't found anything online that points me in the right direction? Any help is appreciated, thank you. 

 
Hi ,

I am quite new to this lightning experience thing. I am just wondering if it is possible to create an attachment or somesort of text file when a user click on a lightning action button. This text file will consists of a small paragraph which consists custom fields from the object. I did some research and it says that attachment is no longer available for the lightning experience? If that is the case, how can i approach this? 
I have written the below controller class. Was wondering how to write a bulk test for it. any suggestions? Are there good guides out there that teaches how to write test class? Besides for the trailhead module?
 
public with sharing class newStudent { 
@AuraEnabled 
public static Contact getStudent(Id stuId) { 
     Contact stu = [ 
                     SELECT Id, Name, Gender__c, School__c 
                     ( 
                        SELECT class_id__c, class_teacher__r.Name, class_subject__c FROM class__r 
                     )
                     FROM Contact WHERE Id =: stuId ]; 
     return stu; 
} 

//https://developer.salesforce.com/blogs/developer-relations/2015/11/create-lightning-component-drag-drop-profile-pictures.html 

@AuraEnabled 
public static Attachment studentPicture (Id stuId) { 
     if (!Schema.sObjectType.Contact.isAccessible()) { 
          throw new System.NoAccessException(); 
     } 
     List<Attachment> lAttachment = new List<Attachment>(
          [
               SELECT Id, Name, LastModifiedDate, ContentType FROM Attachment 
               WHERE parentid=:stuId AND ContentType IN ('image/png', 'image/jpeg', 'image/gif') 
               ORDER BY LastModifiedDate DESC LIMIT 1
          ]
     ); 
     return lAttachment.size() > 0 ? lAttachment[0] : null; 
} 
    @AuraEnabled
    public static Id saveAttachment(Id parentId, String fileName, String base64Data, String contentType) {
        if (!Schema.sObjectType.Contact.isUpdateable()) {
            throw new System.NoAccessException();
        }
        Attachment attachment = new Attachment();
        attachment.parentId = parentId;
        attachment.body = EncodingUtil.base64Decode(base64Data);
        attachment.name = fileName;
        attachment.contentType = contentType;
        insert attachment;
        return attachment.id;
    }
}
is it possible to create a lightning component within the contacts page layout that allows the user to upload a picture of themselves? 
Hi, 
for some reason within lightning component, if I have 
<ui:inputNumber format="#,###" aura:id="numbers" value="{!v.company.Salary__c}" />
on the Front End, if I input 0 within this field, it will blank out. And in the backend, it will not store 0, it will just store as blank. 
Is there a way that I can get SF to store the 0?

I been thinking of doing a event listener that listens when a user press on 0, 
window.addEventListener("keydown", function(event) {
          alert("key: " + event.key + ", code: " + event.code);
        }, true);
and when the user presses 0 and the user is within that aura:id="numbers" inputNumber field, I can set the company__Salary__c value  to 0 within the backend, so even if the front end displays blank, the backend will store a 0 value. Is that possible? How would one approach that? 

Most importantly, is there any way for the 0 to stay on the front end and not have it dissapear? Online says that 0 is not considered a number, to get it to show on the front end, change inputnumber to just input text field. But I do not want that.

Also, I do not want to use lighting:input type="number", as it doesn't round. Some say you can do the step attribute, but on the front end it doesn't actually change the number. It will display the rounded number, but the backend still saves the decimal number, which is not what i want. 

Any help is greatly appreciated, thank you. 
Is is possible to filter out a query list so I only get the highest one? For example, I would like to  query a students name and his exam mark. And I only want to grab the student with the highest exam mark.  (student__c is a child of class__c)
Select (Select Student_Name__c, Exam_Mark__c from Student__r ORDER BY Exam_Mark__c ASC) from class__c
This grabs all the students and it doesn't sort out the exam marks from highest to lowest. I know I can add a limit 1 to grab only the top value, but how can I gaurantee that the first query value that I am grabbing is the highest? 
 

I want to set a parent field to a children field, is that possible? 
I have a class__c (parent) within it, I have a student__c (children). The relationship between them is one to many. There can be many students within a class. 

Within the class__c I have a custom field, StarPupil__c, and I want to set a student name to that field. Is that possible? Do I have to query the field or can I just assign it? 

 

List<Class__c> tempClass = new List<Class>();

//First I want to check if class object have any students, if not I set the starPupil field to blank 

if( tempClass.student__r.size() == 0 )
{
     tempClass.starPupil__c = ' ';
}
// then i check to see if starpupil is equal to student name if not i set it to student name 
else
{
     if(tempClass.starPupil__c  != tempClass.student__r.studentName__c)
     {
          tempClass.starPupil__c = tempClass.student__r.studentName__c;
     }
}
The above code does not work as it seems that I cannot add the .studentName__c after student__r within the if statement inside the else statement. How should I approach this? 
I am having difficulty getting the following code to work. Any insights? 

Within my lightning component i have: 
<div>Number Test</div>
<ui:inputNumber class="slds-input" format="#,###" aura:id="testNumber" value="{!v.testNumber}" keyup="{!c.keyupAction}" updateOn="keyup" />

Within my controller i have:
testNumber: function(component, event, helper)
    {
        var x = component.find("testNumber").getElement();
        if(x.value =='0')
        {
            x.value = '0';
        }
    }
The code saves, but it doesn't work. Right now I have a number input field, but when I input 0, JS somehow clears it, any other input number will stay on the front end, but as soon as you enter a 0 and navigate away from the input field, the 0 gets cleared. Is there a way that I can get the 0 to stay on the front end? It needs to be in an input number field and not input text. 
I am wondering how I can come about this trigger.

I want to write a before insert trigger that fires whenever a new benefit record is created. It will take in value from a look up object, company__c, 
and prepopulate its custom fields medical_location__c, date_of_subscription__c and medical_description__c field and stamp it on the benefit form. Any help on how I can go about this?
I am having trouble writing a test class for the below controller. 
public class fetchPicklistOptsController {
 @AuraEnabled
 public static List < String > getselectOptions(sObject objObject, string fld) {
  system.debug('objObject --->' + objObject);
  system.debug('fld --->' + fld);
  List < String > allOpts = new list < String > ();
  // Get the object type of the SObject.
  Schema.sObjectType objType = objObject.getSObjectType();
 
  // Describe the SObject using its object type.
  Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
 
  // Get a map of fields for the SObject
  map < String, Schema.SObjectField > fieldMap = objDescribe.fields.getMap();
 
  // Get the list of picklist values for this field.
  list < Schema.PicklistEntry > values =
   fieldMap.get(fld).getDescribe().getPickListValues();
 
  // Add these values to the selectoption list.
  for (Schema.PicklistEntry a: values) {
   allOpts.add(a.getValue());
  }
  system.debug('allOpts ---->' + allOpts);
  allOpts.sort();
  return allOpts;
 }
}

 
Hi there, Currently I have a formstack page. Within I see that I can add Javascript Code to the Send Button which is located at the bottom of the page. How can I link that button to a custom checkbox field that I have created in Salesforce.

For simplicity, I have added that field within that page. By default it is shown as a unselected checkbox. I want the checkbox to be checked when the button is pressed. Is there anyways that I can do that?

I have included my setup as well as the front end of the form below. Currently when I press the button 'Attach Pictures', the checkbox/custom field is not updated.

Any help is greatly appreciated, thanks. 

FormStack SetupFront End
I have 2 radio buttons, 
<label >Vegan?</label>
            <lightning:input type="radio" label="Yes" />
            <lightning:input type="radio" label="No" checked="false" />
default is set to false. 

When I select Yes and refresh the page, the button will always default to false. Is there a way that I can get it to stay as the selected choice? even after refresh? Thanks.
 
Hi ,
I am wondering if it is possible to open up a URL within a modal box. 
I see that someone has posted a similar question earlier this year, but there is no solution to it yet. So I am wondering if anyone have figured it out. 
https://developer.salesforce.com/forums/ForumsMain?id=9060G0000005RcSQAU

I have read the SFDC Monkey (http://sfdcmonkey.com/2017/04/15/modal-box-lightning-component-salesforce/) guide and it does not talk about opening URL within modal box, it just goes over how to create one .

If anyone can give any insight to this, it would be greatly appreciated. 

Thanks. 

 
Hi, 
Within my lightning component I have a button, and when you press on it, it calls a function within the controller called userUpload. Upon clicking this button, the page will redirect you to the picture upload page. 

How do i get the record id to associate itself with the page? 

Currently I have, 
//Component: 

<aura:component access ="global" implements="force:hasRecordId">
<div>
     Click below to go to upload page
</div>
 <lightning:button label="Upload" onclick="{!c.userUpload}" />


//Controller
    userUpload: function(component, event, helper) {
        var urlRedirect= $A.get("e.force:navigateToURL");
        urlRedirect.setParams({
            "url": "/upload&id=" + component.get("v.record").id
        });
        urlRedirect.fire();
    },
when i console.log(component.get("v.record").id I get undefined. Anyways to fix this?
 
How can i round or truncate off the decimal? I don't want the decimal to show. If a user input 1.5 I want it to show either 2 or 1 so either round up or truncate off the decimal, either one works. 

Right now I have:
<lightning:input type="number"  value="{!v.customNumber__c}"/>

Any help is greatly appreciated, thank you.
 
Hi, I currently have the code below
<td data-label="TESTING"><lightning:input type="number" min="0" label="" name=" " value="{!v.testint.test__c}"/></td>
I don't want any decimals, so if there is a decial a error will show up, as seen in the pic below 
User-added image
I also have a Next button at the bottom of the page. Is it possible to make the page stay on the current page when a error such as the above shows up? And only allow the page to go to the next section when the number have been changed from a decimal to a whole number, or when there are no errors shown. 
 
Hi, 
I am new to salesforce and I am still trying to learn. I have a question regarding child queries.
Within my Leads object I have a field called Lead Status (API name: Status). A user can have many leads, and I was wondering how i can query it so that I know how many lead status = new for a certain user. Basically I want to look into a user that contains a list of lead status = new. thanks.
How can i round or truncate off the decimal? I don't want the decimal to show. If a user input 1.5 I want it to show either 2 or 1 so either round up or truncate off the decimal, either one works. 

Right now I have:
<lightning:input type="number"  value="{!v.customNumber__c}"/>

Any help is greatly appreciated, thank you.
 
Hi, I currently have the code below
<td data-label="TESTING"><lightning:input type="number" min="0" label="" name=" " value="{!v.testint.test__c}"/></td>
I don't want any decimals, so if there is a decial a error will show up, as seen in the pic below 
User-added image
I also have a Next button at the bottom of the page. Is it possible to make the page stay on the current page when a error such as the above shows up? And only allow the page to go to the next section when the number have been changed from a decimal to a whole number, or when there are no errors shown. 
 
Hi ,

I am quite new to this lightning experience thing. I am just wondering if it is possible to create an attachment or somesort of text file when a user click on a lightning action button. This text file will consists of a small paragraph which consists custom fields from the object. I did some research and it says that attachment is no longer available for the lightning experience? If that is the case, how can i approach this? 
I have written the below controller class. Was wondering how to write a bulk test for it. any suggestions? Are there good guides out there that teaches how to write test class? Besides for the trailhead module?
 
public with sharing class newStudent { 
@AuraEnabled 
public static Contact getStudent(Id stuId) { 
     Contact stu = [ 
                     SELECT Id, Name, Gender__c, School__c 
                     ( 
                        SELECT class_id__c, class_teacher__r.Name, class_subject__c FROM class__r 
                     )
                     FROM Contact WHERE Id =: stuId ]; 
     return stu; 
} 

//https://developer.salesforce.com/blogs/developer-relations/2015/11/create-lightning-component-drag-drop-profile-pictures.html 

@AuraEnabled 
public static Attachment studentPicture (Id stuId) { 
     if (!Schema.sObjectType.Contact.isAccessible()) { 
          throw new System.NoAccessException(); 
     } 
     List<Attachment> lAttachment = new List<Attachment>(
          [
               SELECT Id, Name, LastModifiedDate, ContentType FROM Attachment 
               WHERE parentid=:stuId AND ContentType IN ('image/png', 'image/jpeg', 'image/gif') 
               ORDER BY LastModifiedDate DESC LIMIT 1
          ]
     ); 
     return lAttachment.size() > 0 ? lAttachment[0] : null; 
} 
    @AuraEnabled
    public static Id saveAttachment(Id parentId, String fileName, String base64Data, String contentType) {
        if (!Schema.sObjectType.Contact.isUpdateable()) {
            throw new System.NoAccessException();
        }
        Attachment attachment = new Attachment();
        attachment.parentId = parentId;
        attachment.body = EncodingUtil.base64Decode(base64Data);
        attachment.name = fileName;
        attachment.contentType = contentType;
        insert attachment;
        return attachment.id;
    }
}
is it possible to create a lightning component within the contacts page layout that allows the user to upload a picture of themselves? 
Hi, 
for some reason within lightning component, if I have 
<ui:inputNumber format="#,###" aura:id="numbers" value="{!v.company.Salary__c}" />
on the Front End, if I input 0 within this field, it will blank out. And in the backend, it will not store 0, it will just store as blank. 
Is there a way that I can get SF to store the 0?

I been thinking of doing a event listener that listens when a user press on 0, 
window.addEventListener("keydown", function(event) {
          alert("key: " + event.key + ", code: " + event.code);
        }, true);
and when the user presses 0 and the user is within that aura:id="numbers" inputNumber field, I can set the company__Salary__c value  to 0 within the backend, so even if the front end displays blank, the backend will store a 0 value. Is that possible? How would one approach that? 

Most importantly, is there any way for the 0 to stay on the front end and not have it dissapear? Online says that 0 is not considered a number, to get it to show on the front end, change inputnumber to just input text field. But I do not want that.

Also, I do not want to use lighting:input type="number", as it doesn't round. Some say you can do the step attribute, but on the front end it doesn't actually change the number. It will display the rounded number, but the backend still saves the decimal number, which is not what i want. 

Any help is greatly appreciated, thank you. 
Is is possible to filter out a query list so I only get the highest one? For example, I would like to  query a students name and his exam mark. And I only want to grab the student with the highest exam mark.  (student__c is a child of class__c)
Select (Select Student_Name__c, Exam_Mark__c from Student__r ORDER BY Exam_Mark__c ASC) from class__c
This grabs all the students and it doesn't sort out the exam marks from highest to lowest. I know I can add a limit 1 to grab only the top value, but how can I gaurantee that the first query value that I am grabbing is the highest? 
 
I am having difficulty getting the following code to work. Any insights? 

Within my lightning component i have: 
<div>Number Test</div>
<ui:inputNumber class="slds-input" format="#,###" aura:id="testNumber" value="{!v.testNumber}" keyup="{!c.keyupAction}" updateOn="keyup" />

Within my controller i have:
testNumber: function(component, event, helper)
    {
        var x = component.find("testNumber").getElement();
        if(x.value =='0')
        {
            x.value = '0';
        }
    }
The code saves, but it doesn't work. Right now I have a number input field, but when I input 0, JS somehow clears it, any other input number will stay on the front end, but as soon as you enter a 0 and navigate away from the input field, the 0 gets cleared. Is there a way that I can get the 0 to stay on the front end? It needs to be in an input number field and not input text. 
I am wondering how I can come about this trigger.

I want to write a before insert trigger that fires whenever a new benefit record is created. It will take in value from a look up object, company__c, 
and prepopulate its custom fields medical_location__c, date_of_subscription__c and medical_description__c field and stamp it on the benefit form. Any help on how I can go about this?
I am having trouble writing a test class for the below controller. 
public class fetchPicklistOptsController {
 @AuraEnabled
 public static List < String > getselectOptions(sObject objObject, string fld) {
  system.debug('objObject --->' + objObject);
  system.debug('fld --->' + fld);
  List < String > allOpts = new list < String > ();
  // Get the object type of the SObject.
  Schema.sObjectType objType = objObject.getSObjectType();
 
  // Describe the SObject using its object type.
  Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
 
  // Get a map of fields for the SObject
  map < String, Schema.SObjectField > fieldMap = objDescribe.fields.getMap();
 
  // Get the list of picklist values for this field.
  list < Schema.PicklistEntry > values =
   fieldMap.get(fld).getDescribe().getPickListValues();
 
  // Add these values to the selectoption list.
  for (Schema.PicklistEntry a: values) {
   allOpts.add(a.getValue());
  }
  system.debug('allOpts ---->' + allOpts);
  allOpts.sort();
  return allOpts;
 }
}

 
Hi, 
Within my lightning component I have a button, and when you press on it, it calls a function within the controller called userUpload. Upon clicking this button, the page will redirect you to the picture upload page. 

How do i get the record id to associate itself with the page? 

Currently I have, 
//Component: 

<aura:component access ="global" implements="force:hasRecordId">
<div>
     Click below to go to upload page
</div>
 <lightning:button label="Upload" onclick="{!c.userUpload}" />


//Controller
    userUpload: function(component, event, helper) {
        var urlRedirect= $A.get("e.force:navigateToURL");
        urlRedirect.setParams({
            "url": "/upload&id=" + component.get("v.record").id
        });
        urlRedirect.fire();
    },
when i console.log(component.get("v.record").id I get undefined. Anyways to fix this?
 
Hi,
  I have a requirement where I need a lightning Modal/Pop up box to load a URL upon click of a button. Can someone please help me with the sample code?  There are plenty of examples on how to open a modal box , but none indicates if we can load a URL in it or not.