@Gelos
Also, as a follow on - the ForAll is backward in your formula and not used properly. ForAll returns a table of records, it is very inefficient as a ForLoop like in development (which PowerApps is not!).
If the columns of your collection have the primary key (Id) and the names match, then the only formula you need is:
Patch(tablename, collectionname)
What is nice about this as well, is that if a primary key is found, Patch will update it. If a primary key is NOT found, then it will create a record. So, you can use the above very efficiently to both update and create at the same time.
In the above, the entire table is given to patch all at once and Patch is instantiated once. With a ForAll, the Patch is instantiated for each iteration of the ForAll table source, this will impact performance heavily.
If a more customized record is needed from a collection (i.e. the column names don't match), you can utilize the RenameColumns function to make them match and the DropColumn (or ShowColumns depending on the number of columns in your collection) to match the columns you want in your patch.
So, if your collection, for example, had a column called "PersonName" where the record in the datasource wanted a column called "name" and you also had a "Status" column in the collection, which does not exist in the datasource, then your formula would be:
Patch(tablename,
DropColumns(
RenameColumns(collectioname, "PersonName", "name"),
"Status"
)
)
Again, the above provides a table of records to the Patch function and it is only instantiated once.
If you need more customization, the ForAll is one of the most powerful functions in PowerApps (when used right)! ForAll creates a table. Then this can be used to provide to the Patch function. Example, you want to change the name of all records and prepend the name with "Name:"
Patch(tablename,
ForAll(collectionname,
{Id: Id
name: "Name:" & name,
Age: Age
}
)
)
This will provide a table to the patch function that will have that adjustment made.
To avoid all the typing of column names when modifying only one or a select few columns, this formula would do the exact same as the above formula:
Patch(tablename,
ForAll(collectionname As _item,
Patch(_item, {name: "Name:" & name})
)
)
Again, all of the above are more performant as the Patch function is only instantiated once and provided a table of records that are all ready to go.
When the ForAll is backward, PowerApps has to repeat the same actions and instantiate the Patch function for each iteration of the ForAll table. While it might work, performance will suffer and, as you can see, you will type much more formula to have to maintain.
Once you view the ForAll as the function it was made to be, you will find it to be the most powerful function in PowerApps! Looking at it as a ForLoop and you will curse at it for what it is not.
I hope this is informative and helpful for you.