Skip to main content

Posts

Showing posts from September, 2018

Dynamic Routing Approval

Use Case  When Sales Rep submits Opportunity it requires different approver for different approval stage for different region. Solution  Create object to store approver details such for stage and region.Create Opportunity field to store approver for that particular Opportunity, these fields can be referred in Approval process. Using trigger query the approvers record and populate it in Opportunity based on specific criteria. Meanwhile you can take a look in Appexchange, there an apps named Dynamic Approval Routing. It is unmanaged package so we can view and modify the code to suit our need.The apps actually is a sample on how we can define approver for specific object.Its rule defined in the code and you might have different approver criteria and different object.The concept is to have one object to store approver details and create fields on object that going to be approved. create trigger on object that going to be approved to populate approver fields. Design struc

Dynamic SOQL with SubQuery using SObject class

Requirement to have dynamic query that enable to retrieve the child of the parent objects.For example query the Opportunities field while querying Account instead of run separate query for each object. For this post, I hard code object name and field name which actually can be done dynamically. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 String childF = 'Name'; String childO_1 = 'Opportunity'; String childF_1 = 'Name'; if (childO == 'Contact'){ childO = 'Contacts'; } if (childO_1 == 'Opportunity') { childO_1 = 'Opportunities'; } // create dynamic SOQL query string String query = 'SELECT id, (select ' +childF+ ' from ' +childO+') ,(select '+childF_1 + ' from '+childO_1+') FROM ' +parentO; // query and store results in variable p