• Austin Mayerhofer
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 1
    Replies
Hi all,

I'm trying to display a table of values on my VF page based on if I have 1 or more objects in the backend for a custom object pending_food__c. If there's pending_food__c objects that exist, display a table, if there's not, don't display a table.

For example, I'm trying to achieve this by doing:
<apex:pageBlockSectionItem rendered="{![SELECT Id FROM pending_food__c].size() > 0}">     
</apex:pageBlockSectionItem>
But I'm getting " Syntax error.  Missing '=' ". How can I implement the functionality of displaying based on whether there's pending_food__c's in the backend?
Hi all, I'm creating an inventory management system for a group of customers. They want to be able to keep a database of food items (I've created a custom object food__c) and invoices (I've been using Salesforce files).

I created a VF/Apex page for invoice parsing. The database of food items works. The invoice pdf I store in Salesforce files using ContentVersion and then I use ContentDocumentLink to upload the pdf to the Group I'm in.

I'm wondering though, the sharing setting for food__c is that "All users can see this list view", is there a similar behavior that's possible for Salesforce files? So that all users can go to "files" and see the files that have been uploaded? Or will I still have to use ContentDocumentLink to store the files in the Group so that everyone can see them?

Also, is it possible to attach a custom 6 digit ID to an uploaded file? Maybe I can do this in Object Manager for ContentVersion?

Appreciate any help!
I have a custom object, food__c, and a webhook that inserts foods to our database.

I have food__c objects already in the database with product reference numbers, and when the webhook inserts foods, it will add the food__c regardless of whether the reference number already exists, in which case I would like it to update the quantity of the already existing food__c item, but instead I have been writing a trigger to check when something is inserted.
 
trigger InvoiceEntry on food__c (before insert, after insert) {
    if (Trigger.isBefore) {
        
        List<food__c> foods = [SELECT Quantity__c, Product_Reference__c FROM food__c];
        
        for (food__c f : Trigger.New) {
            if (f.Product_Reference__c != null) {
                for (food__c stored_food : foods) {
                    if (f.Product_Reference__c == stored_food.Product_Reference__c) {
                        stored_food.Quantity__c += f.Quantity__c;
                        update stored_food;

                    }
                }
            }
        }
    }
    if (Trigger.isAfter) {
        List<food__c> foods = [SELECT Quantity__c, Product_Reference__c FROM food__c];
        List<food__c> same_food = new List<food__c>();
        for (food__c f : Trigger.New) {
            if (f.Product_Reference__c != null) {
                for (food__c stored_food : foods) {
                    if (f.Product_Reference__c == stored_food.Product_Reference__c) {
                        //System.debug(stored_food.Quantity__c + ': ' + foods.size());
                        same_food.add(stored_food);
                    }
                }
            }
            
            if (same_food.size() > 1) {
                if (same_food[0].Quantity__c < same_food[1].Quantity__c) {
                    delete same_food[0];
                }
                else if (same_food[0].Quantity__c > same_food[1].Quantity__c) {
                    delete same_food[1];
                }
                else {
                    delete same_food[0];
                }
            }
        }
    }

This works but seems horribly inefficient. I am trying to find a quick way to check, when an object is inserted, if its product reference number already exists in the database or not. If it already exists, update the quantity and don't insert the object. If it doesn't exist, just insert.

With my current code I'm looking through every item in the backend, and doing this for every food__c that is inserted, leading to O(n^2) runtime.

How can I make my code more efficient, and is there a better way to prevent something from being inserted?

To prevent duplicate food__c's from being entered, I tried using addError for food__c's that already existed in the database, but this would send an error back through the webhook and roll back the entire round of inserts.

Thank you.
Hi all, I'm working with a pdf parsing service called Docparser. I currently have functionality for sending POST and GET requests from my page to Docparser. Both work just fine. However, I'd like to set up a webhook so I don't have to send continuous GET requests, but rather have it send my code a POST request when parsing is finished.

Attached below is a picture of Docparser's setup for a Webhook. Docparser will be sending POST requests to my code.

I'm confused as to what I should put for the "Target URL" and "Additional Headers" though?

I've been doing some research and think I may need to set up my Apex code to handle requests. Such as this: https://trailhead.salesforce.com/en/content/learn/modules/apex_integration_services/apex_integration_webservices

Is this trailhead what I'm looking for? But also what would I eventually use as the Target URL and Additional Headers?

Any help is appreciated, thank you.

User-added image
Hi all, I'm having some issues with what I think is an access issue.
 
I have code where the user uploads a pdf to a VisualForce page, and clicks a button which sends that pdf both to Salesforce files and the files in the specified group. This works perfectly when I enter the VisualForce Page in "Preview" from the Developer Console.
 
However, this doesn't work when I go to the actual URL of my Site. I am taken to a "Authorization Required" page after clicking the button and no files are stored. To be clear, by "actual URL" I mean when you go to Salesforce Sites and click the URL of your Site (which has the VisualForce page as its home page).
 
I've found that the main reason this is probably happening is an error. In preview, the SOQL query which is assigned to the pantryGroups variable has a size of 1, indicating it returned the correct group, but at the URL, the pantryGroups variable has a size of 0. Up to this point I did a few hours of research on public access settings to fix other Authorization Required pages but couldn't solve this issue. I was looking into "Profile" and see that I am a System Administrator so I went to give SysAdmins access to the VisualForce page and Apex class, but they already did.
 
What's going on here? When I go to the URL am I not actually a System Administrator at that point? Would I be considered a guest user? Any help is appreciated. I am trying to upload the file to both my Salesforce files and the groups files. Works perfectly fine in Preview, SOQL fails at the URL.
 
 
 
Here's the Apex code that runs when the button is clicked (pdfFile is a ContentVersion object):
 
// insert the file into the SF backend
pdfFile.PathOnClient = pdfFile.Title + '.pdf'; // The files name which will help in preview
pdfFile.ContentLocation = 'S'; // to use S specify this document is in Salesforce, to use E for external files
insert pdfFile;
 
// retrieve the uploaded file ID
Id pdfFileId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: pdfFile.Id].ContentDocumentId;
 
// insert ContentDocumentLink to share file with
ContentDocumentLink pdfLink = new ContentDocumentLink();
pdfLink.ContentDocumentId = pdfFileId;
List<CollaborationGroup> pantryGroups=[select id, MemberCount from CollaborationGroup where Name=:groupName]; // grab the group from SF backend.
System.debug('groups size: ' + pantryGroups.size()); // prints 1 in preview, 0 at URL
CollaborationGroup pantryGroup = pantryGroups[0];
pdfLink.LinkedEntityId = pantryGroup.Id; // link the file to group
pdfLink.Visibility = 'AllUsers'; // all users in group can see
pdfLink.ShareType = 'C'; // all users in group can edit file
insert pdfLink;

 
I have a custom object, food__c, and a webhook that inserts foods to our database.

I have food__c objects already in the database with product reference numbers, and when the webhook inserts foods, it will add the food__c regardless of whether the reference number already exists, in which case I would like it to update the quantity of the already existing food__c item, but instead I have been writing a trigger to check when something is inserted.
 
trigger InvoiceEntry on food__c (before insert, after insert) {
    if (Trigger.isBefore) {
        
        List<food__c> foods = [SELECT Quantity__c, Product_Reference__c FROM food__c];
        
        for (food__c f : Trigger.New) {
            if (f.Product_Reference__c != null) {
                for (food__c stored_food : foods) {
                    if (f.Product_Reference__c == stored_food.Product_Reference__c) {
                        stored_food.Quantity__c += f.Quantity__c;
                        update stored_food;

                    }
                }
            }
        }
    }
    if (Trigger.isAfter) {
        List<food__c> foods = [SELECT Quantity__c, Product_Reference__c FROM food__c];
        List<food__c> same_food = new List<food__c>();
        for (food__c f : Trigger.New) {
            if (f.Product_Reference__c != null) {
                for (food__c stored_food : foods) {
                    if (f.Product_Reference__c == stored_food.Product_Reference__c) {
                        //System.debug(stored_food.Quantity__c + ': ' + foods.size());
                        same_food.add(stored_food);
                    }
                }
            }
            
            if (same_food.size() > 1) {
                if (same_food[0].Quantity__c < same_food[1].Quantity__c) {
                    delete same_food[0];
                }
                else if (same_food[0].Quantity__c > same_food[1].Quantity__c) {
                    delete same_food[1];
                }
                else {
                    delete same_food[0];
                }
            }
        }
    }

This works but seems horribly inefficient. I am trying to find a quick way to check, when an object is inserted, if its product reference number already exists in the database or not. If it already exists, update the quantity and don't insert the object. If it doesn't exist, just insert.

With my current code I'm looking through every item in the backend, and doing this for every food__c that is inserted, leading to O(n^2) runtime.

How can I make my code more efficient, and is there a better way to prevent something from being inserted?

To prevent duplicate food__c's from being entered, I tried using addError for food__c's that already existed in the database, but this would send an error back through the webhook and roll back the entire round of inserts.

Thank you.