• Abhishek Vishwakarma 5
  • NEWBIE
  • 60 Points
  • Member since 2015
  • Developer
  • Trekbin Technology

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 17
    Replies
hi developers.
i am trying to write a test class of :
public class VerifyDate {
//method to handle potential checks against two dates
public static Date CheckDates(Date date1, Date date2) {
//if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month
if(DateWithin30Days(date1,date2)) {
return date2;
} else {
return SetEndOfMonthDate(date1);
}
}
can anyone suggest me to how to write.
Hi Folks,

I have a scenario where I need to update near by 200 records. I tried using the PATCH (PATCH /vXX.X/composite/sobjects) but it gave me error "Cannot specify in an insert call [id]". I was unable to get the resonse when I was passing JSON value.
My Code::

 Http h1 = new Http();
                HttpRequest req1 = new HttpRequest();
                req1.setHeader('Authorization','Bearer '+accessToken);
                req1.setHeader('Content-Type','application/json');
                req1.setHeader('accept','application/json');
                
                req1.setMethod('POST');
                //req1.setHeader('X-HTTP-Method-Override','PATCH');
                string Reqstr = URLXXXXX+'/services/data/v43.0/composite/sobjects';
                System.debug('----Reqstr--'+Reqstr);
                req1.setEndpoint(Reqstr);

String JsonTree ='{"allOrNone" : false,  "records" : [{ "attributes" : {"type" : "Account"}, "id" : "0012900000Nq1ewAAB", "Phone" :27000}]}';

I also checked with this example : https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobjects_collections_update.htm 

Please let me know if someone has faced this issue. Thanks!!
Hi Folks,

I have a scenario where I need to update near by 200 records. I tried using the PATCH (PATCH /vXX.X/composite/sobjects) but it gave me error "Cannot specify in an insert call [id]". I was unable to get the resonse when I was passing JSON value.
My Code::

 Http h1 = new Http();
                HttpRequest req1 = new HttpRequest();
                req1.setHeader('Authorization','Bearer '+accessToken);
                req1.setHeader('Content-Type','application/json');
                req1.setHeader('accept','application/json');
                
                req1.setMethod('POST');
                //req1.setHeader('X-HTTP-Method-Override','PATCH');
                string Reqstr = URLXXXXX+'/services/data/v43.0/composite/sobjects';
                System.debug('----Reqstr--'+Reqstr);
                req1.setEndpoint(Reqstr);

String JsonTree ='{"allOrNone" : false,  "records" : [{ "attributes" : {"type" : "Account"}, "id" : "0012900000Nq1ewAAB", "Phone" :27000}]}';

I also checked with this example : https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobjects_collections_update.htm 

Please let me know if someone has faced this issue. Thanks!!
Hi ,
I need locale format for apex:outputText.
 

Hi everyone,

I have a question if you could help me it would be awesome.
I have a number custom field in Account field__c, and with a trigger I want all the opportunities' ammount related to the Account get added to this field and be cumulated each time an opp is added to the account.

How can I do it with a trigger please, any idea?

Thanks in advance.

Hi,

We are integrating salesforce with external website which runs on PHP Script.
The developer at the external end will push the data into salesforce and he uses sesssion ID for this scenario.

My question is that how do use that data in salesforce,  will i be able to use it directly or do i need to write a rest webservice.
How do i proceed...!

Any Help will be appriciated..!
  • March 31, 2016
  • Like
  • 1
Hi ,
I am creating a login page in visualforce page .Can any one please suggest some code??
@RestResource(urlMapping='/myrest2/*')
global with sharing class Rest_Class2
{
   @HTTPGet
   global static Account[] doGet()
   {
      RestRequest req = RestContext.request;

      RestResponse res = RestContext.response;
      
      String currentIndustry=req.requestURI.substring(req.requestURI.lastIndexof('/')+1);
      
      Account[] acts=new Account[]{};
      
      if (currentIndustry=='all')
      
         acts=[select Name,Industry from account where Industry=:currentIndustry];
      
      else
      
          acts=[select Name from account where Industry=:currentIndustry];
         
      return acts;
   } 
   
}
Hi friends

I have written a rest resource where I want to display all account where Industry='Energy'. when I test this is work bench it is showing error as 
Service not found at: /services/apexrest/industry/enerygy

If it do as       /services/apexrest/industry/all    then it will show all accounts
But either way its not showing records.
Pls guide me.

divya
 
public class RelatedContactList
{
      private string accountID = '';
      public list<cContact> contactList{get;set;}
      public Boolean selectAll {get; set;}
      
      public RelatedContactList(ApexPages.StandardController stdController)
      {
            selectAll= false;
      }
        
      public void showContactList()
      {
            accountID = System.CurrentPageReference().getParameters().get('id');
            contactList = new List<cContact>();
            
            for(Contact c: [select Id,account.Id,Name, lastname,Email, Phone from Contact where account.id=:accountID])
            {
                 contactList.add(new cContact(c,false));
            }
           
      }
    
      public void erase()
      {
            List<Contact> selectedContacts = new List<Contact>();
            List<Contact> selectAllContacts = new List<Contact>();
            
            for(cContact cCon: contactList)
            {
                  if(cCon.selected == true)
                  {
                      
                        selectedContacts.add(cCon.con);
                  }
            }
            delete SelectedContacts;
            
            for(cContact cCon: contactList)
            {
                  if(SelectAll==true)
                  {
                        selectAllContacts.add(cCon.con);
                  }
             
             }
             
             delete SelectAllContacts;
            
             showcontactList();
            
      }
      
      public void Edit(){}
          
      public void Save()
      {
             List<Contact> selectedContacts = new List<Contact>();
             for(cContact cCon: contactList)
             {
                  if(cCon.selected == true)
                  {
                      
                        selectedContacts.add(cCon.con);
                  }
                 
             }
           
             upsert SelectedContacts;
             
             showcontactList();
      }
      public void AddNewContact()
      {
             contact c = new contact();
             c.accountid = System.CurrentPageReference().getParameters().get('id');
             contactList.add(new cContact(c,true));
         
      }
      
      public List<Contact> selectedContacts {get;set;}
      
      public PageReference exportToExcel()
      {
            selectedContacts = new List<Contact>();
            for(cContact cCon: contactList)
            {
                 if(cCon.selected == true)
                 {    
                      
                      selectedContacts.add(cCon.con);
                       
                 }
                
            }
            PageReference pageReference = new PageReference('/apex/excelExportPage');
            pageReference.setRedirect(false);
            return pageReference;
            
      }
      public PageReference exportToPDF()
      {
            selectedContacts = new List<Contact>();
            for(cContact cCon: contactList)
            {
                 if(cCon.selected == true)
                 {    
                      
                      selectedContacts.add(cCon.con);
                       
                 }
                
            }
            PageReference pageReference = new PageReference('/apex/pdfExportPage');
            pageReference.setRedirect(false);
            return pageReference;
            
      }
    
      public class cContact
      {
            
            public Contact con {get; set;}
            public Boolean selected {get; set;}
            
    
            public cContact(Contact c, boolean val)
            {
                  con = c;
                  selected = val;
            }
            
      }
    
}
Hello, 
I've created a custom controller like below 
public class newTaskForTypeController {
    public TaskForTypes__c typeOfTask;
    public string SelectedTaskId { get; set; }
    public TaskForTypes__c getTaskTypes(){
        if(typeOfTask == null) return new TaskForTypes__c();
        return typeOfTask;
    }
    
    //First page which will contain name 
    public PageReference step1(){
        return Page.Tasks_For_Types1;
    }
    
    //Second page which will contain Sub type name and 
    public PageReference step2(){
        return Page.Tasks_For_Types2;
    } 
    
    //Cancel the operation
    public PageReference cancel(){
        //Navigate to first page
        PageReference tft1 = new ApexPages.StandardController(typeOfTask).view();
        tft1.setRedirect(true);
        return tft1;
    }
    
    //Save method
    public PageReference save(){
        if(typeOfTask == null) typeOfTask = new TaskForTypes__c();
        insert typeOfTask;
        PageReference tft1 = new ApexPages.StandardController(typeOfTask).view();
        tft1.setRedirect(true);
        return null;
    }
    
    //Get cuurent tasks
    public List<TaskForTypes__c> getTypeTasks(){
        List<TaskForTypes__c> tsks = [SELECT Subject__c, Task_Description__c FROM TaskForTypes__c WHERE Sub_Type_Name__c =: typeOfTask.Sub_Type_Name__c];
        return tsks;
    }
    
    //Delete Task from List
    public void DeleteTask()
    {
        // if for any reason we are missing the reference 
        if (SelectedTaskId == null) {
            
            return;
        }
        
        // find the account record within the collection
        TaskForTypes__c tobeDeleted = null;
        for(TaskForTypes__c a : getTypeTasks())
            if (a.Id == SelectedTaskId) {
                tobeDeleted = a;
                break;
            }
        
        //if account record found delete it
        if (tobeDeleted != null) {
            Delete tobeDeleted;
        }
        
        //refresh the data
        getTypeTasks();
    }  
    
    public List<TaskForTypes__c> getUniqueTypes(){
        List<TaskForTypes__c> types = [SELECT Sub_Type_Name__c FROM TaskForTypes__c];
        return types; 
    }
}

and my VF page code is 
<apex:page controller="newTaskForTypeController" tabStyle="TaskForTypes__c" >
    <script>
    function confirmCancel() {
        var isCancel = confirm("Are you sure you wish to cancel?");
        if (isCancel) return true; 
        return false;
    } 
    </script>
    <apex:sectionHeader title="Add New Task Assignment For Types Rule"/>
    <apex:form >
        <apex:pageBlock title="Rule Name" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save & Next" />
                <apex:commandButton action="{!cancel}" value="Cancel" onclick="return confirmCancel()" immediate="true" />
            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                   <apex:inputField id="subtype" value="{!typeOfTask.Sub_Type_Name__c}" required="true" />
                
            </apex:pageBlockSection>
         
        </apex:pageBlock>
    </apex:form>  
</apex:page>

I got an error "Unknown property 'newTaskForTypeController.typeOfTask'".

any help please 
I have a field AccountLookup that must be a hyperlink and it should be in font colour and bolding.can any one suggest how to acheive this.
hi developers.
i am trying to write a test class of :
public class VerifyDate {
//method to handle potential checks against two dates
public static Date CheckDates(Date date1, Date date2) {
//if date2 is within the next 30 days of date1, use date2. Otherwise use the end of the month
if(DateWithin30Days(date1,date2)) {
return date2;
} else {
return SetEndOfMonthDate(date1);
}
}
can anyone suggest me to how to write.
in my Scenario, i have picklist field called status, in that picklist field i have multiple values. when i select the picklist field status='approved' and click on the save button then my trigger will run.
here is my trigger:
 for (genesis__Applications__c app1: Trigger.new)
         {     
           
               
              if(app1.genesis__Status__c == 'Approved')
              {
                  
                    application.getDetails(app1.Id);
              }
        }

my requirement is like: this trigger i need to call one time when the trigger is new, suppose if select the status=approved two times and clicking save button, i am getting the result two times with same values.for second time calling the trigger i want to check the trigger whether it is old or new. if it is new , then my class method i need to cal.if it is old then that method no need to cal. can any help me out from this scenario