• Tushar RK
  • NEWBIE
  • 30 Points
  • Member since 2013

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

Hi,

 

I have two different developer orgs. One contains apex REST web service, and I want to call that REST service from my second org. I have tried to call that REST service using normal ajax post request and forcetk.js, But I got following error

 

XMLHttpRequest cannot load https://ap1.salesforce.com/services/apexrest/CustomSettings. Origin https://c.ap1.visual.force.com is not allowed by Access-Control-Allow-Origin.

 

I searched about this problem then I got to know that Salesforce never allows CORS (Cross-Origin-Resource-Sharing).

 

Initially I was using apex to call that REST web service, that time I was able to post data from apex. But as we have callout limitation in salesforce, I want to use javascript.

 

Please help me.

 

Thanks.

 

There is a requirement to share Contacts. We have Contacts which are not directly linked to Account however linked through Junction Object.
Now If I want to share any Contact, then Contact is not visible to Users as they are Private (not linked to Account).

So I have changes OWD for Contact as "Private" and wrote Apex share code as below, It gets invoked through Custom Button on Contact Detail Page.
 
global class ContactShareController
{  
   webservice static string shareContact(string conId)
   {
       ContactShare con = new ContactShare();
       con.ContactId = conId;
       con.ContactAccessLevel = 'Edit';
       con.RowCause = 'Manual';
       con.UserOrGroupId = '00528000000kIX8';
       
       Database.SaveResult sr = Database.insert(con,false);
       string strMsg = '';
        
       if(!sr.isSuccess())
       {
            Database.Error err = sr.getErrors()[0];     
            strMsg = 'Unable to grant sharing access due to following exception: ' + err.getMessage();               
       }
       else
       {
            strMsg = 'Shared with ' + con.id;
       }    
 
       return strMsg;
   }
}

Code is working perfectly fine and I am able to see User gets added to "User and Group Sharing" section however when User logs in then he still gets "Insufficient Access" error for that contact.

Is there issue with Contact which not directly linked to Account? I am not sure where is it getting wrong.

Please let me know in case you have gone through such issue.

Hi,

 

I have two different developer orgs. One contains apex REST web service, and I want to call that REST service from my second org. I have tried to call that REST service using normal ajax post request and forcetk.js, But I got following error

 

XMLHttpRequest cannot load https://ap1.salesforce.com/services/apexrest/CustomSettings. Origin https://c.ap1.visual.force.com is not allowed by Access-Control-Allow-Origin.

 

I searched about this problem then I got to know that Salesforce never allows CORS (Cross-Origin-Resource-Sharing).

 

Initially I was using apex to call that REST web service, that time I was able to post data from apex. But as we have callout limitation in salesforce, I want to use javascript.

 

Please help me.

 

Thanks.