+ Start a Discussion
Filip Poverud 4Filip Poverud 4 
Build a Conference Management App --> Create an Aura Component

I have tried to Copy/Paste using CTRL+C and CTRL+V, using the mouse copy/paste functions and also writing the code manually but all attempts fail. Are there any other ways of copying the text so I can complete this challenge ?
Best Answer chosen by Filip Poverud 4
Filip Poverud 4Filip Poverud 4
I fixed the error by using:
 
e.force:navigateToObjectHome

Instad of:
"standard__objectPage"

For some reason it was the navigation back to the record that failed using the code in the module.
Sean GibsonSean Gibson 
Hi,

I am fairly new to salesforce as an admin, I am looking for a bit of advice around a formula field,

I have a field which converts a date/time value and takes only the date bu converting it to text, however the format of the date is YYYY-MM-DD, I am wondering if there is any way to change the order of the date field so it shows DD-MM-YYYY

My formula is below;

Name&" - "&ProductCode__r.Name&" - "&LEFT(TEXT(Outward_Date__c),FIND(" ",TEXT(Outward_Date__c))-1)&" - "& From__r.Name&" >> "&To__r.Name

Appreciate any help I can be offered,

Thank you,
Best Answer chosen by Sean Gibson
Ajay K DubediAjay K Dubedi
Hi Sean,

I looked at your issue and found the solution. I tested it at my org and it worked.
You have one formula field-
Date field will be in  DD-MM-YYYY format by this solution.

Replace Your code with this->

Name&" - "&ProductCode__r.Name&" - " & Right(TEXT(Outward_Date__c),2) &"-"& RIGHT(LEFT(TEXT(Outward_Date__c),7),2) &"-"& LEFT(TEXT(Outward_Date__c),4) &" - "& From__r.Name&" >> "&To__r.Name


This piece of formula will write the date in DD-MM-YYYY format.

 Right(TEXT(Outward_Date__c),2) &"-"& RIGHT(LEFT(TEXT(Outward_Date__c),7),2) &"-"& LEFT(TEXT(Outward_Date__c),4)


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com
Timothy SmithTimothy Smith 
My company's org has about five triggers more than one existing (after insert, after edit).  I am about to create an (after insert) trigger.  Suggestions as to how I would consolidate or should I create my trigger and add to the pile.  If I should consolidate, how would that look?
Best Answer chosen by Timothy Smith
Deepali KulshresthaDeepali Kulshrestha
Hi Timothy,

1.You can see the best practice to write trigger from the below link:-

https://developer.salesforce.com/index.php?title=Apex_Code_Best_Practices&oldid=26951

2.Trigger Best Practices | Sample Trigger Example | Implementing Trigger Framework

 1) One Trigger Per Object
 A single Apex Trigger is all you need for one particular object. If you develop multiple Triggers for a single object, you have no way of controlling the order of execution if those Triggers can run in the same contexts

 2) Logic-less Triggers
 If you write methods in your Triggers, those can’t be exposed for test purposes. You also can’t expose logic to be re-used anywhere else in your org.

 3) Context-Specific Handler Methods
 Create context-specific handler methods in Trigger handlers

 4) Bulkify your Code
 Bulkifying Apex code refers to the concept of making sure the code properly handles more than one record at a time.

 5) Avoid SOQL Queries or DML statements inside FOR Loops
 An individual Apex request gets a maximum of 100 SOQL queries before exceeding that governor limit. So if this trigger is invoked by a batch of more than 100 Account records, the governor limit will throw a runtime exception

 6) Using Collections, Streamlining Queries, and Efficient For Loops
 It is important to use Apex Collections to efficiently query data and store the data in memory. A combination of using collections and streamlining SOQL queries can substantially help writing efficient Apex code and avoid governor limits

 7) Querying Large Data Sets
 The total number of records that can be returned by SOQL queries in a request is 50,000. If returning a large set of queries causes you to exceed your heap limit, then a SOQL query for loop must be used instead. It can process multiple batches of records through the use of internal calls to query and queryMore

 8) Use @future Appropriately
 It is critical to write your Apex code to efficiently handle bulk or many records at a time. This is also true for asynchronous Apex methods (those annotated with the @future keyword). The differences between synchronous and asynchronous Apex can be found

 9) Avoid Hardcoding IDs
 When deploying Apex code between sandbox and production environments, or installing Force.com AppExchange packages, it is essential to avoid hardcoding IDs in the Apex code. By doing so, if the record IDs change between environments, the logic can dynamically identify the proper data to operate against and not fail
Trigger Example:

 trigger AccountTrigger on Account( after insert, after update, before insert, before update)

{

 

    AccountTriggerHandler handler = new AccountTriggerHandler(Trigger.isExecuting, Trigger.size);

     

    if( Trigger.isInsert )

    {

        if(Trigger.isBefore)

        {

            handler.OnBeforeInsert(trigger.New);

        }

        else

        {
            handler.OnAfterInsert(trigger.New);

        }

    }

    else if ( Trigger.isUpdate )

    {

        if(Trigger.isBefore)

       {

            handler.OnBeforeUpdate(trigger.New ,trigger.Old,Trigger.NewMap,Trigger.OldMap);

        }

        else

        {

            handler.OnAfterUpdate(trigger.New ,trigger.Old,Trigger.NewMap,Trigger.OldMap);

        }

    }

Apex Class for trigger:-

public with sharing class AccountTriggerHandler
{

    private boolean m_isExecuting = false;
    private integer BatchSize = 0;
    public static boolean IsFromBachJob ;
    public static boolean isFromUploadAPI=false;

    public AccountTriggerHandler(boolean isExecuting, integer size)

    {

        m_isExecuting = isExecuting;
        BatchSize = size;

    }

    public void OnBeforeInsert(List<Account> newAccount)

    {
        system.debug('Account Trigger On Before Insert');

    }

    public void OnAfterInsert(List<Account> newAccount)

    {
        system.debug('Account Trigger On After Insert');

    }

    public void OnAfterUpdate( List<Account> newAccount, List<Account> oldAccount, Map<ID, Account> newAccountMap , Map<ID, Account> oldAccountMap )
    {
        system.debug('Account Trigger On After Update ');

        AccountActions.updateContact (newAccount);

    }

    public void OnBeforeUpdate( List<Account> newAccount, List<Account> oldAccount, Map<ID, Account> newAccountMap , Map<ID, Account> oldAccountMap )
    {

        system.debug('Account Trigger On Before Update ');

    }

 
  @future
    public static void OnAfterUpdateAsync(Set<ID> newAccountIDs)
    {

    }     

    public boolean IsTriggerContext

    {

        get{ return m_isExecuting;}

    }
    public boolean IsVisualforcePageContext

    {

        get{ return !IsTriggerContext;}

    }

     

    public boolean IsWebServiceContext

    {

        get{ return !IsTriggerContext;}
    }
    public boolean IsExecuteAnonymousContext

    {

        get{ return !IsTriggerContext;}

    }

}

Create one Trigger Action Class

public without sharing class AccountActions
{
    public static void updateContact ( List<Account> newAccount)
    {
        // Add your logic here
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Nico AnicaNico Anica 
Hello, 
I am trying to display some information but everytime I have this following message error :
SObject row was retrieved via SOQL without querying the requested field: Contact.Client_a_risque__c

Here below is my code : 

<!--*********************************************************************************
Class Name      : CCF_CustomContactSearch
Description     : This page will be open by InIn on an Agent's browser, once a Case is 
                  assigned to the Agent. 
                  When loaded, the page will contain a list of Contacts 
                  possibly matching to a value (svalue) contained in the URL as a parameter
                  The Agent also has the option to search for a specific contact, using the
                  input field beside "Search Contact" button. The value provided in the input 
                  field will be searched in ALL fields in the Contact Object
                  For every listed Contact, the Agent has the option lo link it to the Case,
                  using "Link to Case" button
Created By      : Mihai JURIAN
Created Date    : 30-Jan-17
Modification Log:
================================================================================== 
Developer                   Date                   Description
==================================================================================        
Mihai Jurian            30-Jan-17                   Initial Version
*********************************************************************************-->
<apex:page controller="CCF_searchContactController" docType="html-5.0" action="{!search_onLoad}" title="{!$Label.InIn_Recherche_de_contact}">

    <apex:includeScript value="/support/console/28.0/integration.js"/>
    <script type="text/javascript">
        function openCaseDetails() {
            sforce.console.openPrimaryTab(undefined, '/{!caseId}', true, '{!caseNumber}');
            closeTab();
        }

        // The callback function that closeTab will call once it has the ID for its tab
        var callCloseTab = function callCloseTab(result) {
            sforce.console.closeTab(result.id);
        }
    
        function closeTab() {
            sforce.console.getEnclosingPrimaryTabId(callCloseTab);
        }
    
        var pageLoad = window.onload;
        window.onload = function() 
        {
            if (pageLoad) 
            {
                pageLoad();
            }
            sforce.console.setTabTitle('{!$Label.InIn_Recherche_de_contact}');
        }
    </script>
    <apex:form >
        <apex:actionFunction name="updateSortOrderBy1" action="{!updateSortOrderBy}">
            <apex:param id="updateOrderBy" name="updateOrderBy" value="" />
        </apex:actionFunction>
        <apex:actionFunction name="search_method" action="{!search_method}" />

        
        <apex:input value="{!searchValue}" id="searchValue"/>
        <apex:commandButton value="{!$Label.InIn_Trouver_le_Contact}" onclick="search_method(); return false;" />
        <apex:outputText id="searchWarning" value="Please enter at least 2 characters before searching." rendered="{!showSearchWarning}" />
        
       
        <apex:pageBlock title="Contacts" id="block">
            <apex:inputCheckbox value="{!excludeHasFilter}"  onclick="search_method();" />
            <apex:outputText >{!$Label.CCF_CustomSearch_IncludeAllRecords}</apex:outputText>
            <br/>&nbsp;
            <apex:pageMessages />
            <!-- the Pagination/Navigation buttons -->
            <apex:pageBlockButtons rendered="{!RenderNavigation}" location="bottom"> 
                <apex:commandButton value="{!$Label.navigationFirst}" action="{!first}" disabled="{!DisablePrevious}"/>
                <apex:commandButton value="{!$Label.navigationPrevious}" action="{!previous}" disabled="{!DisablePrevious}"/>
                <apex:commandButton value="{!$Label.navigationNext}" action="{!next}" disabled="{!DisableNext}"/>
                <apex:commandButton value="{!$Label.navigationLast}" action="{!last}" disabled="{!DisableNext}"/>
            </apex:pageBlockButtons>
            <!-- the table showing the Contacts -->
            <apex:pageblockTable id="contactList" value="{!conListToShow}" var="con">
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!$ObjectType.Contact.fields.Name.Label + IF(orderBy == 'Name', '▼', IF(orderBy == 'Name DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="Name" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputLink value="/{!con.Id}" id="theLink">{!con.name}</apex:outputLink>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!$ObjectType.Contact.fields.Birthdate.Label + IF(orderBy == 'Birthdate', '▼', IF(orderBy == 'Birthdate DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="Birthdate" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputfield value="{!con.Birthdate}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!$ObjectType.Contact.fields.Phone_1__c.Label + IF(orderBy == 'Phone_1__c', '▼', IF(orderBy == 'Phone_1__c DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="Phone_1__c" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputfield value="{!con.Phone_1__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!$ObjectType.Contact.fields.Phone_2__c.Label + IF(orderBy == 'Phone_2__c', '▼', IF(orderBy == 'Phone_2__c DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="Phone_2__c" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputfield value="{!con.Phone_2__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!$ObjectType.Contact.fields.Phone_3__c.Label + IF(orderBy == 'Phone_3__c', '▼', IF(orderBy == 'Phone_3__c DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="Phone_3__c" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputfield value="{!con.Phone_3__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!$ObjectType.Contact.fields.Email_1__c.Label + IF(orderBy == 'Email_1__c', '▼', IF(orderBy == 'Email_1__c DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="Email_1__c" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputfield value="{!con.Email_1__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!$ObjectType.Contact.fields.Email_2__c.Label + IF(orderBy == 'Email_2__c', '▼', IF(orderBy == 'Email_2__c DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="Email_2__c" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputfield value="{!con.Email_2__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!$ObjectType.Contact.fields.Agency_PIN__c.Label + IF(orderBy == 'Agency_PIN__c', '▼', IF(orderBy == 'Agency_PIN__c DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="Agency_PIN__c" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputfield value="{!con.Agency_PIN__c}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!'Record Type' + IF(orderBy == 'RecordType.Name', '▼', IF(orderBy == 'RecordType.Name DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="RecordType.Name" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputfield value="{!con.RecordType.Name}"/>
                </apex:column>
                <apex:column >
                    <apex:facet name="header">
                        <apex:commandLink action="{!updateSortOrderBy}" value="{!$ObjectType.Contact.fields.Client_a_risque__c.Label + IF(orderBy == 'Client_a_risque__c', '▼', IF(orderBy == 'Client_a_risque__c DESC', '▲', ''))}" >
                            <apex:param name="updateOrderBy" value="Client_a_risque__c" assignTo="{!updateOrderBy}"/>
                        </apex:commandLink>
                    </apex:facet>
                    <apex:outputfield value="{!con.Client_a_risque__c}"/>
                </apex:column>
                <!-- the buttons "Link to Case" -->
                <apex:column headervalue="{!$Label.Link_to_Case}">
                    <apex:commandButton value="{!$Label.Link_to_Case}" action="{!linkContactToCase}" rerender="block" oncomplete="openCaseDetails()">
                        <apex:param name="theContactId" value="{!con.Id}" assignTo="{!contactId}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageblockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>


THANK YOU VERY MUCH FOR YOUR HELP.
Best Answer chosen by Nico Anica
Deepali KulshresthaDeepali Kulshrestha
Hi Nico,

You are getting this error because you are not querying this field 'Client_a_risque__c' which is in your Contact Object.
If Contact is your parent object then you should use this 'Contact.Client_a_risque__c' in your query in Controller named 'CCF_searchContactController'.

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com
Malik Butler 5Malik Butler 5 
I have an issue in the debug section it's saying that the ParentRecordType is an unexpected token for service appointments. 
global class ServiceAppointmentCancel implements Database.Batchable<SObject>, Schedulable
{ 
    global Database.QueryLocator start(Database.BatchableContext BC) 
    { 
        String subject = 'Reload,Pre-Trip report,Post-Trip report'; 
        String status = 'O'; 
        Date SchedEndTime = Date.today();
        String ParentRecordType = 'Work Order';
        String ID = 'WorkOrder.ID';
        String query = 'SELECT Subject,Status,SchedEndTime FROM ServiceAppointment WHERE subject = :subject AND status = :status AND SchedEndTime < :SchedEndTime' + 'SELECT ParentRecordType, FROM ServiceAppointment WHERE ParentRecordType = :ParentRecordType AND ID = ID'; 
        return Database.getQueryLocator(query); 
    } 

    global void execute(Database.BatchableContext BC, List<WorkOrder> serviceAppointments) 
    { 
        // Loop to iterate over the service appointments 
        for(WorkOrder service : serviceAppointments)
        
        { 
            service.status = 'C';
        } 
        for(WorkOrder work : serviceAppointments)
        {
            work.status = 'C';
        }
        // Preforming the DML operation 
        update serviceAppointments;
    } 

    global void finish(Database.BatchableContext BC) 
    { } 

    global void execute(System.SchedulableContext SC) 
    { 
        Database.executeBatch(new ServiceAppointmentCancel(), 200); 
    } 
}
Best Answer chosen by Malik Butler 5
Dhanya NDhanya N
Hi Malik,

In this query, no need to concat 2 soql.
'SELECT Subject,Status,SchedEndTime FROM ServiceAppointment WHERE subject = :subject AND status = :status AND SchedEndTime < :SchedEndTime' + 'SELECT ParentRecordType, FROM ServiceAppointment WHERE ParentRecordType = :ParentRecordType AND ID = ID';

Instead add all the conditions in same soql:
'SELECT Subject,Status, SchedEndTime, ParentRecordType FROM ServiceAppointment WHERE subject = :subject AND status = :status AND SchedEndTime < :SchedEndTime AND ParentRecordType = :ParentRecordType AND ID = ID';


Thanks,
Dhanya 
Tom DawsonTom Dawson 
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 


 
Best Answer chosen by Tom Dawson
Soyab HussainSoyab Hussain
Hi Tom Dawson,

We you can't do this, because con.Post_Fulfillments__r this one is an another list.

Incorrect
{!con.Post_Fulfillments__r.Post__r.Floor__c}

Correct
{!con.Post_Fulfillments__r[0].Post__r.Floor__c}

Or we can use another <aura:Iteration> inside the <aura:Iteration> like this.
<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">
                             <aura:Iteration items="{!con.Post_Fulfillments__r}" var="post" >
                                    {!post.Post__r.Floor__c} 
                            </aura:Iteration> place</div>
                    </td>
                </tr>
            </aura:Iteration>



Regards,
Soyab
 
Filip Poverud 4Filip Poverud 4 
FYI:

Challenge not yet complete in DreamHouse
The page does not have the 'showHeader' attribute set to false


If we look at the note in this module:

Beyond the Basics
Note that both the sidebar and showHeader attribute have no effect in Lightning Experience, and that there’s no way to suppress the Lightning Experience header. Although the default value of showHeader is true, it has no effect in Lightning Experience.
The page still includes some Salesforce style sheets, which let you match Salesforce choices for fonts, size, and so on. To suppress all Salesforce output, add standardStylesheets="false" to remove the styles as well.


We see that showHeader is obsolete and there is no reason to add it.

In the challenge it is specified that the standard SalesForce header should not be displayed:

It must NOT display the standard Salesforce header

I assume the module was created for Classic or did I miss something basic regarding this attribute in LE ? I'm currently on SU19.

with Regards
Filip Poverud
Best Answer chosen by Filip Poverud 4
Khan AnasKhan Anas (Salesforce Developers) 
Hi Filip,

Greetings to you!

You are absolutely correct. Visualforce pages always display with the standard Lightning Experience user interface when they run in Lightning Experience. There’s no way to suppress or alter the Lightning Experience header or sidebar. In particular, the showHeader and sidebar attributes of <apex:page> have no effect on Visualforce pages when displayed in Lightning Experience.

However, to pass this particular challenge you need to use showHeader attribute in visualforce page. If you don't use showHeader attribute it won't allow you to pass the challenge.
<apex:page showHeader="false" title="DisplayImage" >
    <apex:image value="https://developer.salesforce.com/files/salesforce-developer-network-logo.png" height="100" width="300" />
</apex:page>

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
CodeBeginnerCodeBeginner 
I am trying to write a trigger for acount field update when coresponding contact field in updated. Please help me here the code is not saving 

Trigger FieldupdateOnAccount on Contact(after insert, after update){
set<id> conset = new set<id>();
for(Contact c: trigger.new){
conset.add(c.id);
}
list<Account> Lstacc = [select Name, Phone(select Name, Phone from Contacts) from Account where Contactid in: conset];
List<Account> Acclist = new List<Account>();
if(Lstacc.size()>0 && Trigger.newMap.get(Id).Phone != Trigger.oldMap.get(Id).Phone){
for(Account acc :Lstacc){
for(Contact c: acc.Contacts){

acc.Phone = c.Phone;
Acclist.add(acc);
}
}
Update Acclist;
}
}
Best Answer chosen by CodeBeginner
Soyab HussainSoyab Hussain
Hi CodeBeginner,
You can try this
Trigger FieldupdateOnAccount on Contact(after insert, after update){
    set<id> accountSet = new set<id>();
    for(Contact conRec : trigger.new){
        if(conRec.AccountId != null){
            accountSet.add(conRec.AccountId);  
        }
    }
    Map<Id, Account> accountMap = new Map<Id, Account>([SELECT Phone FROM Account where Id IN :accountSet]);
    if(accountMap.size()>0 ){
        for(Contact con :Trigger.New){
            if(con.AccountId != null && accountMap.containsKey(con.AccountId) ) {
                Account acc = accountMap.get(con.AccountId);
                acc.Phone = con.Phone; 
                accountMap.put(con.AccountId, acc);
            }
        }
    }
    if(accountMap.size() != 0) {
        update accountMap.values();
    }
}
Regards,
Soyab
 
Sara Phillips 1Sara Phillips 1 
Hi Everyone,

I am new to code and the new Salesforce Administrator foe my company. How do I revise Apex code to include additional lookup for allowed contact based on record type? I would also consider deleting it altogether.

Here is the full error message users are receiving.
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger DealCorrespondenceNoteTrigger caused an unexpected exception, contact your administrator: DealCorrespondenceNoteTrigger: execution of AfterInsert caused by: System.DmlException: Update failed. First exception on row 0 with id a062K00001xpI1TQAU; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Only Contacts from the Account in the Deal Correspondence record are allowed.: [Contact__c]: Class.DealCorrespondenceNoteManager.DealCorrespondenceUpdateNote: line 13, column 1


Thank you for any help you are able to provide. Please advise if additional details are necessary.
Best Answer chosen by Sara Phillips 1
Krishna.AvvaKrishna.Avva
Hi Sara,

Please navigate to Contact object - validation Rules and search for "Only Contacts from the Account in the Deal Correspondence record are allowed" to modify the validationrule/formula.
Agnibha Chakrabarti 10Agnibha Chakrabarti 10 
hi,
my requirement is

 After the batch is over, Teacher will mark the batch as complete. Then the course will be moved from Requested Courses to Completed Coursed for all the students of the batch. Before marking a batch as complete, the teacher can remove any student from the batch. This will not be possible after the batch is completed.
Relationship:
User-added imageim trying to access the students whose batch is completed(batch has a checkbox mark as complete or not)
trigger Batch on Batch__c (before insert,after update) {
    List<String> b= new List<String>();  
     for(Batch__c p: Trigger.new){
         b.add(p.Name);
     }
    List<Student__c> c=new List<Student__c>([select Student__r.Name from Student_Batch_Junction__c where Batch__r.Name in :b]);
    
    
}

I tried to access student in this way..it is showing error
Best Answer chosen by Agnibha Chakrabarti 10
Deepali KulshresthaDeepali Kulshrestha
Hi Agnibha,

Please check below code:
trigger Batch on Batch__c (before insert,after update) {
    List<String> b= new List<String>();  
     for(Batch__c p: Trigger.new){
         b.add(p.Name);
     }
    List<Student_Batch_Junction__c > c=new List<Student_Batch_Junction__c>([select Student__r.Name from Student_Batch_Junction__c where Batch__r.Name in :b]);   
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
www.kdeepali.com