+ Start a Discussion
can anyone give me apex trigger examples for better understanding of the apex trigger 
Best Answer chosen by VHsalesforce
Please find the below post for the hands on examples of Apex trigger along with real time scenarios .
Apex Trigger Examples (https://salessforcehacks.blogspot.com/2020/02/apex-trigger-examples-salesforce-apex.html)
Pablo Ledesma 8Pablo Ledesma 8 
I have been trying to pass this challenge (https://trailhead.salesforce.com/en/trails/force_com_dev_intermediate/modules/apex_integration_services/units/apex_integration_webservices):

To pass this challenge, create an Apex REST class that is accessible at '/Accounts/<Account_ID>/contacts'. The service will return the account's ID and Name plus the ID and Name of all contacts associated with the account. Write unit tests that achieve 100% code coverage for the class and run your Apex tests.
The Apex class must be called 'AccountManager'.
The Apex class must have a method called 'getAccount' that is annotated with @HttpGet
The method must return the ID and Name for the requested record and all associated contacts with their ID and Name.
The unit tests must be in a separate Apex class called 'AccountManagerTest'.
The unit tests must cover all lines of code included in the AccountManager class, resulting in 100% code coverage.
Run your test class at least once (via 'Run All' tests the Developer Console) before attempting to verify this challenge.

I getting this error:

Challenge Not yet complete... here's what's wrong: 
Executing the 'AccountManager' method failed. Either the service isn't configured with the correct urlMapping, is not global, does not have the proper method name or does not return the requested account and all of its contacts.

This is my code:
global with sharing class AccountManager {
    global static List<sObject> getAccount(){
        RestRequest request = RestContext.request;
        List<String> urlParams = request.requestURI.split('/');
        String accountId;	
        for(String param: urlParams){
            if((param != 'Accounts') && (param != 'contacts'))
                accountId = param;
        List<Account> lstAccounts = new List<Account>();
        lstAccounts = [SELECT Id, Name FROM Account WHERE Id = :accountId];
        List<sObject> result = new List<sObject>();
        List<Contact> lstContacts = [SELECT Id, Name FROM Contact WHERE AccountId = :accountId];
        for(Contact c:lstContacts){
        return result;

This is my response
[ {
  "attributes" : {
    "type" : "Account",
    "url" : "/services/data/v39.0/sobjects/Account/001o0000015hgVBAAY"
  "Id" : "001o0000015hgVBAAY",
  "Name" : "SFDC Computing"
}, {
  "attributes" : {
    "type" : "Contact",
    "url" : "/services/data/v39.0/sobjects/Contact/003o000001DbYc8AAF"
  "Id" : "003o000001DbYc8AAF",
  "Name" : "Pepito Peres"
}, {
  "attributes" : {
    "type" : "Contact",
    "url" : "/services/data/v39.0/sobjects/Contact/003o000001BsUPwAAN"
  "Id" : "003o000001BsUPwAAN",
  "Name" : "Last0"
} ]

Can someone light my way?​
Best Answer chosen by Pablo Ledesma 8
Sandeep WaliaSandeep Walia
Hi Pablo,

The requirement for the challenge is to return Account and its related contacts, which can be achieved using one SOQL query. I am sharing the code for my apex class that successfully passed the challenge.
//Apex Class

global with sharing class AccountManager{
    global static Account getAccount(){
        RestRequest request = RestContext.request;
        String accountId = request.requestURI.substringBetween('Accounts/','/contacts');
        Account objAccount = [SELECT Id,Name,(SELECT Id,Name FROM Contacts) FROM Account WHERE Id = :accountId LIMIT 1];
        return objAccount;

//Test  class
private class AccountManagerTest{
    static testMethod void testMethod1(){
        Account objAccount = new Account(Name = 'test Account');
        insert objAccount;
        Contact objContact = new Contact(LastName = 'test Contact',
                                         AccountId = objAccount.Id);
        insert objContact;
        Id recordId = objAccount.Id;
        RestRequest request = new RestRequest();
        request.requestUri =
            + recordId +'/contacts';
        request.httpMethod = 'GET';
        RestContext.request = request;
        // Call the method to test
        Account thisAccount = AccountManager.getAccount();
        // Verify results
        System.assert(thisAccount!= null);
        System.assertEquals('test Account', thisAccount.Name);

While your code did provide the evrything that was required the JSON returned in the case of single SOQL  is different as compared to your JSON.

Hope this helps,

I am working in enterprise edition. As winter 14 changed... i am unable to see the option reset security token . In devoloper edition it is visible. So from Enterprise edition i am unable to find.

Best Answer chosen by Admin (Salesforce Developers) 



below is the steps to find Reset security token in "Enabled Improved Setup User Interface".


Step 1. Go to Your Name --> My Settings

Step 2. select Personal | Reset My Security Token


Here you can find the option "Reset Security Token".


Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

Heiko KramerHeiko Kramer 
// Map to keep key (caregory) and value related to each other
        Map<String, String> mailValues = new Map<String, String>();
        // Seperate keys and values and put it in the map 
       	List<String> listOfLines = plainText.split('\n');
        for(String line : listOfLines){
            String key   = line.substringBetween('<', '>');
            String value = line.substringBetween('<' + key + '>', '</' + key + '>');
            if (key != null) {                                    // this works just fine, null key not added 

            // if (key != null || value != null){           // works partial, null key not added, but empty value added
            //  if (key != null || value != ''){              // doesn't work at all, null key + empty value get added 

                mailValues.put(key, value);                
Hi guys, I'm getting tagged values per mail in this format:


Somethimes there are linebreaks, so I get a null key added to the map. Got that solved with "key != null".

But I'm struggling with excluding no-values like <key></key>.
Probably easy, but I'm absulte beginner … can someone give me a hand here?
Best Answer chosen by Heiko Kramer
Sourav PSourav P
Why not to use only , If (value != null) { ,in the second If statement. Using both key & value in the If statement  will generate the key, value pair if any one is true.
Eric Kendi ShiraishiEric Kendi Shiraishi 
Hi, I am having trouble with the "Attributes and Expressions" module from trailhead.

Here is the challenge:
Create a Lightning Component to display a single item for your packing list.
  • Create a component called campingListItem that displays the name (ui:outputText) and the three custom fields using the appropriate output components.
  • Add an attribute named 'item' for type Camping_Item__c.
I created an component named campingListItem and this is the code:
<aura:component >
    <aura:attribute name="item" type="<my_domain>__Camping_Item__c"/>
    <ui:outputText value="{!v.item.Name}"/>
    <ui:outputCheckbox value="{!v.item.<my_domain>__Packed__c}"/>
    <ui:outputCurrency  value="{!v.item.<my_domain>__Price__c}"/>
    <ui:outputNumber value="{!v.item.<my_domain>__Quantity__c}"/>

The error that I am getting is: "Challenge Not yet complete... here's what's wrong: 
The packingListItem Lightning Component's attribute tag doesn't exist or its attributes are not set correctly."

With this, I tried to create another component, with the name "packingListItem", but It didn't work.

Can anyone help me?

Best Answer chosen by Eric Kendi Shiraishi
Jeff DouglasJeff Douglas
Sorry for the inconvenience. Change your attribute to the following and everything should pass. I'm getting this update ASAP.
<aura:attribute name="item" type="Camping_Item__c" required="true"/>

Jeff Douglas
Trailhead Developer Advocate

I've managed to create a lightning homepage component with 1 column using the below component, style, and design elements. If I re-use the {!v.main} in the component page more than once, I receive an error. 

I want to be able to create 3 horizontal sections as shown in the last image below. Is it possible? 

<aura:component implements="lightning:homeTemplate">
    <aura:attribute name="main" type="Aura.Component[]" /> 
        <lightning:layout horizontalAlign="spread">

<flexipage:template >
        <flexipage:region name="main" defaultWidth="Xlarge">

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="120px" height="120px" viewBox="0 0 120 120" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
	<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
		<path d="M120,108 C120,114.6 114.6,120 108,120 L12,120 C5.4,120 0,114.6 0,108 L0,12 C0,5.4 5.4,0 12,0 L108,0 C114.6,0 120,5.4 120,12 L120,108 L120,108 Z" id="Shape" fill="#2A739E"/>
		<path d="M77.7383308,20 L61.1640113,20 L44.7300055,63.2000173 L56.0543288,63.2000173 L40,99.623291 L72.7458388,54.5871812 L60.907727,54.5871812 L77.7383308,20 Z" id="Path-1" fill="#FFFFFF"/>

This is the error I receive
User-added image

This is the layout I can render but doesn't work if I add components to it
User-added image
Best Answer chosen by HNT_Neo
Alain CabonAlain Cabon

<lightning:layout >  and  <lightning:layoutitem> are not mandatory for a template.

Just use  <div class="slds-grid slds-wrap">, it is sufficient
and you have many samples here: https://www.lightningdesignsystem.com/utilities/grid/

<aura:component implements="lightning:homeTemplate" access="global" >
    <aura:attribute name="center" type="Aura.Component[]" />
    <aura:attribute name="left" type="Aura.Component[]" />
    <aura:attribute name="right" type="Aura.Component[]" />
    <div class="slds-grid slds-wrap">
        <div class="slds-col slds-size_1-of-3">
        <div class="slds-col slds-size_1-of-3">
        <div class="slds-col slds-size_1-of-3">

<design:component label="My Two column Page">
        <flexipage:region name="left" defaultWidth="SMALL">
            <flexipage:formfactor type="MEDIUM" width="SMALL"/>
        <flexipage:region name="center" defaultWidth="SMALL">
            <flexipage:formfactor type="MEDIUM" width="SMALL"/>
        <flexipage:region name="right" defaultWidth="SMALL">
            <flexipage:formfactor type="MEDIUM" width="SMALL"/>

User-added image

Roman RauerRoman Rauer 
Hi there :)

i'm currently working on an native Android app for my company and ran into some problems with Salesforce lately.

I hope i can find some help here.

What i want to achieve:
The company has a lot of Accounts in Salesforce with 3 important fields for the app: Name, Business (Workshop or Parts Dealer) and location(latitude, longitude)
I would like to show those Accounts(Workshops/Parts Dealers) as markers on a google map in my Android app based on a radius around the user's current location. So it would be more than sufficient to get the data as JSON or XML(i read about sObjects, which would be nice too)

The app will be freely available on Google Play Store and every user should be able to see all the Workshops/Parts dealers around the world.

The problem i'm facing is that i can't find a way to fetch the data inside my app without authenticating every user with a Salesforce-Login. 
Which API is the best to use in this case?

It would be so awsome if anybody could help me with this problem.

What i tried so far: 
- SalesforceMobileSDK: If i extend SalesForceApplication i always end up with the Salesforce-Login Screen.
It seems that every client has to be authenticated for API-calls to work. I tried using the method "peekUnauthenticatedRestClient", but this method only works on full path URL's(e.g. "https://api.spotify.com/v1/search?q=James%20Brown&type=artist"), which isn't really practically for my Use-case.

- I feel like i read nearly all docs about salesforce api, but can't quite get my head around how to solve this problem, although it seems like to be a pretty common use-case.  

- would a salesforce-apex method which would select all records inside a set radius around the user's location be accessable without authentication?

Thanks for your help in advance!

Best Answer chosen by Roman Rauer
Santosh Bompally 8Santosh Bompally 8
Follow this -> 
1) Write a Restservice to expose your data. 
global with sharing class MyRestResource {

    global static List<Account> doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
       List< Account>  result = [SELECT Id, Name, Business,Location FROM Account ];
        return result;

2)  Create a Community and provide access to apex class and account object to the Guest user profile. 
    Samplecommunity url -> https://somedomain.cs16.force.com/communityname

3) Go to workbench and test your API using rest explorer 
    relative url ->  /services/apexrest/Account
4) Your public url will now be   https://somedomain.cs16.force.com/communityname/services/apexrest/Account 

Mark as Best Answer if it helps. 



Hi Team,


In Text type of Email Templates, i want to specify logged in user as merge field. Could anyone have any suggestions.

I have tried with the following lines. But it is not working.








Best Answer chosen by Admin (Salesforce Developers) 

Hi Anil,


You are using only '!', please use '!$' like {!$User.FirstName}

Hi All,
Help me on this, i want using validation rule "Dealer user cannot save if the selected picklist value in Status field in "Inquiry" record type in Case is "Uploaded".
Best Answer chosen by sanjusfdc
Prakash NawalePrakash Nawale

Use below code in validation rule to prevent creating of Case record based on your requirments.
            $User.Username = 'Dealer username',
            ISPICKVAL( Status , 'Uploaded') 

Please like the answer and mark it as best if this helps.
EQ AdminEQ Admin 
for(Apttus_Billing__Invoice__c invoice:invoiceObjectList1) // loop over invoices
                  List<InvoiceLineItems> listToStoreLineItems = new List<InvoiceLineItems>();
                  APTS_InvoiceJournalWrapper invoiceJournWrapper= new APTS_InvoiceJournalWrapper();
                  Decimal Sum=0;
                                    invoiceJournWrapper.AccountingJournalID=String.valueOf(invoice.Name + '_' +myDate);
                                    invoiceJournWrapper.JournalNumber=String.valueOf(invoice.Name + '_' +myDate);
                  list<Apttus_Billing__InvoiceLineItem__c> invlineitems=[Select id,Apttus_Billing__AssetLineItemId__r.Apttus_Config2__ProductId__r.ProductCode,Apttus_Billing__AssetLineItemId__r.Apttus_Config2__OptionId__r.ProductCode,Apttus_Billing__InvoiceId__r.Name,Apttus_Billing__ProductId__r.Name,Apttus_Billing__InvoiceId__r.CurrencyIsoCode,
                                                             from Apttus_Billing__InvoiceLineItem__c where Apttus_Billing__InvoiceId__c=:invoice.id and Apttus_Billing__Type__c='Contracted' and Apttus_Billing__Amount__c!=0];
                   InvoiceLineItems FirstInvItems= new InvoiceLineItems();

Best Answer chosen by EQ Admin
paul diracpaul dirac
I find some errors and the code does not compile (i mocked all of your custom object but anyway there might be some sintax errors).
Consider to split some "iterative tasks" in an helper (static) class, since your Rest service might grows in future, developers (you too ofc) may encounter difficulties to maintain that. For example, that part in which lineItems are collected and then modified can be delegated to the helper class to enhance code readability.
Further little optization can be done storing fixed numbers/strings in costants but I guess that there are not any improvements that significately reduce the execution time, I mean the optimization I will want to see here is in code readability first. Hope I helped you to solve your cancerns!