• blacknred
  • 10 Points
  • Member since 2012

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 9


I write a schedule :


global class Sch01 implements Schedulable{

   global void execute(SchedulableContext sc) {

     AccountOwnerReassignment acc = new AccountOwnerReassignment();




and this test class;

static testmethod void t62()

        Sch01 sh = new Sch01();
        String sch = '0 0 5 * * ?';
        system.schedule('Schedule TEST', sch, sh);


Ihave this error :Save error: Method does not exist or incorrect signature: Test.startTest().


Please, what is the problem??






I have 4 fields in the account object that disclose the following:


Product: (multi-select pick list) which correlates to a product pick list in the case object

POD: This is a group that is assigned to the account. There is a queue created for each "POD"

Member1: User lookup that is a member of the POD

Member2: User lookup that is a member of the POD


I would like to build a system that when a case is created and based on the account and product that's selected a decision will be made to assign to the correct queue based on the POD and product disclosed within the account. Also, in addition to the dynamic assignment rules, if the case is sev1  an email notification is sent to the members of the POD. I believe a trigger is the route to take instead of a workflow rule because of the scale. I'm looking at 20+ PODS with hundreds of account \ product combinations that will require case assignments to the queues. Also these combinations could change on a regular basis.


I have experience building workflow rules but no experience with APEX triggers. So any help would be greatly appreciated.


Thank you.


Hey all,


This is one of those questions when I feel like I'm probably going about a simple process the wrong way and over complicating it, but I'm not sure the alternative. So I'll ask my question and if you have a better approach, please feel free to share.


The deal is that I have an Apex REST service that allows a user to pass in an object type, and any field values in the URL.

EX : http://na2.salesforce.com/apex/reservice/contact?firstname=frank&lastname=jones&age__c=21


My code works fine for any string values, but chokes on numerics. Because I instantiate a new instance of the type of object they pass in, then I loop over all the fields in the query string and dynamically add them to the sObject. Of course as far as apex is concerned all those arguments in the query string are in fact strings, so when adding non string things to the sObject it explodes. 


Ideally I could use the get describe info about the field I'm inserting to find it's type and cast the value to be inserted to the correct type, but as far as I know there isn't a way to do dynamic casting at runtime. A series of if statments is about the only alternative I see, but that feels really dirty. 


This is what I have currently (you can see I'm kind of using the if statment path, trying to make it as simple as possible).


Just to be clear, this code works, it's just not as efficient/dynamic as I'd like.


    public static sObject saveSObject(string objectType, string recordid, RestRequest req)
        //create a generic sObject to contain the update values.
        sObject updateObj;      
        //get the describe object for the type of object passed in (its just passed in as a string from the URL)
        Schema.sObjectType objectDef = Schema.getGlobalDescribe().get(objectType).getDescribe().getSObjectType();
        //find all the fields for this object type
        Map<String, Schema.SobjectField> ObjectFieldsMap = objectDef.getDescribe().fields.getMap();
        //this method can handle updates or inserts. If a record ID was passed in, 
        //cast the object as the type represented by the ID. If not, just create a
        //new object of the type found in the object describe.
        if(recordId != null)
            updateObj = objectDef.newSobject(recordid);
            updateObj = objectDef.newSobject();
        // populate the object's fields by looping over all the params in the rest request.
        for (String key : req.params.keySet())
            // only add params if they are valid field on the object
            if (ObjectFieldsMap.containsKey(key))
                //figure out the type of this field so we can cast it to the correct type
                string fieldType = ObjectFieldsMap.get(key).getDescribe().getType().name().ToLowerCase();
                //since I don't know how to do, or if it's even possible to do dynamic casting we need a 
                //series of if statments to handle the casting to numeric types. I think all the others should
                //be fine if left as a string. Dates might explode, not sure.
                if(fieldType == 'currency' || fieldType == 'double' || fieldType == 'percent' || fieldType == 'decimal' )
                    updateObj.put(key, decimal.valueOf(req.params.get(key).trim())); 
                else if(fieldType == 'boolean')
                    updateObj.put(key, Boolean.valueOf(req.params.get(key))); 
                else if(fieldType == 'date')
                    updateObj.put(key, date.valueOf(req.params.get(key))); 
                    updateObj.put(key, req.params.get(key));
                system.debug('Invalid field: '+ key + ' for object type ' + objectType);
        //update/insert the object
        upsert updateObj;
        //return the saved object.
        return updateObj;


I am interested in using streaming to replace my trigger/future or outbound messaging integration with another system.


but the soql says select x,y,z from object where flag=true


the remote system will update object whenever there are returning changes.. this will cause the soql to fire I think,

and then the streaming client will be notified of changes.   but I don't want THESE changes sent back to the remote,

as the remote is the one that made them.  .


in my trigger I compare a flag set ONLY on the remote update to cancel the trigger.


in my outbound message I use workflow rules to check the same flag set only by the remote system.


how do I prevent this loop with the streaming api? or does the callback get fired and I have t check the flag in the

client system, and hope that the notification time interval doesn't mask a SF UI sourced change.(as compared to the incoming web service api sourced change)