• Lars Sundberg
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 6
    Replies

I'm trying to figure out how to look up the names of all users who has access to a certain record, and display those for each record on a VF page.

 

Ideally, I want to get that data directly in the getNoteList method. But then I can't return the results as a Note__c object.

 

The other option is to use the getRecipientList method, but then I need to pass a parameter to it (like the Id of the Note__c object), and I can't do that without using a button, can I?

 

This is what I have so far:

 

VisualForce page:

 

<apex:page controller="NoteboardController">
        <apex:repeat value="{!noteList}" var="n" rendered="{!$ObjectType.Note__c.accessible}">
            <div>
                <b>From: </b><apex:outputText value="{!n.owner.Name}"/><br/>
                <b>To: </b>
                    <apex:repeat value="{!recipientList}" var="r">
                        <apex:outputText value="{!r.Name}"/>
                    </apex:repeat>
                <br/><br/>
                <apex:outputText value="{!n.Name}"/><br/><br/>
                <apex:outputText value="{!n.Note_body__c}"/>
            </div>
        </apex:repeat>
        <apex:outputText value="You don't have access the Note object" rendered="NOT({!$ObjectType.Note__c.accessible})"/>
</apex:page>

 

Controller:

 

public with sharing class NoteboardController {
    public NoteboardController() {
    }
    
    public Note__c[] getNoteList() {
        Note__c [] noteList;
        noteList = [SELECT Id, Name, Note_body__c, owner.Name FROM Note__c];
        return noteList;
    }
    
    public User[] getRecipientList() {
        //Get the name of THE FIRST user who has access to THE FIRST of the displayed Notes
        Note__c [] noteList;
        noteList = [SELECT Id, Name, Note_body__c, owner.Name FROM Note__c];
        Note__Share [] noteShare;
        noteShare = [SELECT UserOrGroupId FROM Note__Share WHERE ParentId = :noteList[0].Id];
        User [] recipientList;
        recipientList = [SELECT Name FROM User WHERE Id = :noteShare[0].UserOrGroupId];
        return recipientList;
        
        //Get the names of ALL users who has access to the displayed Notes
        //User [] recipientList;
        //recipientList = [SELECT Name FROM User WHERE Id IN (SELECT UserOrGroupId FROM Note__Share)];
        //return recipientList;
    }
}

 

I have a trigger that invokes a callout on insert of a custom object.

 

In the test below, I only get 33 % code coverage, since the inner classes Response and Data isn't covered by the test. How can I test them?

 

My class:

 

public with sharing class OuterClass {
    @future (callout=true)
    public static void doCallout() {
        //Callout occurs here normally, but to simplify:
        String body = '{"status":1,"data":[{"id":"33e26b70-ec3e-11e1-bbc0-bfcb6088709b","name":"Testname","created":"2012-08-16T14:24:32"}]}';
        getData(body);
    }
    
    public static void getData(String body) {
        Response r = (Response) JSON.deserialize(body, Response.class);
        System.debug(r.status);
        for (Data d : r.data) {
            System.debug('d.id: ' + d.id);
        }
    }
    
    class Response {
        public Integer status;
        public Data[] data;
         
        public Response(Integer status) {
            this.status = status;
            this.data = new List<Data>();
        }        
    }
    
    class Data {
        public String id;
        public String name;
        public String created;
         
        public Data(String id, String name, String created) {
            this.id = id;
            this.name = name;
            this.created = created;
        }        
    }
}

 

My testclass:

 

@isTest 
private class TestOuterClass {
    static testMethod void testOuterClass() {
        //Creating test data...
        
        Test.startTest();
        insert testdata;
        Test.stopTest();
    }
}

 

When listing records of a custom object, I'd also like to list all users that has access to it.

 

Can I access ObjectName__Share somehow and work from there?

The "Submit for approval"-button is, for some reason, displayed for _all_ my custom object in a Partner Developer Edition org.

 

Clicking it where it's not due causes this message to pop up:

 

Unable to Submit for Approval
This record does not meet the entry criteria or initial submitters of any active approval processes. Please contact your administrator for assistance.

 

The only approval process I have is the "Large Invoice Value" one from the Warehouse tutorial app in the Force.com Workbook.

 

Does anyone know why this happens, or how I get rid of it?

 

 

I started with some development a couple of weeks ago in a regular Developer Edition organization.

 

Recently I got access to a Partner Developer Edition, and so, wanted to migrate the code from the old org to the new one.

 

Experimenting with packaging (with the help of the guide at: http://www.salesforce.com/us/developer/docs/packagingGuide/index.htm), I first created a managed package (beta). This included creating a namespace which was automatically added as a prefix to all my objects, and required me to change the object references in my apex code.

 

I realized later this was not what I wanted, and so uninstalled it from the new dev org, deprecated the package in the old org, deleted it, changed the object references back in apex and created a unmanaged package instead.

 

Installing this to the new dev org went fine. All objects were created without any namespace prefix. In the old one it's still there though, which is inconvenient since the references in apex and external scripts now need to be different for the two organizations.

 

So the question is: Is it possible to remove the namespace prefix for the objects in the old, regular Developer Edition organization somehow, or am I stuck with it there?

 

 

 

 

 

Is it possible to set sharing for a record to a certain user directly when creating a record though PHP?

 

With this as reference:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm

 

I tried:

 

        $records = array();
        $records[0] = new SObject();
        $records[0]->fields = array(
            'Name' => $note_name,
            'Note_body__c' => $note_body
        );
        $records[0]->type = 'Note__c';
        $response = $client->create($records);
 
        foreach ($response as $i => $result) {
            $sharingrecords = array();
            $sharingrecords[$i] = new SObject();
            $sharingrecords[$i]->fields = array(
                'ParentId' => $result->id,
                'UserOrGroupId' => $recipient,
                'AccessLevel' => 'Read'
            );
            $sharingrecords[$i]->type = 'Note__Share';
            $sharingresponse = $client->create($sharingrecords);
        }

 

And got the error:

 

Post failed: SoapFault exception: [sf:INVALID_TYPE] INVALID_TYPE: sObject type 'Note__Share' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name.

 

(Note is a custom object, $note_name and $note_body are texts, $recipient is a user id).

 

 

Yesterday (July 25 2012) I started going through the Integration Workbook. Today I find it's quite different, despite the fact that it says it was last updated July 20.

 

I kinda liked the downloadable Java example in Tutorial #1, with the AddMerchandise class. This section is now substituted with Heroku. Did I stumble over an old version? Can I find it again somewhere?

I have a trigger that invokes a callout on insert of a custom object.

 

In the test below, I only get 33 % code coverage, since the inner classes Response and Data isn't covered by the test. How can I test them?

 

My class:

 

public with sharing class OuterClass {
    @future (callout=true)
    public static void doCallout() {
        //Callout occurs here normally, but to simplify:
        String body = '{"status":1,"data":[{"id":"33e26b70-ec3e-11e1-bbc0-bfcb6088709b","name":"Testname","created":"2012-08-16T14:24:32"}]}';
        getData(body);
    }
    
    public static void getData(String body) {
        Response r = (Response) JSON.deserialize(body, Response.class);
        System.debug(r.status);
        for (Data d : r.data) {
            System.debug('d.id: ' + d.id);
        }
    }
    
    class Response {
        public Integer status;
        public Data[] data;
         
        public Response(Integer status) {
            this.status = status;
            this.data = new List<Data>();
        }        
    }
    
    class Data {
        public String id;
        public String name;
        public String created;
         
        public Data(String id, String name, String created) {
            this.id = id;
            this.name = name;
            this.created = created;
        }        
    }
}

 

My testclass:

 

@isTest 
private class TestOuterClass {
    static testMethod void testOuterClass() {
        //Creating test data...
        
        Test.startTest();
        insert testdata;
        Test.stopTest();
    }
}

 

When listing records of a custom object, I'd also like to list all users that has access to it.

 

Can I access ObjectName__Share somehow and work from there?

The "Submit for approval"-button is, for some reason, displayed for _all_ my custom object in a Partner Developer Edition org.

 

Clicking it where it's not due causes this message to pop up:

 

Unable to Submit for Approval
This record does not meet the entry criteria or initial submitters of any active approval processes. Please contact your administrator for assistance.

 

The only approval process I have is the "Large Invoice Value" one from the Warehouse tutorial app in the Force.com Workbook.

 

Does anyone know why this happens, or how I get rid of it?

 

 

Is it possible to set sharing for a record to a certain user directly when creating a record though PHP?

 

With this as reference:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm

 

I tried:

 

        $records = array();
        $records[0] = new SObject();
        $records[0]->fields = array(
            'Name' => $note_name,
            'Note_body__c' => $note_body
        );
        $records[0]->type = 'Note__c';
        $response = $client->create($records);
 
        foreach ($response as $i => $result) {
            $sharingrecords = array();
            $sharingrecords[$i] = new SObject();
            $sharingrecords[$i]->fields = array(
                'ParentId' => $result->id,
                'UserOrGroupId' => $recipient,
                'AccessLevel' => 'Read'
            );
            $sharingrecords[$i]->type = 'Note__Share';
            $sharingresponse = $client->create($sharingrecords);
        }

 

And got the error:

 

Post failed: SoapFault exception: [sf:INVALID_TYPE] INVALID_TYPE: sObject type 'Note__Share' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name.

 

(Note is a custom object, $note_name and $note_body are texts, $recipient is a user id).

 

 

Yesterday (July 25 2012) I started going through the Integration Workbook. Today I find it's quite different, despite the fact that it says it was last updated July 20.

 

I kinda liked the downloadable Java example in Tutorial #1, with the AddMerchandise class. This section is now substituted with Heroku. Did I stumble over an old version? Can I find it again somewhere?

I am having an issue with custom objects being visible to users who need to see them.  Here's my example:

 

I have a custom object Widget__c.

I have a page Widgets that displays a list of Widget__c objects.

I have an admin page that sllows system admins to create Widget__c objects through a custom wizard.

 

Desired behavior:

When a system administrator creates a Widget__C object it appears on the Widgets page in the list.

When a non-system administrator visits the Widgets page, they should see all Widget__c objects listed.

 

Actual  behavior:

When a system administrator creates a Widget__C object it appears on the Widgets page in the list.

When a non-system administrator visits the Widgets page, they cannot see any objects listed.

 

When I look into sharing issues I am reading that custom objects should have a Widget__Share object associated with them and I can create these shares to allow other users access to objects created.  When I attempt this in practice, however I don't have any Widget__Share objects.  I also do not see them in the schema browser in the Eclipse IDE.

 

I tried making the list page controller use "without sharing" which didn't change the outcome.

 

What can I do to have object created by a system administrator be viewable by other users of the app?

 

This is all being done in Developer Edition.