You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
Utility Class error
I am trying to create a utility class but it keeps throughing an error.
Here is the original code
Here is the utility class
So in the original class I am trying this
It states that the return statement is missing and that objecttype is invalid. Is it becasue I am trying to use the Object and I am actaully passing in a string?
Thanks
P
Here is the original code
List<Directory_Template__c> directorytemplate = ([select id,Name from Directory_Template__c where Sobject__c = 'Project' AND Active__c = true limit 1]); for (Permit__c proj : (List<Permit__c >) trigger.New){ for (Directory_Template__c dir : directorytemplate) { if (dir.Id != null) { proj.Directory_Template__c = dir.Id; } } }
Here is the utility class
global class ViewUtils { public static String getDirectory(String objectType){ List<Directory_Template__c> directorytemplate = new List<Directory_Template__c>(); system.debug('objectType '+ objectType); if(objectType == 'Programme__c'){ directorytemplate = ([select id,Name from Directory_Template__c where Sobject__c = 'Programme' AND Active__c = true limit 1]); for (Programme__c prog : (List<Programme__c >) trigger.New){ for (Directory_Template__c dir : directorytemplate) { if (dir.Id != null) { return prog.Directory_Template__c = dir.Id; } } } } else{ directorytemplate = ([select id,Name from Directory_Template__c where Sobject__c = 'Project' AND Active__c = true limit 1]); for (objectType proj : (List<objectType >) trigger.New){ for (Directory_Template__c dir : directorytemplate) { if (dir.Id != null) { return proj.Directory_Template__c = dir.Id; } } } } } }
So in the original class I am trying this
ViewUtils.getDirectory('Permit__c');
It states that the return statement is missing and that objecttype is invalid. Is it becasue I am trying to use the Object and I am actaully passing in a string?
Thanks
P
You might want to try changing the below line to return a string instead