• Ram Chaturvedi
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 65
    Questions
  • 36
    Replies
HttpRequest  req1=new HttpRequest();
    req1.setMethod('POST');
   req1.setEndpoint('https://ap1.salesforce.com/services/apexrest/MyPackageAC/ServerRestApi/0019000001N7LjKAAV?_HttpMethod=DELETE');  
    req1.setHeader('Authorization','OAuth '+access_token);
             
    HttpResponse res=p1.send(req1);
    system.debug(res);
    result=res.getBody();
=============================================================================
@RestResource(urlMapping='/ServerRestApi/*')
global class ServerResource
{

@HttpDelete
  global static void doDelete() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        String accountId=req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Account account = [SELECT Id FROM Account WHERE Id = :accountId];
        delete account;
  }

}

what could be reason for this error "POST requires content-length error".
 
Uesr "A" creates a account record and attach a doc in this record. now user "B" wants to delete those attachment created by user "A", so what permission need to give User "B" in her/his profile or permission set.............?
I am start working on Rest API. Actually  i am going to create a account record for different salesforce account, in current account i am writting code for that.....  

How can i code for this :  
curlhttps://na1.salesforce.com/services/data/v20.0/sobjects/Account/-H"Authorization:Bearer token -H "Content-Type: application/json" -d @newaccount.json"        (Suggested in salesforce document)


account ac = new account();
ac.name = 'Temp' ;           
String accountJSON = JSON.serializePretty(ac);

HttpRequest request =new HttpRequest();                                                     
request.setEndpoint('https://na1.salesforce.com/services/data/v32.0/sobjects/Account');
request.setMethod('POST'); 
request.setHeader('Authorization','OAuth '+AccessToken );
request.setContentType('application/json');
Http htp = new Http();
HTTPResponse res = htp.send(request);
Response =  res.getBody(); 


How to add accountJson in this request..... Please reply if you have ....
 
I am trying to change a user profile in production but it showing error "Cannot grant or remove a profile with modify all data, without having the modify all data permission yourself." i am not getting why this error occur. Please suggest solution, Thanks in Advance.

User-added image 
I have cretaed one outbound change set it contain one trigger with 98% code coverage , but when i am uploading this change set in my production it shown fatal error at the validating time, trigger xxx having 0% code coverage . 

One more thing :- it also showing one another trigger code coverage error wihch trigger i have already deleted from my sandbox .

How can i overcome from these issue... ?
User-added image

I am sending Mail to particular contact but getting no mail on mai id .
User-added image

Deployment Connections Option is Not Showing in my Account , what are the steps for that which i have to follow for this option .
trigger FireMail on Lead__c (after insert,after update) {

    list<lead__c> leads = new list<lead__c>();
    string mailcontent ;
    leads = trigger.new ;
    
    for(lead__c ld : leads){
    
        string nm = ld.name ;
        string EmailId = ld.Email_Id__c ;
        
        if(EmailId != null){
            
               mailcontent ='Thanks For contacting Us ' ;           
                                                                                                        // here error is Occur
               Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
               string [] toaddress= New string[]{EmailId};
               email.setSubject('Thanks for Contacting .');
               email.setPlainTextBody(mailcontent);
               email.setToAddresses(toaddress);
               Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
        
        } 
    }
}
I am fetching a picture from an object and want to store in a apex variable , in which data type we can store that image and how ?
HttpRequest request =new HttpRequest(); 
             request.setEndpoint('https://login.salesforce.com/services/oauth2/token');
             request.setMethod('POST');            
             request.setBody('grant_type=refresh_token&client_id='+Cid+'&client_secret='+ScrId+'&refresh_token='+OldAccessToken+'');

             Http htp = new Http();
             HTTPResponse res = htp.send(request);
      NewAccessToken =  res.getBody();  

responce:        {"error_description":"expired access/refresh token","error":"invalid_grant"}
i am getting responce like this-----------
https://c.ap1.visual.force.com/apex/Rest2Auth
#access_token=xxxxxxxxxxxxxxxxxxxxxlzBLQ9.DSngQqkgP.tr9EmGDYeYNobq2qZ1oxxxxxxxxxxxxxxxxxxxxxxx91lLR5iilZ9J9_8G9jD_j
&instance_url=https%3A%2F%2Fap1.salesforce.com

how can i fetch access token from it .
I am trying to request one salesforce account by another .but after authorization i am not getting any code . Can anybody help me ?

request.setBody('response_type=code&client_id=3MVG9Y6d_Btp4xp7CF6KDJgV3ZvvwY_ISYLO7QsBqp9Wc0.u_AYgBO.If4xxxxxxxxxxxxxxxxxxxx4EBsjLo&redirect_uri=https://c.ap1.visual.force.com/apex/customRedirectedurl&state=mystate');

after this 

result=ApexPages.currentPage().getParameters().get('code');

it its null ; Why ?

 

@isTest
public class govenerLimit {
    public static testMethod void main(){        
        for(integer i =0 ; i<101 ; i++){           
            test.startTest();
            list<student__c> sts = [select name from student__c];
            test.stopTest();          
        } 
    }
}   
//----------- above code execute Successfully .

@isTest
public class govenerLimit
    public static testMethod void main(){
        for(integer i =0 ; i<101 ; i++){           
            test.startTest();
            list<student__c> sts = [select name from student__c];
            test.stopTest();          
        }
            test.startTest();
            list<faculty__c> facs = [select name from faculty__c];
            test.stopTest();
    }
} // -------- But this code gives msg-------- "Testing Already Started" ---------  why ?



User-added image
i want to remove this button from opp tab layout and want to add some custom button, as we can do in list view .
String JobName = 'job8'+recId;
           
           
           
            CronTrigger cjd = [SELECT Id FROM CronTrigger where CronJobDetail.Name=:jobname];
            if(cjd!=null){
           
                delete cjd;
           
            }

how can we delete schedule job ?
I have a vf page have a custom list view now in custom controller class i want to access those records which are selected on vf page.
Uesr "A" creates a account record and attach a doc in this record. now user "B" wants to delete those attachment created by user "A", so what permission need to give User "B" in her/his profile or permission set.............?
I am start working on Rest API. Actually  i am going to create a account record for different salesforce account, in current account i am writting code for that.....  

How can i code for this :  
curlhttps://na1.salesforce.com/services/data/v20.0/sobjects/Account/-H"Authorization:Bearer token -H "Content-Type: application/json" -d @newaccount.json"        (Suggested in salesforce document)


account ac = new account();
ac.name = 'Temp' ;           
String accountJSON = JSON.serializePretty(ac);

HttpRequest request =new HttpRequest();                                                     
request.setEndpoint('https://na1.salesforce.com/services/data/v32.0/sobjects/Account');
request.setMethod('POST'); 
request.setHeader('Authorization','OAuth '+AccessToken );
request.setContentType('application/json');
Http htp = new Http();
HTTPResponse res = htp.send(request);
Response =  res.getBody(); 


How to add accountJson in this request..... Please reply if you have ....
 
User-added image

I am sending Mail to particular contact but getting no mail on mai id .
User-added image

Deployment Connections Option is Not Showing in my Account , what are the steps for that which i have to follow for this option .
trigger FireMail on Lead__c (after insert,after update) {

    list<lead__c> leads = new list<lead__c>();
    string mailcontent ;
    leads = trigger.new ;
    
    for(lead__c ld : leads){
    
        string nm = ld.name ;
        string EmailId = ld.Email_Id__c ;
        
        if(EmailId != null){
            
               mailcontent ='Thanks For contacting Us ' ;           
                                                                                                        // here error is Occur
               Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
               string [] toaddress= New string[]{EmailId};
               email.setSubject('Thanks for Contacting .');
               email.setPlainTextBody(mailcontent);
               email.setToAddresses(toaddress);
               Messaging.sendEmail(New Messaging.SingleEmailMessage[]{email});
        
        } 
    }
}
I am fetching a picture from an object and want to store in a apex variable , in which data type we can store that image and how ?

@isTest
public class govenerLimit {
    public static testMethod void main(){        
        for(integer i =0 ; i<101 ; i++){           
            test.startTest();
            list<student__c> sts = [select name from student__c];
            test.stopTest();          
        } 
    }
}   
//----------- above code execute Successfully .

@isTest
public class govenerLimit
    public static testMethod void main(){
        for(integer i =0 ; i<101 ; i++){           
            test.startTest();
            list<student__c> sts = [select name from student__c];
            test.stopTest();          
        }
            test.startTest();
            list<faculty__c> facs = [select name from faculty__c];
            test.stopTest();
    }
} // -------- But this code gives msg-------- "Testing Already Started" ---------  why ?

i am getting some error when i am trying to call rest  api of x2 engine .
07:32:01:949 USER_DEBUG [24]|DEBUG|{"httpHeaders":{"Content-Type":"application\/json; charset=utf-8"},"reqHeaders":{"Authorization":"Basic xxxxxxxxxxxxxx","SFDC_STACK_DEPTH":"1","User-Agent":"SFDC-Callout\/31.0","Pragma":"no-cache","Host":"trial.x2engine.com","Accept":"text\/html, image\/gif, image\/jpeg, *; q=.2, *\/*; q=.2","Via":"1.1 proxy-chi.net.salesforce.com (squid)","X-Forwarded-For":"10.238.12.23","Cache-Control":"no-cache","Connection":"keep-alive"},"message":"You do not have permission to perform this action..","error":true,"status":403}
I want to call x2 engine rest api  from salesforce , how can i do because i am new to integration so from where i have to start .

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}

var r = confirm(" Are you sure to call the apex class ?");
if(r == true)
{

sforce.apex.execute("javasclass","check",{str:'Amit'});
alert("Sent it for class");
}

---------------------------------------------------
global class javasclass {

    webservice static void check(string x){
       
        system.debug('this is x '+x);
    }
}

-----------------------------------------------
It gives a error :

  User-added image
String Url='/apex/taskTypeDetail?id='+task.id;       // i want to pass one more additional value
            system.debug(Url);
            PageReference newpage=new PageReference(Url);
            newpage.setRedirect(true);
  return newpage;
List<sObject> objs ;
objs = Database.query('select name from Account');


                for(sObject sobj : objs){

                          system.debug(sobj['name']);           // this gives error Expression must be a list type: SObject

                }
//class code :

string para = System.currentPageReference().getParameters().get('objName');
          
          String soql = 'select id, name from ' + para + ' limit 15 ' ;
          system.debug(soql);
           objs = Database.query(soql);
========================================
Visualforce page :
<apex:pageBlockTable var="st" value="{!objs}">
         
              <apex:column headervalue=" Name" >
                 
                          <apex:outputText value="{!st.name}"/>
                
              </apex:column>
         
  </apex:pageBlockTable>

This gives error : Unknown property 'SObject.name'