I am using Apex to call an SOQL query that returns records and a few of their associated fields, some of which are formula fields which (to my understanding) are not writeable. I am then passing this list to a LWC Data Table within the LWC.

I am wanting to remove cells from the data table that do not match the current project. One of these fields happens to be the "Project_ID__c" field, this field is a formula field. I have tried to edit them directly by simply comparing each record and setting the fields I would like to be left out of the data table to null or a blank string, however I am met with the error "Field is not writeable: Project_Contact__c.Project_ID__c".

Is there a way to either remove these fields from the data table or to make a copy of the list in which the fields are cast as editable strings? I will leave snips of my code below for reference.

public static List<Project_Contact__c> searchContacts(String businessName, String PID, String Name, String PCID, String CID)

    List<Project_Contact__c> StartList = Database.query(QueryString);
    return StartList;
@track columns =

@wire(searchContacts, {businessName:'$businessName', PID:'$projectId', Name:'$name', PCID:'$pcid', CID:'$cid'})
    wiredAccounts({error, data})
        if (data)
            this.accList = data.map(row=>{
                return{Test: row.Contact__r.AccountId,
                       Name: row.Full_Name__c,
                       ID: row.Project_ID__c,
                       Business: row.Business_Entity_Name__c,
                       Owner: row.Owner_Full_Name__c,
                       Status: row.Status__c,
                       LastReason: row.Last_Reason__c
            this.error = undefined;
        else if (error)
            this.error = error;

1 Answer 1


try using a wrapper class instead. the class should all the fields you need to display on your datatable (most likely fields coming from you Project_Contact__c query result). and before returning the SObject list, you iterate your result set, perform any validations you need, and then return a list of wrapper objects.

public class Wrapper {
    public String id;
    public String name;
    public String projectId;

    public Wrapper(Project_Contact__c pc) {
        this.id = pc.Id;
        this.name = pc.Name;
        // this would be your formula field.
        this.projectId = pc.Project_Id__c;

then in your searchContacts apex method, something like this:

List<Project_Contact__c> StartList = Database.query(QueryString);
// list to be returned
List<Wrapper> wrappers = new List<Wrapper>();
for (startObject so : StartList) {
    Wrapper w = new Wrapper(so);
    // perform any validation you need
    if (true) {
        // clear the value
        w.projectId = null;

return wrappers;

Of course, change your method's signature from: public static List<Project_Contact__c> searchContacts to public static List<Wrapper> searchContacts

hope it helps!

  • Works great! Thank you very much.
    – JLadage
    Jun 13, 2022 at 13:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .