Support » Plugin: Object Sync for Salesforce » SOQL with OR

  • Resolved jellypixel

    (@jellypixel)


    Hi guys, first THANK YOU for this amazing plugin.

    I have around 100.000 records on my salesforce and just need to sync around 800 of them. I realized that I can use SOQL to do this by extending the hook object_sync_for_salesforce_pull_query_modify like so:

    add_filter( ‘object_sync_for_salesforce_pull_query_modify’, ‘change_pull_query’, 10, 4 );
    function change_pull_query( $soql, $type, $salesforce_mapping, $mapped_fields ) {
    $soql->add_condition( ‘abc’, ‘true’, ‘=’ );
    return $soql;
    }

    However I need multiple OR filter for this and I think this filter only receive AND statement. Is it possible to add OR rules here?

    Thank you guys!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Contributor Jonathan Stegall

    (@jonathanstegall)

    @jellypixel that’s a good question. No, currently it doesn’t support OR rules; the SOQL object constructor is not very comprehensive with how it handles the conditionals. I’d be open to a pull request that would expand it if it could be done in an unobtrusive way. I could see it expanding how the query object gets parsed, maybe? But also there are spots where the query is used as a string and maybe there should be a separate filter for folks who want to write their own SOQL queries. I’m not opposed to either of those.

    In any case, here’s where the SOQL object gets created, if you’d want to take a look: https://github.com/MinnPost/object-sync-for-salesforce/blob/master/classes/class-object-sync-sf-salesforce-select-query.php

    Thread Starter jellypixel

    (@jellypixel)

    Hi Jonathan!

    Thank you for the kind reply! I will need to run this through my client first (because it will cost them) but if they are up to it I think I would just make a new function there where people can just write their own queries.

    I think the current AND methods are good for most cases and those who want an OR logic should just write it themselves.

    another way around it is rather than using ->add_condition we send an ARRAY like wp_query. But honestly it might be too complicated and people who understand to write that would rather writing the SOQL queries themselves.

    • This reply was modified 8 months, 3 weeks ago by jellypixel.
    • This reply was modified 8 months, 3 weeks ago by jellypixel.

    Hi @jellypixel, we had the same use case and ultimately found it easier to add a single boolean (checkbox) field in Salesforce that handled the OR filtering on that end. Essentially, it was a checkbox formula field in SFDC that looked for the conditions to trigger TRUE (OR statements), and then we added the webhook to only sync records where that field = TRUE. I do agree this would be a great addition to the fieldmap creation section of the plugin though!

    Thread Starter jellypixel

    (@jellypixel)

    Hi @adambocik ! Wow that is an ingenious idea! I really like it!

    I forwarded the solution to my client, they have been away for some time so I haven’t got any reply even with the original proposed solution (adding a custom query) but I imagine they would love this solution more.

    Thanks mate!

    • This reply was modified 8 months, 2 weeks ago by jellypixel.

    Glad I could help!

    Plugin Contributor Jonathan Stegall

    (@jonathanstegall)

    @jellypixel so I’ve added a new filter that developers could use to edit the SOQL once it’s been converted to a string. I’m thinking I’ll add it into the next plugin release.

    Here’s a pull request for it, if you’d want to test it: https://github.com/MinnPost/object-sync-for-salesforce/pull/432

    Plugin Contributor Jonathan Stegall

    (@jonathanstegall)

    I’ve merged this into the next release. I’m not sure when that’ll be out; I’m still hoping for someone who is willing to test one other piece of that release. But hopefully soon.

    In any case, unless you have more that this feature needs, @jellypixel, I’m going to mark this one as resolved.

    Thread Starter jellypixel

    (@jellypixel)

    Hi @jonathanstegall ! Thank you very much for this. My client actually used @adambocik ‘s suggestion at the end but I just want to say THANK YOU so much for adding this feature. I think it will be very useful :). Super appreciate the response I got as well so thanks for being so amazing!

    Sorry for just coming back to you, life gets in the way.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘SOQL with OR’ is closed to new replies.