+ Start a Discussion
Alex LazarevAlex Lazarev 
Hello guys,

I'm doing a Trigger, but since I have short experience I need some help please. I have the following Trigger that shoots when there is an attemp of insert into the custom Object. This works fine for a new record. But the logic that I'm missing is for bulk of Inserts where my Company told me that we should take the SELECT out of the loop and first build a list of the IDs and then run a single query with
IN : varibleWithIds

Here is my piece of code, how can I take the queries out of the 'for' statement and do a single 'SELECT' for the List of ids??
 
trigger AddOnlyVehiclesInStock on Order_Item__c (before insert) {
    
    // String to storage vehicle type
    Set<String> orderVehicle = 	New Set<String>();
    
    // Going through the Order_Item__c object to assign the field data to the variable orderVehicle
    for(Order_Item__c o : Trigger.New){
        orderVehicle.add(o.Vehicle_Type__c);
        
        System.debug('1-- Order_Item__c.Vehicle_Type__c: ' + orderVehicle);	
        
        	// Getting Name and quantity of the searched vehicle -- This should get the List of IDs and not loop inside a FOR
            List<Vehicle__c> v = [SELECT Name,Quantity__c FROM Vehicle__c Where Name IN : orderVehicle];
            for(Vehicle__c ve : v){
                System.debug('2-- Vehicle query debug: ' + ve);
                
                // If the vehicle that we are trying to add to the order has less than 1 in stock
                // then we cannot add it.
                System.debug('3-- Vehicle quatity: ' + ve.Quantity__c);
                
                if(ve.Quantity__c < 1){
                    o.addError('Cannot add to order vehicles without stock');
                }
            }
    }
}

Thank you!
Best Answer chosen by Alex Lazarev
Ashish DevAshish Dev
Hi Alex,

Simply take query and inner for loop out of outer for loop. It will be like. 
trigger AddOnlyVehiclesInStock on Order_Item__c (before insert) {
    
    // String to storage vehicle type
    Set<String> orderVehicle = 	New Set<String>();
    
    // Going through the Order_Item__c object to assign the field data to the variable orderVehicle
    for(Order_Item__c o : Trigger.New){
        orderVehicle.add(o.Vehicle_Type__c);
        
        System.debug('1-- Order_Item__c.Vehicle_Type__c: ' + orderVehicle);	
        
        	// Getting Name and quantity of the searched vehicle -- This should get the List of IDs and not loop inside a FOR

    }
	List<Vehicle__c> v = [SELECT Name,Quantity__c FROM Vehicle__c Where Name IN : orderVehicle];
	for(Vehicle__c ve : v){
		System.debug('2-- Vehicle query debug: ' + ve);
		
		// If the vehicle that we are trying to add to the order has less than 1 in stock
		// then we cannot add it.
		System.debug('3-- Vehicle quatity: ' + ve.Quantity__c);
		
		if(ve.Quantity__c < 1){
			o.addError('Cannot add to order vehicles without stock');
		}
	}
}

Let me know if this solves your problem.
Stephen SiggsStephen Siggs 
I am getting the following error trying to Upsert to Product2: INVALID_FIELD: Field name provided, ProductCode does not match an External ID, Salesforce id, or indexed field for Product2.

ProductCode is definitely a field and it is showing as being indexed in the App Setup, Customize, Products area. What am I doing wrong!?

Note: using the SalesForce default sandbox setup - no customisations have been made.

I am sure that this is a daft newbie question, but I've been searching for ages and can't find an answer myself or an example of using upsert for Product2 that answer the question. Thanks in advance!
Best Answer chosen by Stephen Siggs
Ashish DevAshish Dev
Hi Stephen,
Upsert can be only used with ID, External ID or field having idLookup = true. ProductCode is not having idLookup = true, neither ID field nor External id hence can not be used for matching.
DaveFFDaveFF 
I have the following code in a trigger on Account (after update). It's a bit of a hack because I want certain formula fields on certain Contacts to sync to Mailchimp, so their last modified date needs to be touched. I'm now (a week or two later) unable to Update a new field on Opportunities using the Data Loader, as an error down the chain of triggers says "System.QueryException: Non-selective query against large object type (more than 200000 rows)" for this.
List<Contact> teachers = [
    SELECT Id
      FROM Contact
     WHERE AccountId IN :schoolIds
       AND RecordType.DeveloperName LIKE 'Client%'
       AND Account.RecordType.DeveloperName = 'School_or_College'
  ];
The query should only ever return less than 100 rows. The table contains ~215k rows. I guard against emptiness or presence of nulls in schoolIds, which should be a very small set (most likely only 1). Consulting this cheat sheet and Setup/Customize/Contacts/Fields, I note that lookups and record types are indexed. I don't see any of the automatic exceptions to index selectivity- I'm tempted to suspect the LIKE clause but the wildcard is at the end.

Why is this query non-selective, and what can I do to make it better? (Using record type IDs rather than DeveloperNames? Splitting out the last WHERE clause into a separate preliminary query?)
Best Answer chosen by DaveFF
Amit Singh 1Amit Singh 1
Yes, that means it's taking too long.  A couple ways to get more CPU time are to put the code in an @future method (you get 60 seconds of CPU instead of just 10 seconds), or implement it as a Batch Apex job.  Since both of these methods are asynchronous, the trigger and associated DML will complete before the calls to the AccountServices methods are made - but they will be called eventually.  Would this work for you?
https://help.salesforce.com/articleView?id=000002493&type=1

Let me know if this helps :)

Thanks!
Amit Singh
Shridhar H AShridhar H A 
i have a 100 users and i have their date of birth with a field name DOB...suppose if i want to Wish them on their birthday what should i do...?
Best Answer chosen by Shridhar H A
Rahul kumarRahul kumar
Hi Shridhar,
Please check the below document provided by salesforce help. for further reference. I hope it will be helpful.

BestRegards 
RahulKumar.
CushtyCushty 
Hi,

What am I missing fro this test class to get the % code coverage up.

I am an admin and have the below trigger which after an opportunity is set to won will update the contact role.  Its a bit long winded but what it does is count the type of product thats selected on the opportunity and then update the corresponding checkbox on the contact role once the opportunity is set to won

TRIGGER
trigger UpdateContactProduct on Opportunity (after update) {

   Set<Id> st_OppId = new Set<Id>();
List<Contact> con_List;

for(Opportunity opp :Trigger.new)
  {
     if(opp.StageName=='Won' )
         st_OppId.add(opp.id);
 }

if(st_OppId!=null && !st_OppId.isEmpty())
    {

         for(OpportunityContactRole iterating_oppConRole : [SELECT Role, 
                                                                      OpportunityId, 
                                                                      IsPrimary, 
                                                                      Id, 
                                                                      ContactId,
                                                                      Contact.Lead_Lifecycle_Stage__c ,
                                                                      Contact.X1Edit_bought__c, 
                                                                      Contact.X1Exchange_bought__c,         
                                                                      Opportunity.Count_1Edit__c,
                                                                      Opportunity.Count_1Exchange__c,
                                                                   FROM OpportunityContactRole  where OpportunityId IN : st_OppId])
                               {

                    if(iterating_oppConRole.Opportunity.Count_1Edit__c > 0)
                        {
                              iterating_oppConRole.Contact.X1Edit_bought__c = true;
                        }
                                             
                    if(iterating_oppConRole.Opportunity.Count_1Exchange__c> 0)
                        {
                              iterating_oppConRole.Contact.X1Exchange_bought__c = true;
                        }
                                           if(con_List == null)
                                           con_List = new List<Contact>();

                                          con_List.add(iterating_oppConRole.Contact);
                                }

               
           }
        
        if(con_List!=null && !con_List.isEmpty())
            update con_List;
}

TEST CLASS
@IsTest

Public Class testAddProductsBought
 {
    static testMethod void ValidateContactProduct()
    {
    
    Account a = new Account();
    a.Name ='demo';
    a.Industry = 'Education';
    a.BillingCountry = 'United Kingdom';
    insert a;
    
    
    Contact c = new Contact();
    c.FirstName = 'Lord';
    c.LastName = 'Test2';
    c.Accountid = a.id; 
    c.RecordTypeid = '012w000000063q6AAA';
    insert c;
    
    
    Contact ci = new Contact();
    ci.FirstName = 'Bob';
    ci.LastName  = 'Test';
    ci.AccountId = a.id;
    ci.RecordTypeid = '012w000000063q6AAA';
    insert ci;
    
    
    Opportunity o = new Opportunity();
    o.AccountId = a.Id;
    o.StageName = 'Won';
    o.RecordTypeid = '012w0000000ic3mAAA';
    o.Final_Price_Number__c = 2000;
    o.Business_Unit__c = '1Spatial United Kingdom';
    o.Name = 'Test';
    o.Opportunity_Type__c = 'Contract Renewal';
    O.CurrencyIsoCode ='GBP';
    o.Contract_Type__c = 'Framework';
    o.Estimated_Value_Number__c = 10000;
    o.Opportunity_Submission_Date__c = Date.TODAY();
    o.CloseDate = Date.TODAY() +2;
    o.Probability__c = '80-99%';
    o.Purchase_Order__c = '2L3454';
    o.Solution_Summary__c = 'Hardware';
    o.Description = 'Update Contact role';
    o.Opportunity_Process_Stage__c= 'Opportunity Submitted to Customer: Approved`';
    o.Ownerid = '005w0000004ExSiAAK';
    insert o;
    
        
     OpportunityContactRole cr = new OpportunityContactRole();
     cr.Opportunityid = o.id;
     cr.Role = 'Administrator';
     cr.Contactid = c.id;
     cr.IsPrimary = true;
     insert cr;
     
     OpportunityContactRole ocr1 = new OpportunityContactRole();
     ocr1.ContactId = ci.Id;
     ocr1.OpportunityId = o.Id;
     ocr1.IsPrimary = FALSE;
     ocr1.Role = 'Decision Maker';
     insert ocr1;
     
    
     Id pricebookId = Test.getStandardPricebookId();
     Product2 prod = new Product2();
     prod.Name = 'Product 2';
     prod.ProductCode = 'Pro-2';
     prod.isActive = true;
     prod.Revenue_Type__c = 'Services';
     prod.Product_Heading__c = '1Edit';
     insert prod;

     PricebookEntry pbEntry = new PricebookEntry();
     pbEntry.Pricebook2Id = pricebookId;
     pbEntry.Product2Id = prod.Id;
     pbEntry.UnitPrice = 100.00;
     pbEntry.IsActive = true;
     insert pbEntry;

     OpportunityLineItem oli = new OpportunityLineItem();
     oli.OpportunityId = o.Id;
     oli.quantity = 1;
     oli.PricebookEntryId = pbEntry.Id;
     oli.TotalPrice = oli.quantity * pbEntry.UnitPrice;
     insert oli;

    o.StageName = 'Won';
    update o;
    update cr;

}
}
Best Answer chosen by Cushty
AnjunaAnjuna
Hi Cushty,
You haven't specified the field values for Count_1Edit__c,Count_1Exchange__c in your test class. It will cover the class only if the value of these fields are greater than 0. So update these fields with values greater than zero while inserting opportunity record.
 
mukesh guptamukesh gupta 
Hi Expert,

I am creating Custom signup form   from this  url "https://github.com/salesforceidentity/basic-custom-login"  but i am not getting what is "fieldpath" and "dbrequired". if these are registration form field then what field type i need to create.


 
<apex:repeat value="{!$ObjectType.User.FieldSets.Registration}" var="f">  
           <div class="form-group">
               <div class="col-md-4"></div>
               <div class="col-md-4">
                   <apex:inputField value="{!User[f]}" styleClass="form-control reg_{!f.fieldpath}"  onfocus="$('#req_{!f.fieldpath}').fadeIn();"/> 
                </div>
                <div class="col-md-4"><apex:outputText rendered="{!f.dbrequired}"><span id="req_{!f.fieldpath}" style="display:none;color:red;">required</span></apex:outputText></div>
            </div>
            </apex:repeat>

Thanks
Mukesh
Best Answer chosen by mukesh gupta
Amit Singh 1Amit Singh 1
Hello Mukesh,
DBRequired -  Indicates whether the field is required for the object
FieldPath - Lists the field’s spanning info

Refer below link for more info.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_dynamic_vf_field_sets.htm

Let me know if this helps:)

Thanks!
Amit Singh
Apoorv Jain 14Apoorv Jain 14 
Hi ,

I was able to create a lighting component for creating a new record and a separate component for uploading file, but not able to merge these two components like on the single form able to enter the information and attach the file and on save button  it will save the record with the attachment and display the details.

can please someone help me out for the same 
 
Thanks in advance.
Best Answer chosen by Apoorv Jain 14
NagendraNagendra (Salesforce Developers) 
Hi Apoorv,

Well, attachments are not directly related with your object. You first need to create a new record and then create the attachment.

Attachments have one parameter to relate each one with your object. Once you inserted a new record of your object, you have to create an attachment, to relate it to your object you just need to put your record id on attachment's ParentId, this field is the one that relates the attachment with your current object record.

Hope this helps.

Best Regards,
Nagendra.
 
Apex developer 21Apex developer 21 
public class BatchDossierInvoice implements Database.Batchable<sObject>,Schedulable  {

    public void execute(SchedulableContext SC) {
       Database.executeBatch(new BatchDossierInvoice(), 200); 
    }

    public Database.QueryLocator start(Database.BatchableContext info){
system.debug('line 3');  
     try{
       
                    String query = 'SELECT Id ,(SELECT Id , Betaald_max__c ,Betaald__c,Partij__c,Partij__r.AccountId '+
                                    'FROM Partijen__r ORDER BY Betaald__c DESC ), '+
                                    '(SELECT Id , Dossier__c,Totaal_Merlijn__c '+
                                    'FROM Declaraties__r) '+
                        'FROM Dossier__c '+
                        'WHERE Id IN (SELECT Dossier__c FROM Declaratie__c) '+
                        'AND createddate >= LAST_N_DAYS:30';
         
         
     
         return Database.getQueryLocator(query); 
         system.debug(query);
         
        }catch(Exception e ){
         
            System.debug('The following exception has occurred' + e.getMessage());
        } 
        return null;                    
    }
   
    public void execute(Database.BatchableContext bc, List<Dossier__c> dossierList){     
        
        if(!dossierList.IsEmpty() && dossierList != null){
            List<Facturatie__c> facturatieList = new List<Facturatie__c>();    
            
            for(Dossier__c dossierRecord : dossierList){              
                Decimal totalAmount = 0;
                Decimal UpdatedtotalAmount = 0;
                
                // calculate sum Totaal_Merlijn__c of Declaratie__c records     
                for(Declaratie__c DeclaratieRecord : dossierRecord.Declaraties__r){    
                    totalAmount = totalAmount + DeclaratieRecord.Totaal_Merlijn__c;
                }
 system.debug(totalAmount);               
                
                

                if(totalAmount != 0){                   
                    // Find Inkoop_Uren__c record having maximun Betaald_max__c  
                    Partij__c partijMaxBetaaldValue = dossierRecord.Partijen__r[0];
                    for(Partij__c partijRecord : dossierRecord.Partijen__r){                                          
                        if(   partijRecord.Betaald_max__c != null && partijMaxBetaaldValue.Betaald_max__c !=null
                           && partijRecord.Betaald_max__c >= partijMaxBetaaldValue.Betaald_max__c){                              
                            partijMaxBetaaldValue.Betaald_max__c = partijRecord.Betaald_max__c;
                        }                                           
                    }
                    
                    // Find Partij__c record having maximun Betaald_max__c create Facturatie__c 
                    if( partijMaxBetaaldValue != null){
                        Facturatie__c  facturatieRecord;
                        if(totalAmount <= partijMaxBetaaldValue.Betaald_max__c){
                            facturatieRecord = CreateInvoice(partijMaxBetaaldValue ,dossierRecord,totalAmount);
                            UpdatedtotalAmount =0;
                        }else{
                            facturatieRecord = CreateInvoice(partijMaxBetaaldValue ,dossierRecord,partijMaxBetaaldValue.Betaald_max__c);
                            UpdatedtotalAmount = totalAmount - partijMaxBetaaldValue.Betaald_max__c;
                        }
                        if(facturatieRecord != null){
                            facturatieList.add(facturatieRecord);
                        } 
                    }
                    
                    // For reaming record create Facturatie__c on basis of having maximun Betaald__c  
                    for(Partij__c partijRecord : dossierRecord.Partijen__r){                  
                        if(    partijMaxBetaaldValue != partijRecord && UpdatedtotalAmount != 0 
                            && partijRecord.Betaald__c != null && partijRecord.Betaald_max__c != null && UpdatedtotalAmount >= 0){
                            Double invoiceAmount =(totalAmount*(partijRecord.Betaald__c/100));
                            UpdatedtotalAmount = UpdatedtotalAmount - invoiceAmount;
                            
                            Facturatie__c  facturatieRecord = CreateInvoice(partijRecord,dossierRecord,invoiceAmount );                            
                            if(facturatieRecord != null){
                                facturatieList.add(facturatieRecord);
                            }                            
                        }
                    }
                }       
            }
            
            // insert newly created Facturatie__c records 
            if(!facturatieList.IsEmpty()){
system.debug('line 19'); 
                try { 
system.debug('line 20');  
                   database.insert(facturatieList,false);
                   System.debug('facturatieList'+facturatieList);
                }catch(Exception e ){
system.debug('line 21'); 
                     System.debug('The following exception has occurred' + e.getMessage() );
                } 
            }
        } 
    }
   
    // Create invoice records
    public Facturatie__c  CreateInvoice(Partij__c partijRecord,Dossier__c dossierRecord,Decimal invoiceAmount){
system.debug('line 22');        
        if(partijRecord != null && dossierRecord != null && invoiceAmount != null ){
system.debug('line 23');                       
            Facturatie__c facturatieRecord = new Facturatie__c();
            facturatieRecord.Dossier__c = dossierRecord.Id;
            facturatieRecord.Factuur_Datum__c = System.today();
            facturatieRecord.Verval_datum__c =  System.today().addDays(30);
            facturatieRecord.Factuur_Bedrag__c = invoiceAmount; 
            facturatieRecord.Contactpersoon__c = partijRecord.Partij__c;    
            facturatieRecord.Account__c = partijRecord.Partij__r.AccountId;   
                      
            return facturatieRecord;                                 
        } 
        return null;           
    }
    
    public void finish(Database.BatchableContext BC){
system.debug('line 24');        
    }
     
}
 
@isTest
public class BatchDossierInvoiceTestClass{
    @testSetup
    // Creating Test Data
    public static  void testData(){

        Account account = new Account(Name = 'TestAccount1');
        insert account;

        List<Dossier__c> dossierList = new List<Dossier__c>();
        for(integer counter=0;counter<200;counter++){

            Dossier__c dossierRecord = new Dossier__c();
            dossierRecord.Name = 'TestRecord'+counter;
            dossierRecord.Status__c = 'Klant';
            dossierRecord.Partijen__c = 'een team';
            dossierRecord.Datum_eerste_gesprek__c = System.today();
            dossierList.add(dossierRecord);
        }
        insert dossierList;

        List<Partij__c> partijList = new List<Partij__c>();
        for(integer counter=0;counter<200;counter++){
            Partij__c partijRecord = new Partij__c();
            partijRecord.Dossier__c = dossierList[counter].Id;
            partijRecord.Betaald_max__c = 100;
            partijRecord.Betaald__c = 10;
            partijList.add(partijRecord);
        }
        insert partijList;

        List<Partij__c> partijList2 = new List<Partij__c>();
        for(integer counter=0;counter<200;counter++){
            Partij__c partijRecord = new Partij__c();
            partijRecord.Dossier__c = dossierList[counter].Id;
            partijRecord.Betaald_max__c = 0;
            partijRecord.Betaald__c = 10;
            partijList2.add(partijRecord);
        }
        insert partijList2;

        List<Declaratie__c> DeclaratieList = new List<Declaratie__c>();
        for(integer counter=0;counter<200;counter++){
            Declaratie__c DeclaratieRecord = new Declaratie__c();
            DeclaratieRecord.Dossier__c =  dossierList[counter].Id;
            //DeclaratieRecord.Totaal_Merlijn__c = Totaal_Reisuren_Merlijn_new__c + Totaal_Reiskosten_Melijn_new__c + Totaal_Uren_Merlijn__c;
            DeclaratieList.add(DeclaratieRecord);
        }
        insert DeclaratieList;

    }@istest

    public static void  testschedule() {

        Test.StartTest();
        System.schedule('Scheduled Job 2', '0 0 * * * ?', new BatchDossierInvoice ());
        dateTime dt=System.now().addMinutes(1);
        String Csec,Cmin,Chr,Cday,Cmonth,CYear;
        Csec=String.valueof(dt.second());
        Cmin=String.valueof(dt.minute());
        Chr=String.valueof(dt.hour());
        Cday=String.valueof(dt.day());
        Cmonth=String.valueof(dt.month());
        CYear=String.valueof(dt.Year());
        String SchTimer=Csec+' '+Cmin+' '+Chr+' '+Cday+' '+Cmonth+' ? '+CYear;
        system.debug('*************SchTimer:'+SchTimer);
        BatchDossierInvoice  cas = new BatchDossierInvoice  ();
        system.schedule('Scheduler02: Running at', SchTimer, cas);
        Test.stopTest();
    }
}

 
Best Answer chosen by Apex developer 21
Apex developer 21Apex developer 21
Got it working! Was missing some testobjects. Here is the solution 89% coverage:
@isTest
public class BatchDossierInvoiceTestClass{
    @testSetup
    // Creating Test Data
    public static  void testData(){

        Account account = new Account(Name = 'TestAccount1');
        insert account;

        List<Dossier__c> dossierList = new List<Dossier__c>();
        for(integer counter=0;counter<200;counter++){

            Dossier__c dossierRecord = new Dossier__c();
            dossierRecord.Name = 'TestRecord'+counter;
            dossierRecord.Status__c = 'Klant';
            dossierRecord.Partijen__c = 'een team';
            dossierRecord.Datum_eerste_gesprek__c = System.today();
            dossierList.add(dossierRecord);
        }
        insert dossierList;

        List<Partij__c> partijList = new List<Partij__c>();
        for(integer counter=0;counter<200;counter++){
            Partij__c partijRecord = new Partij__c();
            partijRecord.Dossier__c = dossierList[counter].Id;
            partijRecord.Betaald_max__c = 100;
            partijRecord.Betaald__c = 10;
            partijList.add(partijRecord);
        }
        insert partijList;

        List<Partij__c> partijList2 = new List<Partij__c>();
        for(integer counter=0;counter<200;counter++){
            Partij__c partijRecord = new Partij__c();
            partijRecord.Dossier__c = dossierList[counter].Id;
            partijRecord.Betaald_max__c = 0;
            partijRecord.Betaald__c = 10;
            partijList2.add(partijRecord);
        }
        insert partijList2;

        List<Declaratie__c> DeclaratieList = new List<Declaratie__c>();
        for(integer counter=0;counter<200;counter++){
            
            Declaratie__c DeclaratieRecord = new Declaratie__c();
            DeclaratieRecord.Dossier__c =  dossierList[counter].Id;
            DeclaratieList.add(DeclaratieRecord);
        }
        insert DeclaratieList;
        
        
        List<Declaratie_Line_Item__c> DeclaratieLineItem = new List<Declaratie_Line_Item__c>();
        for(integer counter=0;counter<200;counter++){
            Declaratie_Line_Item__c DeclaratieLineRecord = new Declaratie_Line_Item__c();
            DeclaratieLineRecord.Aantal_Minuten__c = 100;
            DeclaratieLineRecord.Declaratie__c = DeclaratieList[counter].id;
            DeclaratieLineRecord.Directe_Bestede_Uren_Tarief_Merlijn__c = 1000;
            DeclaratieLineItem.add(DeclaratieLineRecord);
        }
        insert DeclaratieLineItem;
        

    }@istest

    public static void  testschedule() {

        Test.StartTest();
        System.schedule('Scheduled Job 2', '0 0 * * * ?', new BatchDossierInvoice ());
        dateTime dt=System.now().addMinutes(1);
        String Csec,Cmin,Chr,Cday,Cmonth,CYear;
        Csec=String.valueof(dt.second());
        Cmin=String.valueof(dt.minute());
        Chr=String.valueof(dt.hour());
        Cday=String.valueof(dt.day());
        Cmonth=String.valueof(dt.month());
        CYear=String.valueof(dt.Year());
        String SchTimer=Csec+' '+Cmin+' '+Chr+' '+Cday+' '+Cmonth+' ? '+CYear;
        system.debug('*************SchTimer:'+SchTimer);
        BatchDossierInvoice  cas = new BatchDossierInvoice  ();
        system.schedule('Scheduler02: Running at', SchTimer, cas);
        Test.stopTest();
    }
}

 
Stephen Wood 5Stephen Wood 5 
Is it possible to have the REST API return the value of a formula field when creating a record? I know that the payload returns the record ID, but would like other field values returned as well in order to not have to make a second call. For example the response body for a new account might look like:
 
{
  "id" : "001D000000IqhSLIAZ",
  "errors" : [ ],
  "success" : true
  "Formula_field__c" : "Formula field value"
}

 
Best Answer chosen by Stephen Wood 5
AdminBooster.comAdminBooster.com
You could use the composite API https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite.htm
 
Best Answer chosen by Kevin Blumenfeld
AdminBooster.comAdminBooster.com
Yes, think about a Service Provider (Salesforce) initiated flow. When trying to access Salesforce, if Salesforce has no valid session, your user will be redirected to your identity provider (adfs.contoso.com) with a SAML request, then adfs will authenticate the user and provide a SAML response to Salesforce, granting access. To avoid a login screen on Salesforce, configure the attributes of your my domain to allow only your sso configuration and not login password