function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NaishadhNaishadh 

Retrieve Parent Campaign : too many sql query

Hi,

I want to retrieve ultimate parent of each campaign.
E.g.
Campaign1
--- Campaign1.a
-------Campaign1.a.1

So the ultimate parent of Campaign1.a.1 is Campaign1.

I have developed following code which is working fine in small number of record but if I tried to update bulk records it gives "Too many SQL query" error.

public static String getUltimateParent(String pId) {
        Campaign[] campdata = [Select c.Id,c.ParentId From Campaign c where c.Id = :pId];

        if(campdata.size() > 0) {
            if(campdata[0].ParentId == null) {
                return campdata[0].Id;
            } else {
                return getUltimateParent(campdata[0].ParentId);
            }
        }
        return null;
    }

Any help?
AnjaanAnjaan

Hello Naishadh,

            

               It really is a problem. You are not allowed to make more than 100 calls to db at the same time. I came across this problem. What i did is that, I needed 32 fields from the db so i wrote 32 quries (Dynamic) and in each query I got the specific field  and after getting all the fields i merged them in one. Your scenario may be different but you have to do something like I did.

 

 

Thanks and Regards

 

Osman Ashraf Bajwah

Technosoft Solutions.

SalesForce Developer.

NaishadhNaishadh

Hi,

 

Thanks for reply. I need only two fields from campaign but total number of records are almost 5000 and Salesforce dont allow more than 1000 record in list.