• Vidhya
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 5
    Replies

I am trying to find ways to post Chatter private message to user.

 

Since there is no apex code directly to post Chatter private message to user, figured out there is a way in the REST APIs.

(Ref: http://www.salesforce.com/us/developer/docs/chatterapi/salesforce_chatter_rest_api.pdf)

/services/data/v24.0/chatter/users/me/messages?recipients=005D0000001GOYpIAO,
005D0000001GbdHIAS&Are+we+ready+for+next+week's+customer+meeting?

My question is, how do i call this in apex (Rest API's POST call)?

Since we are using internal salesforce rest api within the system, I am not sure if we should we use OAuth.

Can you please tell me how to call SF Rest api's using Apex?

 

  • April 20, 2012
  • Like
  • 0

I downloaded the Enterprise WSDL from SF and consuming it in .Net application.
I am trying to update an Opportunity Name & Amount.
What I have observed is,

When the initial opp Amount value is blank, when .net app is run, only Opp Name gets updated., Amount field is still blank.
When the initial opp Amount value is not blank, when .net app is run, both Opp Name & Amount fields gets updated.

 

I would like to know, why the amount is not getting updated when the old value is blank.
I am not able to find any documentation for the same.
Am I missing anything?

 

Code:

Opportunity opp = (Opportunity)queryResults.records[0];

Console.WriteLine("Name: " + opp.Name + " - Stage :" + opp.StageName + " - Amount : " + opp.Amount);

opp.Name = "Oppty_Name_Test13";          // old value - "OppTest13"  -> gets changed to new value when run
opp.Amount = 12345.00;                          // old value blank -> no change, still shows blank after run

SaveResult[] saveResults = binding.update(new sObject[] { opp });

 

  • February 21, 2012
  • Like
  • 0

I have created a class implementing Schedulable and have created a batch job to run at 9 pm every day. The job is available at Setup-> Monitoring -> Scheduled Jobs. I have added System.Debug statements in my class for traceability purpose in case of any issues. But I am unable to figure a way to get/mail the debug logs for the same. Can you please let me know what Setting should be set in order to get the debug logs for the Scheduled Jobs?

  • February 08, 2012
  • Like
  • 2

Hi,

 

I am writing apex code to create group membership request by some user say ABCD to a private group - TestGrp.

  

My scenario is:


There is a private group(TestGrp) to discuss about an Opportunity - Opp_1.  People who are willing to join the group, post a chatter feed on Opp_1 record with a keyword say: '!JoinMe'. So I am writing a trigger on FeedItem. If any post on Opp_1 record contains text '!JoinMe', I am creating a group membership request with the userid of the person who posted his willingness to join the group.

 

The request should ideally go to the owner of the private group wher he can decide to approve/decline the request.

The owner of the private group will be informed by email as per this link.

http://www.salesforce.com/us/developer/docs/api/index_Left.htm#CSHID=sforce_api_objects_collaborationgroupmemberrequest.htm|StartTopic=Content%2Fsforce_api_objects_collaborationgroupmemberrequest.htm|SkinName=webhelp

 

This is the code below for what I am trying to achieve.

 

CollaborationGroupMemberRequest req = new CollaborationGroupMemberRequest();
req.CollaborationGroupId = grpId;  // Private group Id
req.RequesterId = userId;    // ABCD Id (the one who posted '!JoinMe' in the Opp_1 record chatter)
insert req;

 

But I am getting the following error:
first error:INVALID_CROSS_REFERENCE_KEY, You can only request group membership for yourself.:[RequesterId]:

 

Is there any workaround in requesting the group membership for someone else through apex code?
Please clarify.

  

Kind Regards,

Vidhya

  • October 20, 2011
  • Like
  • 0

I have created a class implementing Schedulable and have created a batch job to run at 9 pm every day. The job is available at Setup-> Monitoring -> Scheduled Jobs. I have added System.Debug statements in my class for traceability purpose in case of any issues. But I am unable to figure a way to get/mail the debug logs for the same. Can you please let me know what Setting should be set in order to get the debug logs for the Scheduled Jobs?

  • February 08, 2012
  • Like
  • 2

I am trying to find ways to post Chatter private message to user.

 

Since there is no apex code directly to post Chatter private message to user, figured out there is a way in the REST APIs.

(Ref: http://www.salesforce.com/us/developer/docs/chatterapi/salesforce_chatter_rest_api.pdf)

/services/data/v24.0/chatter/users/me/messages?recipients=005D0000001GOYpIAO,
005D0000001GbdHIAS&Are+we+ready+for+next+week's+customer+meeting?

My question is, how do i call this in apex (Rest API's POST call)?

Since we are using internal salesforce rest api within the system, I am not sure if we should we use OAuth.

Can you please tell me how to call SF Rest api's using Apex?

 

  • April 20, 2012
  • Like
  • 0

I'm trying to upload photo using chatter rest api, and its working great for test.salesforce.com and login.salesforce.com.

 

I'm able to login using OAUTH, do get in response instance_url, acess_token etc, and I set the instance_url in my photo upload request and its works great only when my instance_url is a nxxx.salesforce.com or c**.salesforce.com (ie it works for valid salesforce production and sandbox instances).

 

However when I try to login against *.cloudforce.com (a salesforce org), login is successful, instance_url returned is xxx.cloudforce.com, but when I use that instance url for photo upload request its says "Destination URL not reset". Is it something to do with this exception type org of *.cloudforce.com ? 

I downloaded the Enterprise WSDL from SF and consuming it in .Net application.
I am trying to update an Opportunity Name & Amount.
What I have observed is,

When the initial opp Amount value is blank, when .net app is run, only Opp Name gets updated., Amount field is still blank.
When the initial opp Amount value is not blank, when .net app is run, both Opp Name & Amount fields gets updated.

 

I would like to know, why the amount is not getting updated when the old value is blank.
I am not able to find any documentation for the same.
Am I missing anything?

 

Code:

Opportunity opp = (Opportunity)queryResults.records[0];

Console.WriteLine("Name: " + opp.Name + " - Stage :" + opp.StageName + " - Amount : " + opp.Amount);

opp.Name = "Oppty_Name_Test13";          // old value - "OppTest13"  -> gets changed to new value when run
opp.Amount = 12345.00;                          // old value blank -> no change, still shows blank after run

SaveResult[] saveResults = binding.update(new sObject[] { opp });

 

  • February 21, 2012
  • Like
  • 0

Hi,

 

I am writing apex code to create group membership request by some user say ABCD to a private group - TestGrp.

  

My scenario is:


There is a private group(TestGrp) to discuss about an Opportunity - Opp_1.  People who are willing to join the group, post a chatter feed on Opp_1 record with a keyword say: '!JoinMe'. So I am writing a trigger on FeedItem. If any post on Opp_1 record contains text '!JoinMe', I am creating a group membership request with the userid of the person who posted his willingness to join the group.

 

The request should ideally go to the owner of the private group wher he can decide to approve/decline the request.

The owner of the private group will be informed by email as per this link.

http://www.salesforce.com/us/developer/docs/api/index_Left.htm#CSHID=sforce_api_objects_collaborationgroupmemberrequest.htm|StartTopic=Content%2Fsforce_api_objects_collaborationgroupmemberrequest.htm|SkinName=webhelp

 

This is the code below for what I am trying to achieve.

 

CollaborationGroupMemberRequest req = new CollaborationGroupMemberRequest();
req.CollaborationGroupId = grpId;  // Private group Id
req.RequesterId = userId;    // ABCD Id (the one who posted '!JoinMe' in the Opp_1 record chatter)
insert req;

 

But I am getting the following error:
first error:INVALID_CROSS_REFERENCE_KEY, You can only request group membership for yourself.:[RequesterId]:

 

Is there any workaround in requesting the group membership for someone else through apex code?
Please clarify.

  

Kind Regards,

Vidhya

  • October 20, 2011
  • Like
  • 0

Hi,

I have a trigger that posts a notification to a Chatter Group when an opportunity is Closed Won.  The trigger works, however it always posts TWO duplicate posts at the exact same time.  Below is my code....thoughts on how to fix this?  Thanks!

 

 trigger AddClosedWontoChatter on Opportunity (after update) {

    list<FeedItem> fplist = new list<FeedItem>();
    String opportunityPrefix = Opportunity.SobjectType.getDescribe().getKeyPrefix();

    for(Opportunity o : trigger.new){
        FeedItem fpost= new FeedItem();

         if(o.StageName == 'Closed Won' )
        {
            fpost.type = 'LinkPost';
            fpost.parentid = '0F930000000CbQL';
            fpost.Body = 'RTB 
Alert! Your teammate just Closed Won the $' + o.Invoice_Closed_Won__c + ' opportunity -- ' + o.Name 
            + '\nReason Won Details: ' + o.Reason_Won_Lost_Additional_Details__c;
            fpost.linkUrl = 'https://na1.salesforce.com/' + o.id;
            fpost.title = o.Name + ' - ' + o.Invoice_Closed_Won__c;
            fplist.add(fpost);
        }
    }

    if(fplist.size()!=0){
      try{
         insert fplist;
      }
       catch(system.exception e){
          system.debug('Error: '+e);
      }
    }