+ Start a Discussion
hjv6606hjv6606 
Hello,

I am trying to accomplish the following:
  • Call an external REST API on Account page load
  • JSON response will be parsed into a table within a custom object
I have already coded the REST call in apex. How do I get this to interact with a custom object and run on page load? Do I need to use visualforce? I am having some trouble understaing how all of these elements interact, so any guidance would be helpful. Thanks!
Best Answer chosen by hjv6606
SRKSRK

no if you are using lightning 

then just create a lighitng componet 

 

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global" > 

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

</aura:component/>

in you JS file

({
    doInit: function(component, event, helper) {
        console.log(component.get("v.recordId"));
        helper.mymethod(component);
     },
})

helper

mymethod: function(component) 
    {
var action = component.get("c.GetAccountInfo");  // call your apex class method 
            action.setParams({
                AccountId : component.get("v.recordId") // pass the paramters 
            });
            action.setCallback(this, function(a) {
                           //handel the responce
                 }
$A.enqueueAction(action);

}

sevindusevindu 
I am getting this error when using ANT.

UserName:lwcdx@lwcdx.com
Password:Test@123

"Invalid username, password, security token; or user locked out"

Plz help
Best Answer chosen by sevindu
Uttpal_ChandraUttpal_Chandra
Hi sevindu,

Try resting you security token and also make sure your pointing to the correct environment (test.salesforce.com if you're deploying to a sandbox or login.salesforce.com if you're pointing to production)
Jan Kopejtko 2Jan Kopejtko 2 
Hey guys,

could anybody tell me or send me a link to documentation where it says what fires first?

In my org I have Apex triggers, processes, validation rules, workflow rules. What does fire first and what last? Is there some kind of system?

Thank you
Best Answer chosen by Jan Kopejtko 2
GovindarajGovindaraj
Hi Jan,

Below link will be helpful to understand execution order,
https://sfdcpanther.wordpress.com/2017/10/11/triggers-and-order-of-execution-salesforce/

In general, the execution order is like below,
1. System validation
2. Before triggers
3. Custom validation
4. Duplicate rules
5. Data get commited but not saved
6. After triggers
7. Assignment rules
8. Auto response rules
9. Workflow rules, if there is any field update then Before and After triggers get executed again
10. Process builder
........
15. Commits the data into DB
16. Post commit logic

Thanks,
Govindaraj.S
Kal KumarKal Kumar 
I am trying to understand why I cannot query the 'Notes' object directly, but can only use it via the Account relationship.

Below query does not work.
select CreatedBy.Name from Notes.

But this query works
select Name, (select CreatedBy.Name from Notes) from Account
Best Answer chosen by Kal Kumar
Khan AnasKhan Anas (Salesforce Developers) 
Hi Kal,

Greetings to you!

You need to use Note instead of Notes.
SELECT CreatedBy.Name FROM Note

In relationship queries, you need to use Child Relationship Name. Notes is the child relationship name. So, for Parent-Child relationship query you have to use below SOQL:
SELECT Name, (SELECT CreatedBy.Name FROM Notes) FROM Account

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
KARIM EL ALAOUIKARIM EL ALAOUI 
I have been configuring ligthning component and its gone well so far. However I am struggling to find out why the new component doesnt display information, we have reclamation custom objet with lookup relation with contact and I need to display all relamations related to a contact in ligthning component under contact, see bellow all config:

ReclamationListController.apxc
public class ReclamationListController {
        
    @AuraEnabled
    public static List<Reclamation__c> getReclamationList(List<Id> contactIds) {
                List<Reclamation__c> reclamationList = [SELECT Id, Name, Type__c, Description__c, Contact__c FROM Reclamation__c WHERE Contact__c in :contactIds];
        return reclamationList;
    }
}
**************************************************
ReclamationList.cmp

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" controller="ReclamationListController" access="global" >
    <!-- Handler to call function when page is loaded initially -->
    <aura:handler name="init" action="{!c.getReclamationsList}" value="{!this}" />
    <aura:attribute name="reclamationList" type="List" />
        <lightning:card title="Reclamations">
        <p class="slds-p-horizontal_small">       
            <aura:iteration items="{!v.reclamationList}" var="reclamation"> 
                <lightning:recordViewForm recordId="{!reclamation.Id}" objectApiName="Reclamation__c">
                    <div class="slds-box slds-theme_default">
                        <lightning:outputField fieldName="Name" />
                        <lightning:outputField fieldName="Type__c" />
                        <lightning:outputField fieldName="Description__c" />
                    </div>             
                </lightning:recordViewForm>
                <br />
            </aura:iteration>
        </p>

        <aura:set attribute="actions">
            <lightning:button label="New" onclick="{!c.newReclamation}" />
        </aura:set>
    </lightning:card>
</aura:component>
**************************************************************
ReclamationsListController.js

({

        getReclamationsList : function(component, event, helper) {

                helper.fetchReclamations(component, event, helper);
        },

    newReclamation: function(component, event, helper) {
        var createReclamation = $A.get("e.force:createRecord");
        createReclamation.setParams({
            "entityApiName": "Reclamation__c",
            "defaultFieldValues": {
                "Contact__c": component.get("v.recordId")
            }
        });
        createReclamation.fire();
    }
})

*****************************************
ReclamationsListHelper.js

({
        fetchReclamations : function(component, event, helper) {
        var action = component.get("c.getReclamationList");
        var contactId = component.get("v.recordId");
        action.setParams({
            contactIds: contactId

        });

        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === 'SUCCESS') {

                var reclamationList = response.getReturnValue();

                component.set("v.contactList",reclamationList);
            }
            else {
                alert('Error in getting data');
            }
        });
        $A.enqueueAction(action);
        }    
})


*********

Thank you for your halp
Best Answer chosen by KARIM EL ALAOUI
Nayana KNayana K
component.set("v.contactList",reclamationList); line should be
changed to component.set("v.reclamationList",reclamationList);
Homelike DevelopmentHomelike Development 
I would like to query the account history where I am excluding certain account record types.

I am developing the query in Workbench and am currently using the Workbench SOQL query tab.

As a first step I tried to get the Account.RecordTypeId, but neither of the following worked (after allowing for querying parent-child relationships in settings):
 
SELECT AccountId.RecordTypeId FROM AccountHistory LIMIT 10
Fails with: "Didn't understand relationship 'AccountId' in field path."
 
SELECT AccountId__r.RecordTypeId FROM AccountHistory LIMIT 10
Fails with: "Didn't understand relationship 'AccountId__r' in field path."
 
SELECT AccountId.RecordTypeId__r FROM AccountHistory LIMIT 10
Fails with: "Didn't understand relationship 'AccountId' in field path."

Ultimately I am using the query to get data via the python package Simple Salesforce. Alternative approaches are also welcome.






 
Best Answer chosen by Homelike Development
SarvaniSarvani
Hi,

Sorry my bad, please paste the below query format in the workbench and try.
Select Accountid,
Account.name,
Account.recordtypeId
From Accounthistory where 
account.RecordtypeId!=‘012580000004SxCAAU'
Please refer to the similar link below
https://developer.salesforce.com/forums/?id=9060G000000BdqcQAC

Hope this helps, please mark as solved if it does

Thanks
XK ReyesXK Reyes 
I'm trying to achieve a 100% coverage but I'm only getting 71%. Lines 7-8 on the AccountProcessor class are uncovered by my test class. Any ideas?.

AccountProcessor Class
public class AccountProcessor {
    @future
    public static void countContacts(List<Id> accountIds) {
        List<Account> acctsToUpdate = new List<Account>();
        for (Account a : [SELECT Id, (SELECT Id FROM Contacts) FROM Account
                        WHERE Id IN: accountIds]){
            a.Number_of_Contacts__c = a.Contacts.size();
            acctsToUpdate.add(a);                                            
        }
        update acctsToUpdate;
    }
}
AccountProcessor Test Class
@isTest
public class AccountProcessorTest {
    @isTest 
    public static void testCountOfContacts() {
        List<Account> newAccts = new List<Account>();
        List<Contact> newConts = new List<Contact>();
        
        for(Integer x=0;x>5;x++) {
            newAccts.add(new Account(Name='New Account '+x));
        }
        insert newAccts;

        for(Account a:newAccts) {
            for(Integer y=0;y>2;y++){
                newConts.add(new Contact(LastName=a.Name+y,
                                         AccountId=a.Id));
            }
        }
        insert newConts;

        List<Id> accountIds = new List<Id>(new Map<Id,Account>(newAccts).keySet());

        Test.startTest();
            AccountProcessor.countContacts(accountIds);
        Test.stopTest();
        
        for(Account a: [SELECT Id, Number_of_Contacts__c FROM Account
                        WHERE Id IN: accountIds]){
        System.assertEquals(2, a.Number_of_Contacts__c);
        }
    }
}

 
Best Answer chosen by XK Reyes
SarvaniSarvani
Hi,

Please change your test class to the below code:
@isTest
public class AccountProcessorTest {
    @isTest 
    public static void testCountOfContacts() {
        List<Account> newAccts = new List<Account>();
        List<Contact> newConts = new List<Contact>();
        
        for(Integer x=0;x<5;x++) {
            newAccts.add(new Account(Name='New Account '+x));
        }
        insert newAccts;
        system.debug(newAccts.size());

        for(Account a:newAccts) {
            for(Integer y=0;y<2;y++){
                newConts.add(new Contact(LastName=a.Name+y,
                                         AccountId=a.Id));
            }
        }
        insert newConts;

        List<Id> accountIds = new List<Id>(new Map<Id,Account>(newAccts).keySet());

        Test.startTest();
            AccountProcessor.countContacts(accountIds);
        Test.stopTest();
        
        for(Account a: [SELECT Id, Number_of_Contacts__c FROM Account
                        WHERE Id IN: accountIds]){
        System.assertEquals(2, a.Number_of_Contacts__c);
        }
    }
}
Explanation: I changed the for loop condition to x<5 where its creating accounts in your code. The for loop in previous test class will never execute as the x=0  and it is not greater than 5. It comes out of the loop and accounts are not created same with contacts for loop. 

Your code should get 100% coverage now. I tested it

Hope this helps! Please mark as best if it answers your problem.

Thanks
Mohan Babu K JMohan Babu K J 
Hello,
I'm not able to connect my org with my salesforce credential. It was working fine until sometime back I was getting message to merge the account and something got messed up. I'm not able to verify my challenge. Please let me know how it can be resolved

Thanks.
Best Answer chosen by Mohan Babu K J
Khan AnasKhan Anas (Salesforce Developers) 
Hi Mohan,

Greetings to you!

I suggest you please reach out to the Trailhead support team for better and quick assistance on the above issue.

Please refer below link to open a case:
https://trailhead.salesforce.com/help?support=home

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
Weber Sales SupportWeber Sales Support 
I am new to this kind of formula field and I am having issues with this formula not applying the requested values to the different pick list  options on multiple fields:

CASE( Store_in_Prime_Location__c , "Perfect location within strategic plan" ,20, "Good Area outside defined plan",10,0 ) +
CASE( Prepared_to_Relocate__c , "Yes this is the preferred location", 10 ,"Not the Prefered Location see Dealer Review file for further information",0, 0) +
CASE( External_Signage__c , "Average", 5, "Good", 10, "Outstanding" , 15 ,0) +
CASE( Rate_the_Street_Frontage__c , "Mid to small frontage with limited improvement possible", 5, "Mid-range frontage with potential to improve visibility", 10, "Strong Street Presence Clearly visible with high traffic", 15 , "Large Frontage 2 sides highly visible to all traffic" , 20 , 0) +
CASE( How_many_carparks_available__c , "Minimal Car Parking easily accessible", 5, "Ample Car Parks easily accessible", 10,0) +
CASE(Property_Status__c , "Owned", 5, 0)

I am hoping someone can point me in the right direction as I am lost as to where I am going wrong.
Best Answer chosen by Weber Sales Support
SarvaniSarvani
Hi Weber,

Can you please verify if your picklist field values for  'preferred location' and the 'street frontage'  are having correct API names in the formula.

Hope this helps! 

Thanks
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();
                   countHeader=0;
                   
                   count=count+1;
                  Decimal Sum=0;
                   
                                    invoiceJournWrapper.id=String.valueof(invoice.id);
                                    invoiceJournWrapper.HeaderKey=String.valueof(count);
                                    invoiceJournWrapper.ZCurrency=(invoice.CurrencyIsoCode!=null?invoice.CurrencyIsoCode:'USD');
                                    //invoiceJournWrapper.AccountingJournal='null';
                                    invoiceJournWrapper.AccountingJournalID=String.valueOf(invoice.Name + '_' +myDate);
                                    invoiceJournWrapper.JournalNumber=String.valueOf(invoice.Name + '_' +myDate);
                                    invoiceJournWrapper.ExternalReferenceID=String.valueOf(invoice.Name);                  
                                    invoiceJournWrapper.AccountingDate=String.valueof(Date.valueof(invoice.Apttus_Billing__InvoiceDate__c));
                  //-------------------
                  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,
                                                                      Apttus_Billing__Type__c,Apttus_Billing__InvoiceId__c,Name,Apttus_Billing__Amount__c,Apttus_Billing__SoldToAccountId__r.EQ_ClientRef__c,Apttus_Billing__LocationId__c,
                                                                      Apttus_Billing__ProductId__r.EQ_FeeCode__c,Apttus_Billing__BillToAccountId__r.EQ_ClientRef__c,Apttus_Billing__ProductId__r.ProductCode,Apttus_Billing__InvoiceId__r.EQ_TotalInvoiceAmount__c 
                                                             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();
                            countHeader=countHeader+1;
                            FirstInvItems.LineKey=string.valueof(countHeader);

 
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!