+ Start a Discussion
Jennifer Blankenship 12Jennifer Blankenship 12 
knowledge is not in any of my trailhead playgrounds. how do i get it to do trails?
Best Answer chosen by Jennifer Blankenship 12
Kamal ThakurKamal Thakur
Hi Jennifer,

Goto your profile in your trailhead playground. 
Check the "Knowledge User" checkbox and click save. 

Please like this answer and mark it as best if helpful. 

Regards,
Kamal
Manisha ValavalaManisha Valavala 
Hi ,

I am not able to browse third party url in lightning component as it shows below error 

"The domain is not set in 'CSP trusted sites whitelist'

But I have added the third party url in CSP , please assist
Best Answer chosen by Manisha Valavala
SwethaSwetha (Salesforce Developers) 
HI Manisha,
Ensure that you have  added the URL to CSP Errors whitelist using a wildcard like this: https://*.forcecontentuser.com

Also there is a known issue with the lightning:map usage which is worth checking: https://trailblazer.salesforce.com/issues_view?id=a1p3A000001FSlqQAG

If this information helps, please mark the answer as best. Thank you
DiamundoDiamundo 
Hi there.

In my lightning app I have a few components:
  • one component has a ui:inputSelect and registers an event. the ui:inputSelect has a change attribute that fires a function, wherein the selected text (an ID) is put in an event and fired.
  • one component that handles the event, is an aura:iteration list of a component that, on handling the event, should retrieve a list of items where a master-child lookup is the sent ID of the master object. This then displays all those child objects.
  • the other component that handles the event, has three inputText fields, that are supposed to display the other fields of the master object
The problem: either the event seems to not be fired, or the handlers seem to not be activated.

I put console.debug's, alerts and component.set("v.testmessage", "fired") 's in the handlers but they never execute.
I then put one of the handlers as the init-handler and then it did execute the handler (with an undefined ID since the event hadn't yet been fired, which is reasonable).

I have triple-checked the event name, event type and handler action, everything matches. I have no compilation problems, I have no errors when I am using my app. 
I also have no response whatsoever from my event. Any ideas?

**Registering component**
<aura:component controller="PrefixMasterHeaderSelectorController">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:registerEvent name="updateMaster" type="c:PrefixMasterEvent" />
    <aura:attribute name="masters" type="PrefixMaster__c[]"/>
      
    <label class="slds-master-element__label" for="masterSelector">Select a master to work with:</label>
    <div class="slds-master-element__control">
        <div class="slds-select_container">
            
            <ui:inputSelect aura:id="masterID" class="slds-select" change="{!c.masterHasChanged}">
                <aura:iteration items="{!v.masters}" var="master">
                    <ui:inputSelectOption text="{!master.Id}" label="{!master.Name}" />
                    <!-- + ' (Last modified: ' + master.LastModifiedDate + ' by ' + master.LastModifiedBy.Name + ')'}"/> -->
                </aura:iteration>	
                <ui:inputSelectOption text="newMaster" label="Create a new master" />
            </ui:inputSelect>
            
        </div>
    </div>

    <c:PrefixMasterHeaderMaster />
</aura:component>

**Registering controller**
({
    doInit : function(component, event, helper) {
        // Create the action
        var action = component.get("c.getMasters");
    
        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.masters", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
    
        // Send action off to be executed
        $A.enqueueAction(action);
    },
    
    masterHasChanged : function(component, event, helper) {
        var masterID = component.find("masterID").get("v.value");
        var masterEvent = component.getEvent("updateMaster");
        masterEvent.setParams({"master" : masterID})
        masterEvent.fire();
        
		console.debug('UPDATE MASTER = ' + masterID);
        alert('Hiya! masterEvent ' + masterEvent.getParam("master"));
    }
		
})

**List-child component**
<aura:component controller="PrefixListChildsController">
	<aura:handler name="updateForm" event="c:PrefixFormEvent" action="{!c.loadChilds}" />
    <aura:attribute name="childs" type="PrefixChild__c[]"/>
    
	<!--   	<aura:handler name="saveChild" event="c:PrefixChildEvent" action="{!c.handleAddItem}"/> -->
    <!--	to reload the masters after adding a new child -->
    
    <div>
        <header class="slds-p-top--small">
            <h3 class="slds-text-heading--small">Childs</h3>
        </header>
        
        <div id="list" class="row">
            <aura:iteration items="{!v.childs}" var="child">
                <aura:if isTrue="{!child.Order__c % 2 == 1}">
                        <div class="slds-p-around--small" style="background-color: lightblue; border-radius: 10px">
                            <c:PrefixChild child="{!child}"/>
                        </div>
                    <aura:set attribute="else" >
                        <div class="slds-p-around--small" style="background-color: none; border-radius: 10px">
                            <c:PrefixChild child="{!child}"/>
                        </div>
                    </aura:set>
                </aura:if>
            </aura:iteration>
            {!v.testEventmessage}
            <c:PrefixNewChild />
        </div>
    </div>

</aura:component>

**List-child controller.js**
({
	loadChilds : function(component, event, helper) {
 	    var action = component.get("c.getChilds");
		var masterID = event.getParam("master");    
    	action.setParams({ "masterID" : masterID });
        
        console.debug('master id = ' + masterID);
        alert('load childs ' + masterID);
        component.set("v.testEventmessage", masterID);

        // Add callback behavior for when response is received
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (component.isValid() && state === "SUCCESS") {
                component.set("v.childs", response.getReturnValue());
            }
            else {
                console.log("Failed with state: " + state);
            }
        });
        
        // Send action off to be executed
        $A.enqueueAction(action);
    }
})


 
Best Answer chosen by Diamundo
DiamundoDiamundo
Solved it...

After I found out that the firing component was able to handle the (component) event, but a component somewhere else (not a parent or child component, but, say, an uncle-component) was not, I changed the type of the event to application. Still didn't work, so I looked up the documentation and saw that an application-type event is registered slightly different.

**APPLICATION-TYPE EVENT:**
<aura:event type="APPLICATION" >
    <aura:attribute name="item" type="sObject__c" />
</aura:event>
**REGISTERING COMPONENT**
<aura:registerEvent name="PrefixMasterEvent" type="c:PrefixMasterEvent" />

**FIRING CONTROLLER**
var applicationEvent = $A.get("e.c:PrefixMasterEvent");
    applicationEvent.setParams({"item" : itemID})
    applicationEvent.fire();
(Note: instead of component.getEvent("eventName") you now use $A.get("e.c:EventName") !
I'm not sure what the 'e' stands for, but I'm pretty sure the 'c' part is the namespace, and be careful to put the name of the event FILE as 'EventName' in the $A.get() parameter.)

**HANDLING COMPONENT**
<aura:handler event="c:PrefixApplicationEvent" action="{!c.doAnotherFunction}" />
(Note: the main difference is: with an application event there is no need (or use) for an event 'name', and I'm not sure why it has to be specified at the registerEvent tag other than it's a required attribute of the tag.)

**HANDLING CONTROLLER**
({
    doAnotherFunction(component, event, helper) {
        var item = event.getParam("item");
        alert('The item is: ' + item);
    }
})




 
Shane QuiringShane Quiring 
Hi Experts,

I need some assitance with a date formula. I trying to calculate the number of months left between two dates, start and end date. I currently have the folloiwng formula:

(Custom_End_Date__c - today ())/30

Which will give me the number of days left and if I divide the number by 30 and I should get the numbner of months. Unfortunately I am short by one month. For example if I have a end date of 12/01/2015 minus today, 30 July, would give me 124 days. If I divide that by 30 I get 4 months, or more exactly 4.13 months. But from July to Dec is 5 months.

Any assistance would be greatly appreciated.

Thank-you
Best Answer chosen by Shane Quiring
CyberJusCyberJus
Dividing by 30 is going to give you slightly inaccurate results because not every month is 30 days. 

If you are only concerned about difference in the actual month - ie July 30th to Aug 1st = 1 month
Try this:
(MONTH(Custom_End_Date__c) + (12*(YEAR(Custom_End_Date__c)-YEAR(TODAY()))) - MONTH(TODAY())
Chris McCartyChris McCarty 
How does one add the Salesforce Trailhead Badges (link) on their Linkedin Profile? When I edit my Linkedin profile where do I do this?
Thanks!
Best Answer chosen by Chris McCarty
Sebastian.PerazaSebastian.Peraza
I just added a badge that i've already had in my LinkedIn profile.
You can go to your LinkedIn profile and under Add certificate -> Certification Name & Certification Authority (Salesforce Trailhead).
That's it.
Akshay ShrivastavaAkshay Shrivastava 
i have created a app ..in which iam using standard objects..i want to restrict user not to see the records created by admin  
Best Answer chosen by Akshay Shrivastava
Suraj Tripathi 47Suraj Tripathi 47

Hi Akshay,

You control record-level access in four ways.
Org-wide defaults specify the default level of access users have to each other’s records.
Role hierarchies ensure managers have access to the same records as their subordinates. Each role in the hierarchy represents a level of data access that a user or group of users needs.
Sharing rules are automatic exceptions to org-wide defaults for particular groups of users, to give them access to records they don’t own or can’t normally see.
Manual sharing lets record owners give read and edit permissions to users who might not have access to the record any other way.

Please refer this link

https://trailhead.salesforce.com/content/learn/modules/data_security/data_security_sharing_rules

 

Please mark it as Best Answer if it helps!

Thank You!

Abilash Kosigi 8Abilash Kosigi 8 
A question on a lighter note. I am new to Salesforce and to this forum. What is the criteria that is followed to award points in the forum. Are there any benefits for the peole who accrue more? :)
Best Answer chosen by thisisnotapril
pconpcon
The points are awarded for answering posts, being chosen as the correct answer and having your posts/answers liked.  As for the benefits, there's the fame that goes along with being known in the developer community and the satisfaction of knowing you've helped your fellow developers.  Also, if you continue to be an outstanding member in the community (doing additional things like giving talks in your local area or blogging about the platform) you could be nomitated for the MVP program [1].

[1] http://www.salesforce.com/mvp/
gbalakrigbalakri 

I am trying to execute the following code for recalling an approval process an ends up getting the following error

 

 

execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: INVALID_OPERATION, Illegal transition type:

 

 Approval.ProcessWorkItemRequest pwr = new Approval.ProcessWorkItemRequest();
       
List<ProcessInstance> procins = new List<ProcessInstance>([select Id from ProcessInstance where Status = 'Pending' and TargetObjectId = :objectId]);
// Retrieve the process work instance id associated to the process instance
            List<ProcessInstanceWorkitem>  workitem = new List<ProcessInstanceWorkitem>([select Id from ProcessInstanceWorkitem where ProcessInstanceId = :procins[0].id]);

            if ((workitem != null) && (workitem.size() > 0))
            {
                pwr.SetComments(statusToUpdate);

                pwr.setWorkItemId(workitem[0].id);
                pwr.setAction('Remove');
            
               
                // Execute process request
                Approval.ProcessResult pr = Approval.process(pwr);

}

Best Answer chosen by Admin (Salesforce Developers) 
jlojlo

 gbalakri - Try changing this line:

 

pwr.setAction('Remove');

 to this:

 

 

 

pwr.setAction('Removed');

 

 

See the docs: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content%2Fapex_ProcessWorkitemRequest.htm|SkinName=webhelp

Message Edited by jlo on 04-08-2009 12:07 PM
David Vickers 44David Vickers 44 
I am a beginner with coding and looking for help

The code I have below works for getting 100% coverage and passes the trailhead evaluation however I also wanted to assert that the Error message is correct.

because I wanted to set up all test data outside of the starttest() and I wanted to check and valid insert as well as a invalid one I need to write the saveresults to a list. Everything works fine untill i tried to access the  error messages.
I have played with every variation but cannot figure out the syntax

system.debug(r1.getErrors());  gives me  DEBUG|(Database.Error[getFields=();getMessage=The Last Name "INVALIDNAME" is not allowed for DML;getStatusCode=FIELD_CUSTOM_VALIDATION_EXCEPTION;])

system.debug(r1.getErrors().getMessage);  doesn't compile " Initial term of field expression must be a concrete SObject: List<Database.Error>"
system.debug(r1.getErrors().getMessage()); doesn't  Method does not exist or incorrect signature: [List<Database.Error>].getmessage()

And so my tries Have gone on!

how do I get the getMessage field from the getErrors?

 
@istest
private class TestRestrictContactByName {
    @isTest Static void TestRestictedname(){
        List<contact> testcontacts = New List<contact>();
        contact c0 = new contact(LastName = 'Testcontact');
        testcontacts.add(c0);
        Contact c1 = new contact(LastName = 'INVALIDNAME');
        testcontacts.add(c1);
        Test.startTest(); 
        Database.SaveResult[] srList = Database.insert(testcontacts, false); 
        Test.stopTest();
        Database.SaveResult R0 = srlist[0];
        Database.SaveResult R1 = srlist[1];
        
        System.assert(r0.isSuccess());
        System.assert(!r1.isSuccess());
                      
                      }
                      }

 
Best Answer chosen by David Vickers 44
Amit Chaudhary 8Amit Chaudhary 8

Please check below post for same issue
1) https://developer.salesforce.com/forums/?id=906F0000000BNjqIAG
2) https://developer.salesforce.com/forums/?id=906F0000000BQwoIAG

you can try below code
@isTest
public class TestRestrictContactByname {
    
    @isTest static void TestContactWithInvalidNameNotInserted(){
        
        String inputLastName = 'INVALIDNAME';
        Contact newContact = new Contact(LastName= inputLastName);	    
        
        Test.startTest();
        try{
            insert newContact;
        }
        catch (DmlException dmlEx) {
        	
        	// Verify (Assert)
        	// In this case the insert should have been stopped by the trigger,
        	// so we need to verify that we got a dml exception (and specifically that we got the error message
            // that we were expecting).
        	String expectedMessage = 'The Last Name "'+ newContact.LastName+'" is not allowed for DML';
            System.assertEquals(expectedMessage, dmlEx.getDmlMessage(0));
        }
        Test.stopTest();
    }
}

Sample code 2:-
@isTest
private class TestRestrictContactByName {

    @isTest static void metodoTest() 
    {
        Contact c = new Contact(LastName = 'INVALIDNAME');
  
       
        Database.SaveResult result = Database.insert(c, false);
      
       
        System.assert(!result.isSuccess());
        System.assert(result.getErrors().size() > 0);
        System.assertEquals('The Last Name "INVALIDNAME" is not allowed for DML',
                             result.getErrors()[0].getMessage());


        
    }
    
}


Let us know if this will help you

Thanks
Amit Chaudhary
 
Ravikant kediaRavikant kedia 
Hello everyone,
                            I am doing integration salesforce with box.com when i uplod file that time first i convert blob into base 64 encoded string then send file using rest api after uploading  file my file in  not readable form it meanse file is encoded. And i am sending file in body as a blob and also try in body but i can't sucess. so give me some idea that how i can solve this issue.
   (Thanks in advance).
             
Best Answer chosen by Ravikant kedia
Deepak Kumar ShyoranDeepak Kumar Shyoran
Box dot supports some common formate like csv,txt,etc which contains text type data, and you'll be easily able to do that but when you try to upload some file (Blob type) then you need to some work around for that.

Try below code it'll help you to upload your file to box.com
public static HTTPResponse uploadFile(Attachmnet file)
 {
  String boundary = '__boundary__xxx';
  String header = '--'+boundary+'\n';
     + 'Content-Disposition: form-data; name="data"; filename="'+file.name
     +'"\nContent-Type: application/octet-stream\n\n';
 
  String footer = '\n--'+boundary+'--';
   
  String body = EncodingUtil.base64Encode(file.Body); //encodes the blob into a base64 encoded String
   
  body = header + body + footer;
   
  HttpRequest req = new HttpRequest();
  req.setHeader('Content-Type','multipart/form-data; boundary='+boundary);
  req.setMethod('POST');
  req.setEndpoint('http://posttestserver.com/post.php?dir=what_a_wonderful_post');   //COOL site to test form uploads
  req.setBody(body);
  req.setTimeout(60000);
  req.setHeader('Content-Length',String.valueof(body.length()));
   
  Http http = new Http();
      return http.send(req);
 }

Please mark my answer as a best solution to your question to help others if it solves your problem.