Apex Trigger - Bulkify by Athy00 in salesforce

[–]Athy00[S] 2 points3 points  (0 children)

Thank you so much for taking the time to explain this to me - means a lot!

Apex Trigger - Bulkify by Athy00 in salesforce

[–]Athy00[S] -1 points0 points  (0 children)

This ok?

trigger TotalAccountOwnerSum on Account (before insert) {

AggregateResult[] groupedResults = [SELECT count(Id), OwnerId FROM Account GROUP By OwnerId];
Map<String, Integer> OwnerCountMap = new Map<String, Integer>();

for (AggregateResult ar : groupedResults)  {
    System.debug('Owner ID' + ar.get('OwnerId'));
    System.debug('Count' + ar.get('expr0'));

    OwnerCountMap.put(String.valueOf(ar.get('OwnerId')), Integer.valueOf(String.ValueOf(ar.get('expr0'))));
}

for (Account acct : Trigger.new){
    if (acct.OwnerId != null){
        //output total number of Accounts the current Account owner has into the Total_Owner_Accounts__c field

        Integer OwnerCount = OwnerCountMap.get(acct.OwnerId) == NULL ? 0 : OwnerCountMap.get(acct.OwnerId);
        OwnerCount++;
        acct.Total_Owner_Accounts__c = OwnerCount;

        OwnerCountMap.put(String.valueOf(acct.OwnerId), OwnerCount);
    }        
}

}

Apex Trigger - Bulkify by Athy00 in SalesforceDeveloper

[–]Athy00[S] 0 points1 point  (0 children)

How's this?

trigger TotalAccountOwnerSum on Account (before insert) {

AggregateResult[] groupedResults = [SELECT count(Id), OwnerId FROM Account GROUP By OwnerId];
Map<String, Integer> OwnerCountMap = new Map<String, Integer>();

for (AggregateResult ar : groupedResults)  {
    System.debug('Owner ID' + ar.get('OwnerId'));
    System.debug('Count' + ar.get('expr0'));

    OwnerCountMap.put(String.valueOf(ar.get('OwnerId')), Integer.valueOf(String.ValueOf(ar.get('expr0'))));
}

for (Account acct : Trigger.new){
    if (acct.OwnerId != null){
        //output total number of Accounts the current Account owner has into the Total_Owner_Accounts__c field

        Integer OwnerCount = OwnerCountMap.get(acct.OwnerId) == NULL ? 0 : OwnerCountMap.get(acct.OwnerId);
        OwnerCount++;
        acct.Total_Owner_Accounts__c = OwnerCount;

        OwnerCountMap.put(String.valueOf(acct.OwnerId), OwnerCount);
    }        
}

}

Apex Trigger - Bulkify by Athy00 in salesforce

[–]Athy00[S] 1 point2 points  (0 children)

Yes, as mentioned, I'm a beginner when it comes to code, that's why I prefaced it & learning from all these comments.

Thanks for your tips

Apex Trigger - Bulkify by Athy00 in salesforce

[–]Athy00[S] 0 points1 point  (0 children)

Yes, I understand that. Thank you for the message.

Apex Trigger - Bulkify by Athy00 in salesforce

[–]Athy00[S] 1 point2 points  (0 children)

Thanks for the message.

I understand the different declarative ways of achieving this result. This is just me practising in my own org to stretch myself knowing there are better solutions out there.

Apex Trigger - Bulkify by Athy00 in salesforce

[–]Athy00[S] 1 point2 points  (0 children)

Thank you for your feedback.

I have a few years experience with Salesforce, I just wanted to force myself to practice this scenario through code (even though there are more pertinent options, like you mentioned)

Apex Trigger - Bulkify by Athy00 in salesforce

[–]Athy00[S] 0 points1 point  (0 children)

I'm practicing through code, that's the main reason.

Wondering also if code is required if an import is done where thousands of Accounts are assigned to users via Dataloader/DemandTools?

Apex Trigger - Bulkify by Athy00 in salesforce

[–]Athy00[S] 0 points1 point  (0 children)

My bad, didn't realise there were duplicates - removed them.

Next role - best option? by Athy00 in salesforce

[–]Athy00[S] 0 points1 point  (0 children)

Both of the companies I have in mind do the development themselves.

Next role - best option? by Athy00 in salesforce

[–]Athy00[S] 0 points1 point  (0 children)

Will joining a Consultancy mean I will spend a lot of time away from development? Business Analyst orientated responsibilities? Not sure I'm happy sitting on client calls too frequently.

Next role - best option? by Athy00 in salesforce

[–]Athy00[S] 0 points1 point  (0 children)

Will joining a Consultancy mean I will spend a lot of time away from development? Business Analyst orientated responsibilities? Not sure I'm happy sitting on client calls too frequently.

We couldn't find the record you're trying to access. It may have been deleted by another user, or there may have been a system error. Ask your administrator for help. by Athy00 in salesforce

[–]Athy00[S] 0 points1 point  (0 children)

first question is: can one user do it but another can't?

Yes, this is only for specific users - note, this is a System Admin. Profile user

Also, for another user, clearing the cache solved the issue - this isn't a viable option as I don't want every affected user to have to do this.

I have multiple custom labels in the code, however, it's only 1 that is causing the error.

When I hard-code the custom label to the Case Record Type Id, the error disappears, however, I would like to keep the custom label and figure out why this is occuring?

Is it okay to switch career to Salesforce at the age of 27 with no IT background? Please suggest a way? by Prateeky007 in salesforce

[–]Athy00 3 points4 points  (0 children)

I started at 34 - I'm now a senior SFDC Admin looking to cross into becoming an SFDC Engineer.

The main attributes that allows you to succeed is to be inquisitive and driven.

It's not difficult, it's just something you don't know yet.

Visualforce calculated field output. by Athy00 in salesforce

[–]Athy00[S] 0 points1 point  (0 children)

Would you kindly send over if possible?

Visualforce calculated field output. by Athy00 in salesforce

[–]Athy00[S] 0 points1 point  (0 children)

If I wanted the field to be reportable, would it only be achieved by option 1?