• Somya Tiwari
  • NEWBIE
  • 178 Points
  • Member since 2019
  • Salesforce Developer
  • Mindruby Technology


  • Chatter
    Feed
  • 4
    Best Answers
  • 4
    Likes Received
  • 0
    Likes Given
  • 12
    Questions
  • 37
    Replies
Hi, 
I want to introduce version control into my workflow.  I also want to work locally.  I have a Bitbucket account that I would like to use.

Currently I work in the Developer consoole in the sandbox and deploy from there.  

Any advice would be appricated.
Thanks
I'm new to apex and currently learning variables and trigger. I'm creating simple scenarios and attempting to write triggers for those scenarios. Below are the 2 scenarios I need help with;

Write a trigger that creates a contact when an account is created and should be associated with the account.

Write a trigger that creates two identical Contacts whenever an account is created and should be associated with the account.

Here's the trigger I wrote for the first scenario and I get an error when I try to create a new account. 
How do I go about the second trigger?

trigger AccountCreate on Account (after insert) {
    
    for (Account acc : Trigger.new) {
    
    Contact C = new Contact();
    
    C.LastName = 'Grace';
    C.AccountId = acc.id;
    C.Email = 'testme@hotmail.com';
 
    insert acc;
      }
}
 

In my Vf page i have a selection radio option.. i want to have a javascript function which will show validation message whenever i click save button without selecting the radio options.. kindly plz help me with this.

   <apex:selectradio id="modeFamilyTraveling" value="{!modeFamilyTraveling}" layout="pageDirection" style="font-weight:0px !important;" >
 <apex:selectOptions value="{!transportMode}"></apex:selectOptions>
 </apex:selectradio>

I have a scenario where I need to insert more than 60 detail records of a single master. In the same instance I have to insert the master record get the ID and then insert 60 different details of the same.
The same works flawlessly until 38 records here is the limits that are utilized in inserting 38 records:
17:08:53.1 (641222913)|SYSTEM_METHOD_ENTRY|[91]|Database.insert(List<SObject>) 
17:08:53.1 (641260235)|DML_BEGIN|[91]|Op:Insert|Type:Payment_Schedules__c|Rows:38 
17:08:53.1 (641283908)|LIMIT_USAGE|[91]|DML|2|150 
17:08:53.1 (641291826)|LIMIT_USAGE|[91]|DML_ROWS|39|10000 
17:08:53.1 (641308456)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:156 
17:08:53.1 (739617623)|DML_END|[91]
17:08:53.1 (739747119)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:156 
17:08:53.1 (739787515)|SYSTEM_METHOD_EXIT|[91]|Database.insert(List<SObject>) 
17:08:53.1 (739800747)|STATEMENT_EXECUTE|[92] 
17:08:53.1 (739814918)|LIMIT_USAGE|[92]|SCRIPT_STATEMENTS|6645|200000 
17:08:53.1 (739881176)|HEAP_ALLOCATE|[92]|Bytes:8 
17:08:53.1 (739900982)|DML_BEGIN|[92]|Op:Update|Type:Lending_Contract__c|Rows:1 
17:08:53.1 (739919823)|LIMIT_USAGE|[92]|DML|3|150 
17:08:53.1 (739930181)|LIMIT_USAGE|[92]|DML_ROWS|40|10000 
17:08:53.1 (739947279)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8 
17:08:53.1 (754589970)|DML_END|[92] 17:08:53.1 (754609159)|STATEMENT_EXECUTE|[93] 
17:08:53.1 (754620238)|LIMIT_USAGE|[93]|SCRIPT_STATEMENTS|6646|200000 
17:08:53.1 (754936104)|VARIABLE_ASSIGNMENT|[93]|Calculations.LendingContractID|"a004x000001d9BhAAI" 
17:08:53.1 (754968258)|METHOD_EXIT|[1]|01p4x000003WgvL|Calculations.CreateSchedules(Double, Double, Integer, String, Date, Date) 
17:08:53.1 (754980981)|SYSTEM_MODE_EXIT|false 
17:08:53.764 (764240185)|CUMULATIVE_LIMIT_USAGE 
17:08:53.764 (764240185)|LIMIT_USAGE_FOR_NS|(default)| 

Number of SOQL queries: 0 out of 100 
Number of query rows: 0 out of 50000 
Number of SOSL queries: 0 out of 20 
Number of DML statements: 3 out of 150 
Number of Publish Immediate DML: 0 out of 150 
Number of DML rows: 40 out of 10000 
Maximum CPU time: 189 out of 10000 
Maximum heap size: 0 out of 6000000 
Number of callouts: 0 out of 100
Number of Email Invocations: 0 out of 10 
Number of future calls: 0 out of 50 
Number of queueable jobs added to the queue: 0 out of 50
Number of Mobile Apex push calls: 0 out of 10 

17:08:53.764 (764240185)|TOTAL_EMAIL_RECIPIENTS_QUEUED|0
The same code fails when there are more than 38 records here is the limits usage when tried for 39 records:
17:08:58.1 (588262540)|SYSTEM_METHOD_ENTRY|[91]|Database.insert(List<SObject>) 17:08:58.1 (588307190)|DML_BEGIN|[91]|Op:Insert|Type:Payment_Schedules__c|Rows:39 
17:08:58.1 (588331920)|LIMIT_USAGE|[91]|DML|2|150 
17:08:58.1 (588340141)|LIMIT_USAGE|[91]|DML_ROWS|40|10000 
17:08:58.1 (588356694)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:160 
17:08:58.1 (610899136)|DML_END|[91] 
17:08:58.1 (615098680)|SYSTEM_MODE_EXIT|false 
17:08:58.1 (615455839)|FATAL_ERROR|Internal Salesforce.com Error 
17:08:58.615 (615492715)|CUMULATIVE_LIMIT_USAGE 
17:08:58.615 (615492715)|LIMIT_USAGE_FOR_NS|(default)| 

Number of SOQL queries: 0 out of 100 
Number of query rows: 0 out of 50000 
Number of SOSL queries: 0 out of 20 
Number of DML statements: 2 out of 150 
Number of Publish Immediate DML: 0 out of 150 
Number of DML rows: 40 out of 10000
Maximum CPU time: 175 out of 10000 
Maximum heap size: 0 out of 6000000 
Number of callouts: 0 out of 100 
Number of Email Invocations: 0 out of 10
Number of future calls: 0 out of 50 
Number of queueable jobs added to the queue: 0 out of 50 
Number of Mobile Apex push calls: 0 out of 10 

17:08:58.615 (615492715)|TOTAL_EMAIL_RECIPIENTS_QUEUED|0
Do we have any kind of fix how we can solve the same... The code is quite simple with the following insert and update patterns
  • Insert MasterRecord
  • for loop to create details:
  • Update detailRecordList
  • Update MasterRecord

I am integrating with one of the provider who accepts a file to upload in their system. While doing so they require the file to be sent as multipart/form-data in the following format !! 

I tried configuring it as MultiPart form data using Base64 String still it is not working !! 

-H "accept: application/json"
-H "x-api-key: API_KEY" 
-H "x-api-token: API_TOKEN" 
-H "Content-Type: multipart/form-data" 
-F "file=@b4b35527-522d-4228-a266-bdaa80e28a8b.jpg;type=image/jpeg"

Hi Guys !! 

I am stuck at the challenge 7, trailhead showing error of a missing function, apparently it is present in my code !! Please help !
 

import { LightningElement, track, wire, api } from 'lwc';
import getBoatsByLocation from '@salesforce/apex/BoatDataService.getBoatsByLocation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';

const LABEL_YOU_ARE_HERE = 'You are here!';
const ICON_STANDARD_USER = 'standard:user';
const ERROR_TITLE = 'Error loading Boats Near Me';
const ERROR_VARIANT = 'error';
export default class BoatsNearMe extends LightningElement {
    @api boatTypeId;
    @track mapMarkers = [];
    @track isLoading = true;
    @track isRendered = false;
    latitude;
    longitude;
    @wire(getBoatsByLocation, { latitude: '$latitude', longitude: '$longitude', boatTypeId: '$boatTypeId' })
    wiredBoatsJSON({ error, data }) {
        if (data) {
            this.createMapMarkers(data);
        } else if (error) {
            this.dispatchEvent(
                new ShowToastEvent({
                    title: ERROR_TITLE,
                    message: error.body.message,
                    variant: ERROR_VARIANT
                })
            );
            this.isLoading = false;
        }
    }
    renderedCallback() {
        if (this.isRendered == false) {
            this.getLocationFromBrowser();
        }
        this.isRendered = true;
    }
    getLocationFromBrowser() {
        navigator.geolocation.getCurrentPosition(
            (position) => {
                this.latitude = position.coords.latitude;
                this.longitude = position.coords.longitude;
            },
            (e) => {

            }, {
            enableHighAccuracy: true
        }
        );
    }
    createMapMarkers(boatData) {
        this.mapMarkers = boatData.map(rowBoat => {
            return {
                location: {
                    Latitude: rowBoat.Geolocation_Latitude_s,
                    Longitude: rowBoat.Geolocation_Longitude_s
                },
                title: rowBoat.Name,
            };
        });
        this.mapMarkers.unshift({
            location: {
                Latitude: this.latitude,
                Longitude: this.longitude
            },
            title: LABEL_YOU_ARE_HERE,
            icon: ICON_STANDARD_USER
        });
        this.isLoading = false;
    }
}


Error :

Lightning Web Component Specialist Challenge 7

Hello,

I have a Core i5 8th Gen PC with 8Gigs of RAM, and had been struggling quite hard while developing on APEX. i was earlier using the Developer Console, and as the Project i am working is quite dense, we have to test Batch Classes, and Aura Components.

When we load any Aura page, there are muliple logs of Aura or Batch Class in case of running the batch, are created, and this makes the PC to hang.

To solve the issue we started to work on VS Code, but that made the situation worse. 

Also we guys are using Ubuntu 18.04 LTE.

What do you guys suggest? Should we move to Windows or simply increase our RAM? 

It would be great if you guys can help with your experiance with AURA, APEX, and dealing with lots of LOGS in Dev Console according to your current configuration of PC. 

I have a Webservice which sends me transactions. We want to track the changes record by record just as a Bank Statement. We are using webservice to store Credit and Debit amount.

In the trigger we are quering for the last record [I know this is not what best practice says, but was not able think of a better way] and then calculating the balance for this record.

trigger:

trigger ASM_Balance on Assembly_Transactions__c (before insert) {
    
    List<Assembly_Transactions__c> trans = [SELECT ID, balance__c FROM Assembly_Transactions__c WHERE Wallet_Owner__c =: Trigger.new[0].Wallet_Owner__c ORDER BY CreatedDate DESC LIMIT 1];
    
    Double balance = 0;
    if(trans.size()>0)
    {
        if(trans[0].balance__c != null)
            balance = trans[0].balance__c;
    }
    Assembly_Transactions__c tr = Trigger.new[0];
    Double cr = tr.credit__c;
    Double dt = tr.debit__c;
    Double amount = balance+cr-dt;
    tr.balance__c = amount;
}

The error occours when we have two transactions at the same time, and the webservice is hit back to back. 

I think this is due to SOQL being run just before we have the last transaction inserted successfully. 

Please help me out with suggestions.

I have set Default value for a Picklist, but to my luck it is not working, don't know the reason for the same.

Can anyone help me with any workaround? Even Custom Picklists are not working with default values on Account. Although it is working for Contact. 

Default Value:
User-added image

New Account Page:
User-added image
 

I have a wiered problem with my org. This came up after i enabled Person Account. Now i don't want to use it but as we cannot disable it i am missing some of basic functionality.

The most basic one is Lookup Fields on Opportunity are not getting saved. Here are the screen shots have a look. I have tried looking into before Trigger, after Trigger, in Workflow, and Process Builders, but not found any clue to my bad luck. Can anyone help with this?
User-added image

User-added image
I want to integrate Google Maps API with a VisualForce Page to generate Autofill Suggesstions for Address. When i use <Apex:InputText> tag Google Maps API gives following error:   
InvalidValueError: not an instance of HTMLInputElement
Hence i am using HTML tags for taking the Input, now can anyone help me to get this input into the controller?

Apex Controller
public class location {
    //public location(ApexPages.StandardController controller){}
    public void receiveInput() {
        System.debug('Google');
        string search0 = Apexpages.currentPage().getParameters().get('search0');
        string search1 = Apexpages.currentPage().getParameters().get('search1');
        System.debug('Search 0' + search0);
        System.debug('Search 1' + search1);
    }
}
VisualForce Page
<apex:page controller="location">
<apex:form id="form1">
    <apex:pageBlock title="Submit Location" id="loc">
        <label>Location 1</label>
            <input id="search0" name="search0" type="text" size="50"/>
        <label>Location 2</label>
            <input id="search1" name="search1" type="text" size="50"/>
        <apex:commandButton onClick="callActionFunction(search0, search1);" value="Click Here!"/>
        <apex:actionFunction name="SearchLocation" action="{!receiveInput}">
                <apex:param name="search0" assignTo="{!search0}" value=""/>
                <apex:param name="search1" assignTo="{!search1}" value=""/>
        </apex:actionFunction>
    </apex:pageBlock>
</apex:form>
<script src="https://maps.googleapis.com/maps/api/js?key=**INSERT_YOUR_GOOGLE_API_HERE**&libraries=places"></script>
<script type="text/javascript">
        //for first searchbox
        function initialize() {
            var input = document.getElementById('search0'); //Element ID of 2nd = search0
            new google.maps.places.Autocomplete(input);
        }
        //for second SearchBox
        function initialize2() {
            var input2 = document.getElementById('search1'); //Element ID of 2nd = search1
            new google.maps.places.Autocomplete(input2);
        }
        google.maps.event.addDomListener(window, 'load', initialize);
        google.maps.event.addDomListener(window, 'load', initialize2);

        function callActionFunction(v1, v2) {
            var val1, val2;
            val1 = document.getElementById(v1);
            val2 = document.getElementById(v2);
            alert(val1);
            alert(val2);
            alert(document.getElementsByName(search0));
            SearchLocation(val1, val2);
        }
</script>
</apex:page>
Result What i need !!
User-added image

I have a Scenario Where i want to update Branch Number on my Accounts. Basically it will be a tree, where Account which is the Root one will have its own Branch Code Auto Generated. While Accounts with Parent ID will have branch Code as (Parent Branch Code + Serial Number of Child).

Here is the Scenerio.
Root Node : 'Cloud Crackers' Branch Code : CC
Child Nodes of 'Cloud Crackers' as 'Somya Tiwari', and 'Harsh Panot' wherein there Branch Code is as follow:
Node: 'Somya Tiwari'  Branch Code: CC - 1
Node: 'Harsh Panot' Branch Code: CC - 2

Now if i have childs of 'Somya Tiwari' as 'A' and 'B', their Branch Code will be as follow

Node: 'A'  Branch Code: CC - 1 - 1
Node: 'B' Branch Code: CC - 1 - 1

and if 'Harsh Panot' will have child as 'C' and 'D', their branch code will be as follow:

Node: 'C'  Branch Code: CC - 2 - 1 
Node: 'D' Branch Code: CC - 2 - 2

Now whenever i change this tree i need to get all the branch codes updated. For this i have created three different classes. Currently i am learning so there is a bit of mistakes. kindly ignore those.

Here is my code, please help me with update, only that is creating issue where if i update a child which is having multiple siblings. Eg: Chidls of A as B, C, D, and E

So branch codes are as follow:
A - AA
B - AA - 1
C - AA - 2
D - AA - 3
E - AA - 4

Now if i edit D to have no parent then branch Coding must be as follow:
 
A - AA
B - AA - 1
C - AA - 2
D - DD
E - AA - 3

But Currently it is coming as follow

A - AA
B - AA - 1
C - AA - 2
D - DD
E - AA - 4

Although if i delete D then it is coming correct as follow:

A - AA
B - AA - 1
C - AA - 2
E - AA - 3

I am attaching the code. Please have a look and help me with the same.

Trigger:- Branching.apxt

trigger Branching on Account (before insert, before delete, before update, after update) 
{
    //Insert Account Logic
    if(Trigger.isInsert)
    {
        List<Account> accList = new List<Account>();
        List<Account> accListWP = new List<Account>();
        for(Account acc: Trigger.new)
        {
            if(acc.ParentId == null)
                accList.add(acc);
            else {
                accListWP.add(acc);
            }
        }
        if(acclist.size()>0)
        {
            defaultBranchCode dbc = new defaultBranchCode(acclist);
            dbc.start();
        }
        if(accListWP.size()>0)
        {
            defaultBranchCode dbc = new defaultBranchCode(accListWP, 'with parent account');
            dbc.startWP();
        }    
    }
    //Delete Account Logic
    if(Trigger.isDelete)
    {
        List<Account> accList = new List<Account>(); // List of Accounts With ParentID
        List<Account> accCheckList = new List<Account>(); //List of All Accounts which are going to be deleted
        for(Account acc: Trigger.old) //Using Trigger.old to get all the records for which the trigger is fired
        {
            if(acc.ParentID != null) // If Account have parents then add to accList 
            {
                accList.add(acc);
            }
            accCheckList.add(acc); // All accounts are added here.
        }
        if(accList.size()>0)
        {
            changeBranchCode cbc = new changeBranchCode(accList); //Refreshing the Siblings
            cbc.deleteAccount();
        }
        List<Account> unparentChild = new List<Account>();
        if(accCheckList.size()>0)
        {
            changeBranchCode cbc = new changeBranchCode(accCheckList); // Getting List of all the childs
            unparentChild.addAll(cbc.searchchilds());
        }
        if(unparentChild.size()>0) // Updating all the childs with Initiated with delete
        {
            defaultBranchCode dbc = new defaultBranchCode(unparentChild);
            dbc.startWU();
            List<Account> upd = new List<Account>();
            for(Account a: unparentChild)
            {
                a.ByDelete__c = true;
                upd.add(a);
            }
            update upd;
            /*UpdateQueue uq = new UpdateQueue(unparentchild);
            System.enqueueJob(uq);*/
            UpdateMethods um = new UpdateMethods(unparentchild);
            um.UpdateChilds(unparentchild);
        }
    }

    if(Trigger.isUpdate)
    {
        if(Trigger.isAfter)
        {
            List<Account> acc = [SELECT ID, ParentID, branchcode__c, pbc__c FROM ACCOUNT];
            List<Account> child = new List<Account>();
            List<Account> temp = new List<account>();
            List<Account> FA = new List<Account>();
            for(Account a: Trigger.new)
            {
                temp.add(a);
            }
            child.addAll(changeBranchCode.searchchilds2(temp));
            if(child.size() >0)
            {
                List<Account> ab = new List<Account>();
                for(Account a: child)
                {
                    List<String> split = a.branchcode__c.split(' - ');
                    integer i = 0;
                    if(a.branchcode__c.length()>4)
                        i = Integer.valueOf(split[split.size()-1]);
                    if(i>0)
                        a.branchcode__c = a.pbc__c +' - '+ i;
                    else
                        a.branchcode__c = a.pbc__c;
                    ab.add(a);
                }
                fa.addAll(ab);
                //update ab;
            }
            List<Account> fud = new List<Account>();
            for(Account a: Trigger.old)
            {
                if(a.parentID != null)
                    fud.add(a);
            }
            if(fud.size()>0)
            {
                changeBranchCode cbc = new changeBranchCode(fud);
                cbc.deleteAccount();
            }
            update fa;
        }
        if(Trigger.isBefore)
        {
            List<Account> accListWP = new List<Account>();
            Map<ID, Account> oldmap = Trigger.oldmap;
            for(Account a: Trigger.new)
            {
                if(a.ByDelete__c == false)
                {
                    Account old = oldmap.get(a.Id);
                    if(a.pbc__c != old.pbc__c)
                    {
                        accListWP.add(a);
                    }
                    else
                    {
                        List<String> split = a.branchcode__c.split(' - ');
                        integer i = 0;
                        
                        if(a.branchcode__c.length()>4)
                            i = Integer.valueOf(split[split.size()-1]);
                        if(i>0)
                            a.branchcode__c = a.pbc__c +' - '+ i;
                        else
                            a.branchcode__c = a.pbc__c;
                    }
                    
                    System.debug(a.branchcode__c);
                }
                else
                {
                    a.ByDelete__c = false;
                }
            }
            if(accListWP.size()>0)
            {
                defaultBranchCode dbc = new defaultBranchCode(accListWP, 'with parent account');
                dbc.startWP();
            }
        }
        
    }
}
DefaultBranchCode.apxc
public class defaultBranchCode 
{
    List<Account> acc_list;
    List<Account> accList = [SELECT branchcode__c, parentID FROM Account];
    List<String> temp = new List<String>();
    // For Base Account
    public defaultBranchCode(List<Account> acc_list) 
    {
        this.acc_list = acc_list;
    }

    String createBranchCode(Account a)
    {
        List<String> split = a.Name.split(' ');
        String ret = '';
        for(integer i = 0; i<split.size(); i++)
        {
            ret+=split[i].substring(0, 1);
        }
        if(ret.length()>2)
        {
            ret = ret.substring(0,2);
        }
        else if(ret.length()<2)
        {
            ret = ret+ret;
        }
        return ret.toUpperCase();
    }

    String verifiedBranchCode(String branchCode)
    {
        Integer size = accList.size();
        for(integer i = 0; i<size; i++)
        {
            if(accList[i].branchcode__c == branchCode)
            {
                if(branchCode.length()>2)
                {
                    String val = branchCode.substring(2, branchCode.length());
                    Integer k = Integer.valueOf(val);
                    k = k+1;
                    branchCode = branchCode.substring(0, 2) + k;
                }
                else 
                {
                    branchCode = branchCode+1;    
                }
                i = 0;
            }
        }
        return branchCode;
    }

    public void start()
    {
        for(Account acc : acc_list)
        {
            String branchCode = createBranchCode(acc);
            branchCode = verifiedBranchCode(branchCode);
            acc.BranchCode__C = branchCode;
            temp.add(branchCode);
        }
    }

    //For Accounts w/ parents
    Map<Id, integer> currentvalue = new Map<Id, integer>(); 
    public defaultBranchCode(List<Account> acc_list, String temp) 
    {
        this.acc_list = acc_list;
    }

    Integer counter(String pid)
    {
        integer count = 0;
        for(Account acc : accList)
        {
            System.debug(acc.ParentId);
            if(acc.ParentID == pid)
                count++;
            System.debug(count);
        }
        return count;
    }

    public void startWP()
    {
        for(Account acc : acc_list)
        {
            String pid = acc.ParentID;
            if(!currentvalue.containsKey(pid))
                currentvalue.put(pid, counter(pid));
            integer current = currentvalue.get(pid);
            current = current+1;
            currentvalue.put(pid, current);
            acc.BranchCode__C = acc.pbc__C + ' - ' + current;
        }
    }

//For Delete function
    public void startWU()
    {
        List<Account> ltoupdate = new List<Account>();
        for(Account acc : acc_list)
        {
            String branchCode = createBranchCode(acc);
            branchCode = verifiedBranchCode(branchCode);
            acc.BranchCode__C = branchCode;
            ltoupdate.add(acc);
        }
        update ltoupdate;
    }

}



ChangeBranchCode.apxc
public class changeBranchCode {
    List<Account> listacc = new List<Account>();
    List<Account> allaccount = [SELECT branchcode__c, parentID,pbc__C, Id FROM Account];
    public changeBranchCode(List<Account> listacc) 
    {
        this.listacc = listacc;
    }
    Map<Account, List<Account>> map_PC = new Map<Account, List<Account>>();
    void createMap()
    {
        for(Account acc: allaccount)
        {
            Account parentaccount = findparent(acc.parentID);
            if(map_PC.containsKey(parentaccount)){
                List<Account> temp = map_PC.get(parentaccount);
                temp.add(acc);
                map_PC.put(parentaccount, temp);
            }
            else {
                List<Account> temp = new List<Account>();
                temp.add(acc);
                map_PC.put(parentaccount, temp);
            }
        }
    }
    Account findparent(ID pid)
    {
        Account acc;
        for(Account t : allaccount)
            if(t.Id == pid)
                acc = t;
        return acc;
    }
    
    static Map<Account, List<Account>> map_PC1 = new Map<Account, List<Account>>();
    static List<Account> allaccount1 = [SELECT branchcode__c, parentID,pbc__C, Id FROM Account];
    static void createMap1()
    {
        for(Account acc: allaccount1)
        {
            Account parentaccount = findparent2(acc.parentID);
            if(map_PC1.containsKey(parentaccount)){
                List<Account> temp = map_PC1.get(parentaccount);
                temp.add(acc);
                map_PC1.put(parentaccount, temp);
            }
            else {
                List<Account> temp = new List<Account>();
                temp.add(acc);
                map_PC1.put(parentaccount, temp);
            }
        }
    }
    static Account findparent2(ID pid)
    {
        Account acc;
        for(Account t : allaccount1)
            if(t.Id == pid)
                acc = t;
        return acc;
    }
    
    
    /*static Account findparent1(ID pid, List<Account> allaccount)
    {
        Account acc;
        for(Account t : allaccount)
            if(t.Id == pid)
                acc = t;
        return acc;
    }*/

    void rebase(Account acc, Account notinclude, integer f)
    {
        List<Account> child = map_PC.get(acc);
        List<Account> ListToupdate = new List<Account>();
        try {
            for(Account a : child)
            {
                if(a != notinclude)
                {
                    List<String> split = a.branchcode__c.split(' - ');
                    Integer i = 0;
                    if(a.branchcode__c.length()>4)
                        i = Integer.valueOf(split[split.size()-1]);
                    if(i>f)
                        i--;
                    Account up = new Account(ID = a.Id);
                    if(i>0)
                        up.branchcode__c = a.pbc__c +' - '+ i;
                    else
                        up.branchcode__c = a.pbc__c;
                    ListToupdate.add(up);
                }
            }
        } catch (NullPointerException e) {
            System.debug(e.getStackTraceString());
        }
        update ListToupdate;
    }

    public void deleteAccount()
    {
        createMap();
        for(Account acc : listacc)
        {
            Account parent = findparent(acc.parentID);
            List<String> split = acc.branchcode__c.split(' - ');
            Integer i = 0;
            if(acc.branchcode__c.length()>4)
                i = Integer.valueOf(split[split.size()-1]);
            //rebase(parent, acc, i);
            if(Trigger.isDelete)
                rebase(parent, acc, i);
            else {
                ID ta = parent.Id;
                ID ta2 = acc.Id;
				if(!System.isFuture())
                	rebase_2(ta, ta2, i);
                else
                    rebase(parent, acc, i);
            }
        }
    }

    @future static void rebase_2(ID ta, ID ta2, integer f)
    {
        //Account acc = [SELECT ID, Name, branchcode__c, parentID,pbc__C FROM ACCOUNT where ID=:ta];
        Account notinclude = [SELECT  ID, Name, branchcode__c, parentID,pbc__C FROM ACCOUNT where ID=:ta2];
        //List<Account> child = map_PC1.get(acc);
        List<Account> child = [SELECT  ID, Name, branchcode__c, parentID,pbc__C FROM ACCOUNT where ParentID = :ta];
        System.debug(child);
        List<Account> ListToupdate = new List<Account>();
        try{
            for(Account a : child)
            {
                if(a != notinclude)
                {
                    List<String> split = a.branchcode__c.split(' - ');
                    Integer i = 0;
                    if(a.branchcode__c.length()>4)
                        i = Integer.valueOf(split[split.size()-1]);
                    if(i>f)
                        i--;
                    Account up = new Account(ID = a.Id);
                    if(i>0)
                        up.branchcode__c = a.pbc__c +' - '+ i;
                    else
                        up.branchcode__c = a.pbc__c;
                   ListToupdate.add(up);
                }
            }
        } catch (NullPointerException e) {
            System.debug(e.getStackTraceString());
        }
        update ListToupdate;
    }

    public List<Account> searchchilds()
    {
        List<ID> lid = new List<ID>();
        for(Account a : listacc)
        {
            lid.add(a.id);
        }
        List<Account> childs = [SELECT Id, branchcode__c, Name, ParentID, pbc__c FROM Account WHERE ParentID = :lid];
        return childs;
    }
    
    public static List<Account> searchchilds2(List<Account> listac)
    {
        List<ID> lid = new List<ID>();
        for(Account a : listac)
        {
            lid.add(a.id);
        }
        List<Account> childs = [SELECT Id, branchcode__c, Name, ParentID, pbc__c FROM Account WHERE ParentID = :lid];
        return childs;
    }
    
}

UpdateMethods.apxc
public class UpdateMethods 
{
    List<Account> listacc = new List<Account>();
    List<Account> allaccount = [SELECT Name, branchcode__c, parentID,pbc__C, Id FROM Account];
    public UpdateMethods(List<Account> listacc) 
    {
        this.listacc = listacc;
    }
    public UpdateMethods()
    {

    }
    Map<Account, List<Account>> map_PC = new Map<Account, List<Account>>();
    void createMap()
    {
        for(Account acc: allaccount)
        {
            Account parentaccount = findparent(acc.parentID);
            if(map_PC.containsKey(parentaccount)){
                List<Account> temp = map_PC.get(parentaccount);
                temp.add(acc);
                System.debug(temp);
                map_PC.put(parentaccount, temp);
            }
            else {
                List<Account> temp = new List<Account>();
                temp.add(acc);
                map_PC.put(parentaccount, temp);
            }
        }
    }
    Account findparent(ID pid)
    {
        Account acc;
        for(Account t : allaccount)
            if(t.Id == pid)
                acc = t;
        return acc;
    }
    public void UpdateChilds(List<Account> fchilds)
    {
        createMap();
        List<Account> childs = findchilds(fchilds);
        List<Account> ListToupdate = new List<Account>();
        for(Account a: childs)
        {
            List<String> split = a.branchcode__c.split(' - ');
            integer i = 0;
            if(a.branchcode__c.length()>4)
                i = Integer.valueOf(split[split.size()-1]);
            Account up = new Account(ID = a.Id);
            if(i>0)
                up.branchcode__c = a.pbc__c +' - '+ i;
            else
                up.branchcode__c = a.pbc__c;
            System.debug(split);
            ListToupdate.add(up);
        }
        update ListToupdate;
    }
    
    List<Account> searchchilds(List<Account> fchilds)
    {
        List<Account> childs = new List<Account>();
        for(Account a : fchilds)
        {
            if (map_PC.get(a) != null)
                childs.addAll(map_PC.get(a));
        }
        return childs;
    }

    List<Account> findchilds(List<Account> fchilds)
    {
        List<Account> childs = new List<Account>();
        integer prev, current;
        for(integer i = 0 ; i<1; )
        {
            prev = childs.size();
            childs.addAll(searchchilds(fchilds));
            fchilds = childs;
            current = childs.size();
            if(prev == current)
                i = 1;
        }
        return childs;
    }
}

 
I am unable to login to Trailhead !! I am again and again redirected to login.salesforce.com
Anyone came accross to any such issue? 

Tried creating multiple playgrounds !! Still unable to use Trailhead any solution to this?

Hello,

My Workflow on leads object is being triggered twice which creates an issue of creating double task. When i created a contact with lead creation, then an error was thrown that duplicate contact detected.

Please find here with the screen shots.
First ProcessSecond ProcessOnly One Created while creating Task with OpportunitiesDuplicate Detected while creating a Contact with a Lead using same Workflow.
The Workflow rule is just simple. It will be triggered whenever the object is created. There is no recurrsion of any sort used in the Workflow. So this is absolutely not an error of Recursion. 

 

Anyone with any such issue? 

Hello,

I have a Core i5 8th Gen PC with 8Gigs of RAM, and had been struggling quite hard while developing on APEX. i was earlier using the Developer Console, and as the Project i am working is quite dense, we have to test Batch Classes, and Aura Components.

When we load any Aura page, there are muliple logs of Aura or Batch Class in case of running the batch, are created, and this makes the PC to hang.

To solve the issue we started to work on VS Code, but that made the situation worse. 

Also we guys are using Ubuntu 18.04 LTE.

What do you guys suggest? Should we move to Windows or simply increase our RAM? 

It would be great if you guys can help with your experiance with AURA, APEX, and dealing with lots of LOGS in Dev Console according to your current configuration of PC. 

I have a Webservice which sends me transactions. We want to track the changes record by record just as a Bank Statement. We are using webservice to store Credit and Debit amount.

In the trigger we are quering for the last record [I know this is not what best practice says, but was not able think of a better way] and then calculating the balance for this record.

trigger:

trigger ASM_Balance on Assembly_Transactions__c (before insert) {
    
    List<Assembly_Transactions__c> trans = [SELECT ID, balance__c FROM Assembly_Transactions__c WHERE Wallet_Owner__c =: Trigger.new[0].Wallet_Owner__c ORDER BY CreatedDate DESC LIMIT 1];
    
    Double balance = 0;
    if(trans.size()>0)
    {
        if(trans[0].balance__c != null)
            balance = trans[0].balance__c;
    }
    Assembly_Transactions__c tr = Trigger.new[0];
    Double cr = tr.credit__c;
    Double dt = tr.debit__c;
    Double amount = balance+cr-dt;
    tr.balance__c = amount;
}

The error occours when we have two transactions at the same time, and the webservice is hit back to back. 

I think this is due to SOQL being run just before we have the last transaction inserted successfully. 

Please help me out with suggestions.

I have set Default value for a Picklist, but to my luck it is not working, don't know the reason for the same.

Can anyone help me with any workaround? Even Custom Picklists are not working with default values on Account. Although it is working for Contact. 

Default Value:
User-added image

New Account Page:
User-added image
 

Hello,

I have a Core i5 8th Gen PC with 8Gigs of RAM, and had been struggling quite hard while developing on APEX. i was earlier using the Developer Console, and as the Project i am working is quite dense, we have to test Batch Classes, and Aura Components.

When we load any Aura page, there are muliple logs of Aura or Batch Class in case of running the batch, are created, and this makes the PC to hang.

To solve the issue we started to work on VS Code, but that made the situation worse. 

Also we guys are using Ubuntu 18.04 LTE.

What do you guys suggest? Should we move to Windows or simply increase our RAM? 

It would be great if you guys can help with your experiance with AURA, APEX, and dealing with lots of LOGS in Dev Console according to your current configuration of PC. 

Hi All,

I am new to SF and  having some issue in API level. I am having 12k + System logs in developer console and i am querying Apexlog and selecting 2K records at a time and deleting it. But my Org API limits are increasing at same time. Just want to know that deleting the logs counts as API call for my org or any other things can affect?

Thanks in Advance. 

I have a Webservice which sends me transactions. We want to track the changes record by record just as a Bank Statement. We are using webservice to store Credit and Debit amount.

In the trigger we are quering for the last record [I know this is not what best practice says, but was not able think of a better way] and then calculating the balance for this record.

trigger:

trigger ASM_Balance on Assembly_Transactions__c (before insert) {
    
    List<Assembly_Transactions__c> trans = [SELECT ID, balance__c FROM Assembly_Transactions__c WHERE Wallet_Owner__c =: Trigger.new[0].Wallet_Owner__c ORDER BY CreatedDate DESC LIMIT 1];
    
    Double balance = 0;
    if(trans.size()>0)
    {
        if(trans[0].balance__c != null)
            balance = trans[0].balance__c;
    }
    Assembly_Transactions__c tr = Trigger.new[0];
    Double cr = tr.credit__c;
    Double dt = tr.debit__c;
    Double amount = balance+cr-dt;
    tr.balance__c = amount;
}

The error occours when we have two transactions at the same time, and the webservice is hit back to back. 

I think this is due to SOQL being run just before we have the last transaction inserted successfully. 

Please help me out with suggestions.

Hi all,
Need help. I am still a novice with Development, hence would need someone to please help me with the below query.

Background: We are having a custom object as 'Survey', which is having around 10-12 fields (combination of Text and picklist field).

Use of the Object: The fields in this object 'Survey' are getting populated dynamically - through AMP Script from Marketing Cloud. As these surveys are sent to customers through Marketing Cloud emails, and whatever input the customer add on the Survey Cloud Page, it automatically gets recorded under same name fields in Sales Cloud object.

Requirement: We want to send an 'Email Notification' to the Manager, each time a survey gets recorded in the Sales Cloud Object 'Survey' object.
Also, the Notification Email should display the 'Customer Name' 'Email' &  'Answers to all the questions of the Survey'.

I am not too sure how to achieve this using Apex and Trigger ?
Can someone please help me with this and explain the steps in basic language.

Thanks in advance !
Hi,I have a vf page where there are multiple checkboxes. Once a checkbox is checked to true, the corresponding data is shown visible. This has been already done by us. But now we want to make checkbox default to true and also show the corresponding data as soon as the checkbox is checked by default:
VF page :

<div class="selectAllDiv">
                    <apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId1','inputId2','inputId3','inputId4','inputId5','inputId6','inputId7','inputId8','inputId9',
                                                 'inputIdWirerd','inputIdHDWIC','inputIdDrwnWire', 'inputIdPcSt','inputIdSteelFab','inputIdCarpet')">
                        <apex:actionSupport event="onchange"  />
                    </apex:inputCheckbox><span>Select all</span>
                </div>
                <table class="blueTable" style="width:730px">
                    <tbody>
                        <tr>
                            <td>Product Type:</td>
                            <td>
                                <apex:inputCheckbox id="inputId1" selected ="true" value="{!Opportunity.barCheckBox__c}"  style="margin-left:8px">
                                <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Rebar
                                <br/>
                                <apex:inputCheckbox id="inputId2"  value="{!Opportunity.CutAndBend__c}" >
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Cut And Bend 
                                <br/>
                                <apex:inputCheckbox id="inputId3" value="{!Opportunity.PreFabCage__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Prefabricated Cage
                                <br/>
                                <apex:inputCheckbox id="inputId4" value="{!Opportunity.BorePileCage__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Bored Pile Cage
                                <br/>
                                <apex:inputCheckbox id="inputId5" styleClass="chkwc" onclick="disableMPCWoC(this,'inputId6')" value="{!Opportunity.Micro_Pile_Cage_with_centraliser__c}"   > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Micro Pile Cage (w/ centraliser)
                                <br/>
                                <apex:inputCheckbox id="inputId6" styleClass="chkwoc" onclick="disableMPCWC(this,'inputId5')" value="{!Opportunity.Micro_Pile_Cage_w_o_centraliser__c}"   > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Micro Pile Cage (w/o centraliser)
                                <br/>
                                <apex:inputCheckbox id="inputId7" value="{!Opportunity.Coupler1__c}"   > 
                                    <apex:actionSupport event="onchange" />
                                </apex:inputCheckbox> Coupler
                                <br/>
                            </td>
                            <td><apex:inputCheckbox id="inputId8" value="{!Opportunity.Deformed_Bar_In_Coil__c}" style="margin-left:8px">
                                <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Deformed Bar in Coil 
                                <br/>
                                <apex:inputCheckbox id="inputId9" value="{!Opportunity.Deformed_Bar_In_Coil_Semi__c}" >
                                    <apex:actionSupport event="onchange"  /> 
                                </apex:inputCheckbox> Deformed Bar in Coil (semi)
                                <br/>
                                <apex:inputCheckbox id="inputIdWirerd" value="{!Opportunity.Wire_Rod__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Wire Rod
                                <br/>
                                <apex:inputCheckbox id="inputIdHDWIC" value="{!Opportunity.Hard_drawn_wire_in_Coil__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Hard Drawn wire in Coil
                                <br/>
                                <apex:inputCheckbox id="inputIdDrwnWire" value="{!Opportunity.Hard_drawn_wire__c}" > 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Hard Drawn wire
                                <br/>
                                <apex:inputCheckbox id="inputIdPcSt" value="{!Opportunity.PC_Strand__c}"   > 
                                    <apex:actionSupport event="onchange" />
                                </apex:inputCheckbox> PC Strand
                                <br/>
                                <br/>
                            </td>
                            <td><apex:inputCheckbox id="inputIdSteelFab" value="{!Opportunity.Steel_Fabric_Products__c}" style="margin-left:8px;">
                                <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Steel Fabric Products
                                <br/>
                                <apex:inputCheckbox id="inputIdCarpet" value="{!Opportunity.Carpet__c}"> 
                                    <apex:actionSupport event="onchange"  />
                                </apex:inputCheckbox> Carpet
                                <br/><br/><br/><br/><br/><br/>
                            </td>
                        </tr>
                    </tbody>
                </table><br/>
                <apex:outputPanel rendered="{!Opportunity.barCheckBox__c}" id="barCheckBox">
                    <table class="blueTable" style="width:730px">
                        <thead>
                            <tr>
                                <th>Rebar (w/o DS) in mm </th>
                                <th>Volume (mt)</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>8</td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_8__c}"/></td>
                            </tr>
                            <tr>
                                <td>10,13 </td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_10_13_volume__c}"/></td>
                            </tr>
                            <tr>
                                <td>28,40 </td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_28_40_volume__c}"/></td>
                            </tr>
                            <tr>
                                <td> 16,20,25,32</td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_16_20_25_32_volume__c}"/></td>
                            </tr>
                            <tr>
                                <td> 50 </td>
                                <td><apex:inputField value="{!Opportunity.Material_w_o_DS_50_Volume__c}"/></td>
                            </tr>
                            <tr>
                                <td><b>Total Rebar &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</b></td>
                                <td><apex:inputField value="{!Opportunity.Total_w_o_DS__c}"/></td>
                            </tr>
                        </tbody>
                    </table>
                </apex:outputPanel><br/>
I have to create a lightning component for event object which overides standard add new event button......Can anyone help me.....
Hi, 
I want to introduce version control into my workflow.  I also want to work locally.  I have a Bitbucket account that I would like to use.

Currently I work in the Developer consoole in the sandbox and deploy from there.  

Any advice would be appricated.
Thanks
I have a piece of code in apex controller as follows.
 @auraEnabled   
    public static List<Service_Request__c> showSomeData(String caseId,String srReason, String recordTypeName)
    {
         try {
               List<Service_Request__c> srList = [SELECT Id,name
                                           FROM Service_Request__c  
                                           WHERE Service_Request_Reason__c =:someCondition];
           return srList;
    }
         catch(Exception e){
         System.debug('Error from ApexController Method' + e.getMessage());
            
        }  
    }

I added the try catch block as above and when I save it shows an error as  " Missing return statement required return type: List<Service_Request__c>"

Please let me know I missing some syntaxt
I'm new to apex and currently learning variables and trigger. I'm creating simple scenarios and attempting to write triggers for those scenarios. Below are the 2 scenarios I need help with;

Write a trigger that creates a contact when an account is created and should be associated with the account.

Write a trigger that creates two identical Contacts whenever an account is created and should be associated with the account.

Here's the trigger I wrote for the first scenario and I get an error when I try to create a new account. 
How do I go about the second trigger?

trigger AccountCreate on Account (after insert) {
    
    for (Account acc : Trigger.new) {
    
    Contact C = new Contact();
    
    C.LastName = 'Grace';
    C.AccountId = acc.id;
    C.Email = 'testme@hotmail.com';
 
    insert acc;
      }
}
 
public class DuplicatePanCheck {
    public static void duplicatePanNo(List<Consultant__c> cons){
        for(Consultant__c c: cons){
                if(c.Pan_Number__c!= null){ 
                List<Consultant__c> con = [select id,Pan_Number__c,Phone__c,Email__c from Consultant__c where Pan_Number__c =: c.Pan_Number__c];  //checking the duplicate record based on the pan number
                        if(con.size()>1){
                        for(Consultant__c cn : con){   //if duplicate records found, updating phone, email fields in the old records 
                            cn.Phone__c = c.Phone__c;
                            cn.Email__c = c.Email__c;
                        }
                    update con;
                }
            }
        }
    }
}

trigger Trigg_DuplicatePanCheck on Consultant__c (after insert) {
    DuplicatePanCheck.duplicatePanNo(Trigger.new);
}
 
Hi guys, my requirement is,

Create Renewal Opportunity - When opportunity stage is set to “Closed Won”, renewal
opportunity needs to be created with the following field mapping
Record type = “Renewal” (Create Opportunity Record Type, if not exist)
Account = Account of Original Opportunity
Type = Type of Original Opportunity
Stage = “Negotiation/Review”
Renewed from Opportunity = Original Opportunity (Create Lookup field of Opportunity on
Opportunity)
Close date = Close date of Original Opportunity + 10 Days
Name = “Renewal” + [SPACE] + Original Opportunity Name
2. Copy opportunity line Item to the renewal opportunity from Original Opportunity
  • August 24, 2019
  • Like
  • 0
Hello,
I need help with a deleing Contacts from an Account and updating the Account.  If I have multiple Contacts on an Account and one of the Contacts is checked as the primary then the checkbox on the Account should be checked.  If a contact is deleted I need to detemine if it was the Primary.  So if a non primary Contact is deleted then the checkbox on the Account remains checked.  But if the Contact that is flagged as the primary is deleted then i need checkbox on teh Account to be unchecked. 

Thanks
Hello everyone,
I am trying to update the field in account object. The field is called, open_activities__c. The count of all open activities for the corresponding account should appear on the field. 
I am getting the right count of activities(Tasks,Events) But the corresponding account Id is not being stored in my map datastructure. I have variable from aggregate query called cnt, that stores the count of open tasks/events. and accId that gets the WhatId of those tasks and events and I am putting both variables into my map<Id,Double> 
Here is the log result.

Log result for cnt:
14:42:44:055 VARIABLE_ASSIGNMENT [6]|agg|{"cnt":9}|0x6729bfa8
Log result for accId:
14:42:44:055 VARIABLE_SCOPE_BEGIN [7]|accId|Id|false|false
14:42:44:055 VARIABLE_ASSIGNMENT [7]|accId|null
I can not figure out the reason for the accId to be null.
Here is the code and trigger:
public class ActivityCounter {

   public static void activityCount(Set<Id> accountIds) { 
  
   List<Account> acctToUpdate = new List<Account>();
    Integer taskcounts=0;
    System.debug('coming here atleast');
   Map<Id,Double> tasksByAccount = new Map<Id, Double>();
   for (AggregateResult agg : [Select WhatId , count(Id) cnt From Task Where WhatId IN :accountIds and IsClosed = false GROUP BY WhatId]) {
     Id accId = (Id) agg.get('WhatId');
     Double cnt = (Double) agg.get('cnt');
     taskcounts=cnt.intValue();
     System.debug('Tasks got: '+taskcounts);  
     tasksByAccount.put(accId, cnt);
   }
    System.debug('size of tasks by account: '+tasksByAccount.size());
   Map<Id, Double> eventsByAccount = new Map<Id, Double>();
   for(AggregateResult agg : [Select  WhatId , count(Id) cnt From Event Where WhatId IN :accountIds and  EndDateTime <= TODAY GROUP BY WhatId]) {
     Id accId = (Id) agg.get('WhatId');
     Double cnt = (Double) agg.get('cnt');
         
     eventsByAccount.put(accId, cnt);
   }
    System.debug('Reaches events'); 
   for(Id accountId : accountIds) {
     Double taskCount = tasksByAccount.containsKey(accountId) ? tasksByAccount.get(accountId) : 0;
     Double eventCount = eventsByAccount.containsKey(accountId) ? eventsByAccount.get(accountId) : 0;
     Account acc = new Account(Id = accountId, Open_Activities__c=(taskCount + eventCount) );
     System.debug('coming here');
     acctToUpdate.add(acc);    
   }    

   update acctToUpdate;

  }
}
Trigger:
trigger OpenActivityCountTrigger on Task (before insert,after update) {
Set<Id> acctIds = new Set<Id>();
String accPrefix = Account.SObjectType.getDescribe().getKeyPrefix();
  for (Task t : trigger.New) {
    //I Have to check this is an account and not something else
    if (string.valueof(t.WhatId).startsWith(Account.SObjectType.getDescribe().getKeyPrefix())) {
      acctIds.add(t.WhatId);
        System.debug('What is going on??');
    }
  }
    
  openActivityCounter.activityCount(acctIds);
    System.debug('Are you even executing after this?');
}
 
trigger Count_Of_JobApp on job_application__c (after insert,after delete) 
{
    if((Trigger.isInsert && Trigger.isAfter) || (Trigger.isDelete && Trigger.isAfter))
    {
        Set<Id> parentIdsSet = new Set<Id>();
        List<Position__c> positionList = new List<Position__c>();
        if(Trigger.isInsert){
            for(job_application__c jobObj : Trigger.new){
                parentIdsSet.add(jobObj.Total_Job_Application__c);
            }
        }else if(Trigger.isDelete)  {
            for(job_application__c jobObj : Trigger.old){
                parentIdsSet.add(jobObj.Total_Job_Application__c);
            }   
        }
        
        System.debug('parentIdsSet-->'+parentIdsSet);
        if(parentIdsSet.size() > 0){
            positionList = [SELECT Id,
                            Name,
                            Count_Of_Job_App__c,
                            (SELECT Name
                             FROM job_applications__r)
                            FROM Position__c
                            WHERE Id IN : parentIdsSet];
        }
        System.debug('positionList-->'+positionList);
        if(positionList.size() > 0){
            for(Position__c postionObj : positionList){
                postionObj.Count_Of_Job_App__c = postionObj.job_applications__r.size();//Error on this line.
            }
            update positionList;
        }
    }
}
Hello,
We are using the Bulk API to insert records in a custom object, which uses a Master-Detail field to the Contact object. 
I am sending my data in JSON format.  Here is a sample of that payload:  (Contact__r is the Relationship Name of the Master-Detail field)
[
    {
        "Subscriber_Key__c": "0030a00001sjeAXAAY",
        "Contact__r": {
            "Id": "0030a00001sjeAXAAY"
        },
        "Job_Id__c": "72299",
        "Subscriber_ID__c": "35827818",
        "Email_Address__c": "shelby@email.com",
        "Email_Name__c": "Early Bird Template Based Email - 20181211_132833",
        "Email_Subject__c": "test email",
        "Dynamic_Email_Subject__c": "",
        "From_Name__c": "Pittsburgh Three Rivers Marathon, Inc. (P3R)",
        "From_Email__c": "Long@email.com",
        "Event_Type__c": "Send",
        "Event_Sub_Type__c": "",
        "Event_Date__c": "2019-01-08",
        "Is_Unique__c": false,
        "URL__c": "",
        "Account__c": "100012345",
        "Business_Unit_Id__c": "100012345"
    },
    {
        "Subscriber_Key__c": "0030a000024Mv81AAC",
        "Contact__r": {
            "Id": "0030a000024Mv81AAC"
        },
        "Job_Id__c": "72299",
        "Subscriber_ID__c": "35827820",
        "Email_Address__c": "brady@email.com",
        "Email_Name__c": "Early Bird Template Based Email - 20181211_132833",
        "Email_Subject__c": "test email",
        "Dynamic_Email_Subject__c": "",
        "From_Name__c": "Pittsburgh Three Rivers Marathon, Inc. (P3R)",
        "From_Email__c": "Long@email.com",
        "Event_Type__c": "Send",
        "Event_Sub_Type__c": "",
        "Event_Date__c": "2019-01-08",
        "Is_Unique__c": false,
        "URL__c": "",
        "Account__c": "100012345",
        "Business_Unit_Id__c": "100012345"
    },
    {
        "Subscriber_Key__c": "0031800000UnAxwAAF",
        "Contact__r": {
            "Id": "0031800000UnAxwAAF"
        },
        "Job_Id__c": "57113",
        "Subscriber_ID__c": "34693791",
        "Email_Address__c": "lennie@email.com",
        "Email_Name__c": "Abandoned Page",
        "Email_Subject__c": "%%First Name%%, you can still get discounted registration and free swag",
        "Dynamic_Email_Subject__c": "",
        "From_Name__c": "Pittsburgh Three Rivers Marathon, Inc. (P3R)",
        "From_Email__c": "Long@email.com",
        "Event_Type__c": "Click",
        "Event_Sub_Type__c": "",
        "Event_Date__c": "2019-01-07",
        "Is_Unique__c": true,
        "URL__c": "",
        "Account__c": "100012345",
        "Business_Unit_Id__c": "100012345"
    },
    {
        "Subscriber_Key__c": "0031800000UnAxwAAF",
        "Contact__r": {
            "Id": "0031800000UnAxwAAF"
        },
        "Job_Id__c": "57113",
        "Subscriber_ID__c": "34693791",
        "Email_Address__c": "lennie@email.com",
        "Email_Name__c": "Abandoned Page",
        "Email_Subject__c": "%%First Name%%, you can still get discounted registration and free swag",
        "Dynamic_Email_Subject__c": "",
        "From_Name__c": "Pittsburgh Three Rivers Marathon, Inc. (P3R)",
        "From_Email__c": "Long@email.com",
        "Event_Type__c": "Open",
        "Event_Sub_Type__c": "",
        "Event_Date__c": "2019-01-07",
        "Is_Unique__c": false,
        "URL__c": "",
        "Account__c": "100012345",
        "Business_Unit_Id__c": "100012345"
    },
    {
        "Subscriber_Key__c": "0030a000024Mv81AAC",
        "Contact__r": {
            "Id": "0030a000024Mv81AAC"
        },
        "Job_Id__c": "72299",
        "Subscriber_ID__c": "35827820",
        "Email_Address__c": "brady@email.com",
        "Email_Name__c": "Early Bird Template Based Email - 20181211_132833",
        "Email_Subject__c": "test email",
        "Dynamic_Email_Subject__c": "",
        "From_Name__c": "Pittsburgh Three Rivers Marathon, Inc. (P3R)",
        "From_Email__c": "Long@email.com",
        "Event_Type__c": "Open",
        "Event_Sub_Type__c": "",
        "Event_Date__c": "2019-01-08",
        "Is_Unique__c": true,
        "URL__c": "",
        "Account__c": "100012345",
        "Business_Unit_Id__c": "100012345"
    },
    {
        "Subscriber_Key__c": "0030a00001sjeAXAAY",
        "Contact__r": {
            "Id": "0030a00001sjeAXAAY"
        },
        "Job_Id__c": "72299",
        "Subscriber_ID__c": "35827818",
        "Email_Address__c": "shelby@email.com",
        "Email_Name__c": "Early Bird Template Based Email - 20181211_132833",
        "Email_Subject__c": "test email",
        "Dynamic_Email_Subject__c": "",
        "From_Name__c": "Pittsburgh Three Rivers Marathon, Inc. (P3R)",
        "From_Email__c": "Long@email.com",
        "Event_Type__c": "Open",
        "Event_Sub_Type__c": "",
        "Event_Date__c": "2019-01-08",
        "Is_Unique__c": true,
        "URL__c": "",
        "Account__c": "100012345",
        "Business_Unit_Id__c": "100012345"
    },
    {
        "Subscriber_Key__c": "0030a000024Mv81AAC",
        "Contact__r": {
            "Id": "0030a000024Mv81AAC"
        },
        "Job_Id__c": "72299",
        "Subscriber_ID__c": "35827820",
        "Email_Address__c": "brady@email.com",
        "Email_Name__c": "Early Bird Template Based Email - 20181211_132833",
        "Email_Subject__c": "test email",
        "Dynamic_Email_Subject__c": "",
        "From_Name__c": "Pittsburgh Three Rivers Marathon, Inc. (P3R)",
        "From_Email__c": "Long@email.com",
        "Event_Type__c": "Open",
        "Event_Sub_Type__c": "",
        "Event_Date__c": "2019-01-08",
        "Is_Unique__c": false,
        "URL__c": "",
        "Account__c": "100012345",
        "Business_Unit_Id__c": "100012345"
    }
]
However, the result of the Bulk API is always that the Id field of Contact is not an External ID or not indexed. 
[
    {
        "success": false,
        "created": false,
        "id": null,
        "errors": [
            {
                "message": "Field name provided, Id is not an External ID or indexed field for Contact",
                "fields": [],
                "statusCode": "INVALID_FIELD",
                "extendedErrorDetails": null
            }
        ]
    },
    {
        "success": false,
        "created": false,
        "id": null,
        "errors": [
            {
                "message": "Field name provided, Id is not an External ID or indexed field for Contact",
                "fields": [],
                "statusCode": "INVALID_FIELD",
                "extendedErrorDetails": null
            }
        ]
    },
    {
        "success": false,
        "created": false,
        "id": null,
        "errors": [
            {
                "message": "Field name provided, Id is not an External ID or indexed field for Contact",
                "fields": [],
                "statusCode": "INVALID_FIELD",
                "extendedErrorDetails": null
            }
        ]
    },
    {
        "success": false,
        "created": false,
        "id": null,
        "errors": [
            {
                "message": "Field name provided, Id is not an External ID or indexed field for Contact",
                "fields": [],
                "statusCode": "INVALID_FIELD",
                "extendedErrorDetails": null
            }
        ]
    },
    {
        "success": false,
        "created": false,
        "id": null,
        "errors": [
            {
                "message": "Field name provided, Id is not an External ID or indexed field for Contact",
                "fields": [],
                "statusCode": "INVALID_FIELD",
                "extendedErrorDetails": null
            }
        ]
    },
    {
        "success": false,
        "created": false,
        "id": null,
        "errors": [
            {
                "message": "Field name provided, Id is not an External ID or indexed field for Contact",
                "fields": [],
                "statusCode": "INVALID_FIELD",
                "extendedErrorDetails": null
            }
        ]
    },
    {
        "success": false,
        "created": false,
        "id": null,
        "errors": [
            {
                "message": "Field name provided, Id is not an External ID or indexed field for Contact",
                "fields": [],
                "statusCode": "INVALID_FIELD",
                "extendedErrorDetails": null
            }
        ]
    }
]
I was under the impression that the ID field of standard object is always indexed by default.  Is there anything else that need to be done to either the custom object or Contact to allow the lookup ?

Any advice or insight would be much appreciated.

Thank you!
Cheers,

Francois

Hi all, Any hints on how to get person accounts made available?

 

From the documentation I've read it looks like I need to request it from SF directly, but for the life of me I can't seem to locate a method to make that request.

 

Thanks

-M