• Mhlangano Khumalo
  • NEWBIE
  • 50 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 15
    Questions
  • 17
    Replies
Hi,
I have a custom action buttion on the Opportunity page layout which lauches a lightning component upon click.
How can I show/hide the button depending on the Opportunity stage field?
I’ve created a class to create a pdf attachment upon inserting of a lead record with fields mapped from the lead.
 
The web to lead form works fine when the form is filled within VF pages. The only problem is it saves a blank pdf page when done through the site page. If enabled Read & Edit permissions on the Lead plus Field Level security on every field but still doesn’t populate the pdf.

What could be the problem? Below is the code
public with sharing class CreatePdfOnLead{
    @Future(callout=true)
    public static void savePdf(Id leadId){

    PageReference pagePdf = new PageReference('/apex/ApplicationPDFonLead?id='+leadId); 
    blob body = pdf.getContentAsPDF();
    string filename = 'File Name';
        
    attachment theFile = new attachment();
    theFile.isPrivate = false;
    theFile.body = body;
    theFile.ParentId = leadId;
    theFile.Name = filename;
    insert theFile;        
    }         
}
Trigger that creates the attachment
trigger MergonCreatePdfOnLeadTrg on Lead (after insert) {
    for(Lead thelead :Trigger.New){        
        //Invoke the method
        CreatePdfOnLead.savePdf(thelead.Id);
        }
}
I strongly suspect it has to do with permissions on the site page because if the record owner/creator is sys admin the pdf is populated.  If the owner is site quest user, it shows a blank page. It does not even show static text on the page that's not mapped to fields, Any Ideas?

 
My Webservice GET's a list of records in JSON format from another system, then updates to those specific records in Salesforce.
My data model: I have a master detail relationship between Account & Advance_Summary__c custom object. RC_Account_No__c is an external ID field that's unique on Account and Balance__c  is a custom currency field on Advance_Summary__c. We only need to update Balance__c,  the catch is if there is more that one Advance_Summary__c records related to an Account, we Only update the most recently created.

Below is the code.
 
/* Json string im getting looks like this.
[
	{
	"IDCUST": "RC-002394", //Mapped to RC_Account_No__c on Account
	"AMTBALDUEH": 1345.89 //Mapped to Balance__c on Advance_Summary__c
	},
	{
	"IDCUST": "RC-002408",
	"AMTBALDUEH": 133.33
	}
]
*/

public class CustomerStatsBatch 
{   
    @future(callout=true) 
    public static void executeThis() {
       
        Http h = new Http();    
        HttpRequest req = new HttpRequest();    
		
		//Calling the endpoint URL
        req.setEndpoint('http://crm.retal.com/SageERPAPI/api/CustomerStats'); 
 
        req.setMethod('GET');
    
        HttpResponse res = h.send(req);
    
        String rNf =res.getbody();
        String jsonString = '{"items": '+res.getbody()+'}'; 
		/* Above I format the JsonString so it looks like below
		{
		"items": [
				{
				"IDCUST": "RC-002394",
				"AMTBALDUEH": 1345.89
				},
				{
				"IDCUST": "RC-002408",
				"AMTBALDUEH": 133.33
				}
			    ]
		}
	     */
		
		//Deserialize it using apex class JSON2ApexCustomerStats
        JSON2ApexCustomerStats objResponseBody = 
					(JSON2ApexCustomerStats)JSON.deserialize(jsonString, JSON2ApexCustomerStats.class);

        List <Account> updateAcc = new List<Account>{};
        integer count = 0;
        
        List<String> rcNums = new List<String>{};
        List<Account> list2bUpdated = new List<Account>{};
        List<Advance_Summary__c> plswork = new List<Advance_Summary__c>{};
        
        //Load RC Numbers you're getting from json string so I can use them as an index
        for(JSON2ApexCustomerStats.items row: objResponseBody.items) {
            rcNums.add(row.IDCUST);
        }  
       
	    //The first query selects an account with aleast 1 child, the most recent if there more than 1
        for(Account rec : [select Id, RC_Account_No__c,
							(select id, Balance__c from Account.Balance__cr order by createddate desc limit 1) 
							from Account where RC_Account_No__c in: rcNums and Id In 
							(Select Advance_Summary__c from Advance_Summary__c) ]){
            for(JSON2ApexCustomerStats.items row: objResponseBody.items) {
            
                if(row.IDCUST == rec.RC_Account_No__c){
                    Account l = new Account();
                    l.id = rec.id;                   
                    list2bUpdated.add(l);
                    
                    Advance_Summary__c advSum = new Advance_Summary__c();
                    
                    //error in the line below if null;                         
                    advSum.id= rec.Advance_summary__r[0].id;
                    
                    advSum.Balance__c = row.AMTBALDUEH;
                    plswork.add(advSum);
                }
            }            
        }

        Database.update(list2bUpdated,false); 
        
        Database.update(plswork,false); 
        
        system.debug('list2bUpdated:'+ list2bUpdated);        
        system.debug('plswork:'+ plswork);
       
      }    
}
Your assistance will be appreciated and indicated as the best answer.
My requirement is to display radiobutton fields in a VF page like below. which i've managed to do using bootstrap template to achieve this but when I put VF tags on the  radio button the look & feel changes.
User-added image
After selecting option
User-added image
<apex:page standardController="Opportunity" standardStylesheets="false" docType="html-5.0" showHeader="false">
...(static resources, html header, <apex:form>...etc goes in here)
<label for="year" class="control-label input-group">8. Can ROI be efficiently estimated?</label>

<div class="btn-group" data-toggle="buttons">
	<label class="btn btn-default"><input name="year" value="2011" type="radio"/>Yes</label>
	<label class="btn btn-default"><input name="year" value="2012" type="radio"/>Potentially</label>
	<label class="btn btn-default"><input name="year" value="2013" class="active" type="radio"/>No</label>
</div>
....
</apex:page>

I want to keep the radio button field like above but link it to the standard controller using JavaScript/Jquery so the styling isn't compromised.

I've tried using apex tags.
<apex:selectRadio styleClass="btn btn-default" value="{!Opportunity.ROI__c}"  >
  <apex:selectOption itemLabel="Yes"  html-class="" itemValue="Yes"></apex:selectOption>
  <apex:selectOption itemLabel="Potentially" itemValue="Potentially"></apex:selectOption>
  <apex:selectOption itemLabel="No" itemValue="No"></apex:selectOption>
</apex:selectRadio>
The Output.
User-added image
after selection
User-added image
If anyone has a better solution/approach. Please suggest.
I want pull only the list of records that match the ones i'm getting through a JSON array list. The json array list string doesn't have the Salesforce record ID.The JSON string looks like below. I use the rcNumber, accountNumber and bankName  as a composite primary key and what's returned on unpaidCode as a condition for updating records.
{
    "bacctList": [{
        "rcNumber": "RC-2848323",
        "accountNumber": "12324434",
        "bankName" :  "NEDBANK",
        "unpaidCode" : ""
    },
    {
        "rcNumber": "RC-002274",
        "accountNumber": "1111111",
        "bankName" :  "FNB",
        "unpaidCode" : "99"
    }]
}
The Logic of the class works perfectly, I just want to bulkify it. Please help!...the fist for loop (line 27) with an inner loop, I think is not best practice.
 
@RestResource(urlMapping='/dosystem/bankaccounts2/*')
global with sharing class BankAccountWebservice2 {
       
    //Decorator class- Retured JSON mapping
    global class BankAccountsReturned{
        public String rcNumber;             
        public String accountNumber;  
        public String bankName;
        public String unpaidCode;
        
        public BankAccountsReturned(String rcNum, String accNum, String bName, String uCode){
            this.rcNumber = rcNum;
            this.accountNumber = accNum;
            this.bankName = bName;
            this.unpaidCode =uCode;
        }          
    } 
    
    @HttpPatch
    global static List<Bank_Account__c > updateDateProcessed(BankAccountsReturned [] bacctList) {
        
        //St
        List<String> rcNumbers = new List<String>{};  
           
        List<Bank_Account__c> BAccList  = new List<Bank_Account__c>{};
        
        for (integer i=0; i< bacctList.size(); i++) {                                                         
             for(Bank_Account__c j : [select id, Account__r.Name, Account__r.RC_Account_No__c,Bank__c,RC_Account_No__c,Unpaid_Code__c  
                                                         FROM Bank_Account__c where 
                                                         RC_Account_No__c =: bacctList[i].rcNumber AND 
                                                         A_c_Number__c =: bacctList[i].accountNumber AND 
                                                         Bank__c =: bacctList[i].bankName ]){

              // If unpaidCode is blank then deactive bank account, DO NOT create case 
              if(bacctList[i].unpaidCode == ''){                      
                  BAccList.add(new Bank_Account__c(Id = j.Id, Debit_Order_A_c__c = false, Unpaid_Code__c = bacctList[i].unpaidCode));
              }
              /* If the error code is populated with 99 the DO NOT deactivate the bank account BUT
               create an active ADHOC record with the current Debit Order amount on the bank account. DO NOT Create Case */
              else if(bacctList[i].unpaidCode == '99'){
                  rcNumbers.add(j.Account__r.RC_Account_No__c);
                  BAccList.add(new Bank_Account__c(Id = j.Id, Debit_Order_A_c__c = true, Unpaid_Code__c = bacctList[i].unpaidCode));                  
              }
              //If unpaid code is any other number beside 99, deactivate and create a case
              else{
                 
                  rcNumbers.add(j.Account__r.RC_Account_No__c); //<--Populates the list with ONLY RC Numbers we need to create cases for
                  BAccList.add(new Bank_Account__c(Id = j.Id, Debit_Order_A_c__c = false, Unpaid_Code__c = bacctList[i].unpaidCode));
              
              }
            }                                  
        }  
        
        update  BAccList;
        
        //Create Adhoc records
        List<Ad_hoc_Debit_Orders__c> adhocRecords = new List<Ad_hoc_Debit_Orders__c>();
        for(Bank_Account__c createActiveDO : [select id, Bank__c,Unpaid_Code__c,
                                            (select Id,Current_DO__c from Bank_Account__c.Debit_Orders__r where Active__c = true Order by CreatedDate Desc LIMIT 1)
                                              from Bank_Account__c where id in: BAccList and Unpaid_Code__c= '99']){
                                              
            Ad_hoc_Debit_Orders__c ad = new Ad_hoc_Debit_Orders__c(); 
            ad.Bank_ID__c = createActiveDO.id;
            ad.Custom__c = 'Adhoc';
            ad.Debit_Order_amount__c = createActiveDO.Debit_Orders__r[0].Current_DO__c;
            ad.Active__c = true;   
            adhocRecords.add(ad);     
        }
        insert adhocRecords;
        
        
        //Get more details about the deactivated bank account inoder to be populated when creating case.
        List<Case> createCase = new List<Case>();
        for(Account oUsr: [SELECT Id, Name, RC_Account_No__c,
                                    (select Id, Name, email, phone from contacts where Primary_contact_Indicator__c = true order by createddate desc Limit 1),
                                    (select Id, Name, Bank__c from Account.Bank_Accounts__r where Debit_Order_A_c__c = true Order by CreatedDate Desc LIMIT 1 )
                                     FROM Account WHERE RC_Account_No__c in: rcNumbers ]){
            Case u = new Case();            
            u.AccountId = oUsr.id;
            u.ContactId = oUsr.Contacts[0].Id;        
            u.Status = 'New';
            u.Origin = 'API Call';
            u.Subject = 'Deactivated Bank Account';
            u.Description = 'Bank Account Deactivated for '+oUsr.Name +' Account with  '+oUsr.RC_Account_No__c+' Number';             
            createCase.add(u);
        }
        insert createCase;
       
       return BAccList;
       }         
    }
I would like to use best practice. Because the json array string doesn't have the salesforce record Id, I want to select only the records is salesforce that = my composite primary key. and store them on a list as it will have the Record ID which will make it easier to do processing & updates.
I would like to use this bootstrap template http://mariusn.com/themes/reales-wp/ to create a responsive force.com website that will interact with data stored in Salesforce. All information displayed on the website will be coming from records created in Salesforce. The website will be used on Mobile devices as well as desktop.

How should I go about doing this? I know how to use a bootstrap template in Visualforce thanks to (http://www.oyecode.com/2013/11/how-to-use-bootstrap-3-with.html) but doing CRUD operations is a challenge for me. I can only do READ at most. Should I use APEX? JavaScript? Remote Object?

What is the best approach, how should I do it & if there are any examples of code (CRUD operations on a responsive website with many pages) /resources, please help.

 
Bank_Account__c is the Parent object, Debit_Order__c and Ad_hoc_Debit_Orders__c are child objects. I want my query to only select Bank_Account__c records with Debit_Order_A_c__c = true AND with at least 1 record in in both child objects where the field Active__c = true;
List<Bank_Account__c> result = [SELECT RC_Account_No__c,  Bank_Account__c.Account__r.Name, Bank__c, Bank_code__c, Bank_A_C_Type__c, A_c_Number__c,
                (SELECT Name, Current_DO__c FROM Bank_Account__c.Debit_Orders__r where Active__c = true AND Date_Processed__c < TODAY),
                (SELECT Name, Debit_Order_amount__c FROM Bank_Account__c.Ad_hoc_Debit_Orders__r where Active__c =true)                 
        FROM Bank_Account__c WHERE Debit_Order_A_c__c = true  AND...????];

 
I'm receiving a JSON string from another system in the format below. These records already exist in Salesforce. I want to only query these records in salesforce, set a boolean field to false in all of them and update.
{ "bacctList" : 
     [{
       "RC_Account_No__c" : "RC-2",
       "A_c_Number__c" : "111",
       "Bank_code__c" : "250655"
      },
      {
       "RC_Account_No__c" : "RC-1",
       "A_c_Number__c" : "222",
       "Bank_code__c" : "198765"
      }]
   }

The below code works fine, the issue is it's not bulkified.
@RestResource(urlMapping='/dosystem/bankaccounts/*')
global with sharing class BankAccountWebservice{
   
 @HttpPatch
    global static BankAccountWrapper doPatch(List<Bank_Account__c> bacctList) {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        BankAccountWrapper response = new BankAccountWrapper();
        
        List<Bank_Account__c> bankAccountsToUpdate= new List<Bank_Account__c>();

        for(integer i=0; i<bacctList.size(); i++){
            List<Bank_Account__c> ac = [SELECT Debit_Order_A_c__c,A_c_Number__c,Bank_code__c,RC_Account_No__c  
            FROM Bank_Account__c 
            WHERE (RC_Account_No__c =: bacctList[i].RC_Account_No__c AND  A_c_Number__c =: bacctList[i].A_c_Number__c AND Bank_code__c =: bacctList[i].Bank_code__c)];
            
            for(integer j=0; j< ac.size(); j++){
                ac[j].Debit_Order_A_c__c = false;       
                bankAccountsToUpdate.add(ac[j]);
             }    
        }
        
        try {
            update bankAccountsToUpdate;

            response.bacctList = bankAccountsToUpdate;
            response.status = 'Success';
            response.message = bacctList.size()+' Records Updated successfully';
        }
        catch(Exception exc) {
            res.StatusCode = 500;
            response.bacctList = null;
            response.status = 'Error';
            response.message = 'Your request failed with the following error: ' + exc.getMessage();
        }
        
        return response;
    }
    
    global class BankAccountWrapper {
        public List<Bank_Account__c> bacctList;
        public String status;
        public String message;
        
        public BankAccountWrapper(){
            bacctList = new List<Bank_Account__c>();
        }
    }   
}

The problem is the FOR loop. I tried using the IN clause in SOQL but the problem is im not getting the ID in the JSON string.
List<Bank_Account__c> bankAccountsToUpdate= new List<Bank_Account__c>();
        integer updatedRecordCount=0;
        
        List<Bank_Account__c> ac= [select Name,Debit_Order_A_c__c,A_c_Number__c,Bank_code__c From Bank_Account__c where Id IN : bacctList];
                    
		for(integer i=0; i<ac.size(); i++){                                    
			ac[i].Debit_Order_A_c__c = false;       
			bankAccountsToUpdate.add(ac[i]);
			updatedRecordCount++;                 
		
		}

PLEASE HELP.

 
Please assist with a compile error in my test class:
User-added image

If I remove the variable 'bacctList'

User-added image
Full Class:
 
/***************************************************************************************************Json String:
 
   { "bacctList" : 
     [{
       "A_c_Number__c" : "323838492",
       "Bank_code__c" : "198765"
      },
      {
       "A_c_Number__c" : "198765",
       "Bank_code__c" : "250655"
      }]
   }
 *    
 ****************************************************************************************************/
@RestResource(urlMapping='/dosystem/bankaccounts/*')
global with sharing class BankAccountWebservice{
   
 @HttpPatch
    global static BankAccountWrapper doPatch(List<Bank_Account__c> bacctList) {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        BankAccountWrapper response = new BankAccountWrapper();
        
        List<Bank_Account__c> bankAccountsToUpdate= new List<Bank_Account__c>();

        for(integer i=0; i<bacctList.size(); i++){
            List<Bank_Account__c> ac = [select Name,Debit_Order_A_c__c,A_c_Number__c,Bank_code__c  from Bank_Account__c where  A_c_Number__c =: bacctList[i].A_c_Number__c AND Bank_code__c =: bacctList[i].Bank_code__c];
            
            for(integer j=0; j< ac.size(); j++){
                ac[j].Debit_Order_A_c__c = false;       
                bankAccountsToUpdate.add(ac[j]);
             }    
        }
        
        try {
            update bankAccountsToUpdate;

            response.bacctList = bankAccountsToUpdate;
            response.status = 'Success';
            response.message = bacctList.size()+' Records Updated successfully';
        }
        catch(Exception exc) {
            res.StatusCode = 500;
            response.bacctList = null;
            response.status = 'Error';
            response.message = 'Your request failed with the following error: ' + exc.getMessage();
        }
        
        return response;
    }
    
    global class BankAccountWrapper {
        public List<Bank_Account__c> bacctList;
        public String status;
        public String message;
        
        public BankAccountWrapper(){
            bacctList = new List<Bank_Account__c>();
        }
    }   
}
Full Test Class
 
@isTest
private class BankAccountWebserviceTest{
    
   static testMethod void testDoGet_WithoutId() {
        
        setupTestData();
        
        Test.startTest();
        // Set up the RestContext object
        System.RestContext.request = new RestRequest();
        System.RestContext.response = new RestResponse();
        RestContext.request.requestURI = 'https://cs87.salesforce.com/services/apexrest/dosystem/bankaccounts/';  
        RestContext.request.httpMethod = 'PATCH';
        
        BankAccountWebservice.BankAccountWrapper results = new BankAccountWebservice.BankAccountWrapper();
        results = BankAccountWrapper.doPatch(bacctList);
        Test.stopTest();
        
        system.assertEquals(results.status, 'Success');
        system.assertEquals(results.message,'2 Records Updated successfully');
        system.assertEquals(System.RestContext.response.StatusCode, 200);
    }
    private static void setupTestData() {
        List<Account> accounts = new List<Account>();
        accounts.add(new Account(Name='Account 1', Phone='(111) 222-3344', Website='www.account1.com'));
        accounts.add(new Account(Name='Account 2', Phone='(222) 333-4455', Website='www.account1.com'));
        insert accounts;
        
        List<Bank_Account__c> baccounts = new List<Bank_Account__c>();
        baccounts.add(new Bank_Account__c(Account__c  = accounts[0].Id, Bank__c = 'FNB', A_c_Number__c='123456789', Bank_A_C_Type__c='Savings',Debit_Order_A_c__c = true));
        baccounts.add(new Bank_Account__c(Account__c  = accounts[1].Id, Bank__c = 'FNB', A_c_Number__c='987654321', Bank_A_C_Type__c='Savings', Debit_Order_A_c__c = true));
        insert baccounts;        
    }
    
      
}


 
Below is my class.
@RestResource(urlMapping='/V1/IndividualKYC/*')
global with sharing class IndividualKYCManager {

  //Create
  @HttpPost
    global static String createIndividualKYC(String a,Boolean termsandconditions,String phone, 
    String idnum, String name,String photo, String email, ID entity, String address1, String address2, String suburb, String nationality, Integer postcode, String summary) {
       
        Individual_KYC__c ikyc= new Individual_KYC__c ();
            
        ikyc.Name=name;
        ikyc.Email__c=email;
        ikyc.ID_Number__c=idnum;
        ikyc.Phone__c=phone;
        ikyc.Terms_and_Conditions__c = termsandconditions;
        ikyc.Address_Line_1__c = address1;
        ikyc.Address_Line_2_Optional__c= address2;
        ikyc.Suburb__c= suburb;
        ikyc.Nationality__c= nationality;
        ikyc.Post_Code__c= postcode;
        ikyc.Profile_Summary__c= summary ;
        
        string before = photo;
        Blob beforeblob = Blob.valueOf(before);
        string paramvalue = EncodingUtil.base64Encode(beforeblob);
        
        ikyc.Photo__c = paramvalue ; 
        insert ikyc;
        String ikycid=ikyc.id;
        return ikycid;
          
    }
    
    global void createAtt(String  ikycid)
    {
    
      String pId=ikycid;
        
     
     string before2 = 'Testing base 64 encode';
     Blob beforeblob = Blob.valueOf(before2);
     string paramvalue = EncodingUtil.base64Encode(beforeblob);
     //System.debug(before2 + ' is now encoded as: ' + paramvalue);
     
         Attachment attachmet = new Attachment (ParentId = pId,
                                           Body = EncodingUtil.base64Decode(paramvalue),
                                           ContentType = 'application/vnd.ms-excel',
                                           Name = 'SendViaMyPhone');
          insert attachmet ;
    
    }
}
I want to insert a record & create 2 attachments in one POST. The challenge is wont allow me to have 2 inserts (ikyc & attachmet) in one method (createIndividualKYC), which is why i've split them. Im looking for a way to insert a record with 2 attachements (pdf. & jpg.) In one POST.
 
I want the radio buttons to look like the image below. below is my code.
I want the  radio buttons to look like this 
Currently they look like this
 
 User-added image

below is my code, please help.
<apex:selectRadio value="{!Object__c.Field__c}"  layout="pageDirection"  >
      <apex:selectOption itemLabel="USA <br/> New york <br/> Chicago" itemValue="USA" itemEscaped="false" />
      <apex:selectOption itemLabel="Japan <br/> Osaka <br/> Tokyo"  itemValue="Japan" itemEscaped="false" />       </apex:selectRadio>
This code displays a multi-select picklist as checkboxes perfectly on a Visualforce page, but when clicking the save button, it shows this error.
Conversion Error setting value 'Its complicated' for '#{Benchmarking_Result__c.Challenges_with_M_E__c}'.

Here is the controller
Public ApexPages.StandardController stdcontroller;

List<SelectOption> Commprefvalue = new List<SelectOption>();
   
    public List<Selectoption> getCommpref()
    {
        Schema.DescribeFieldResult CommprefField = Schema.sObjectType.Benchmarking_Result__c.fields.Challenges_with_M_E__c; 
        Schema.PicklistEntry [] Commpref = CommprefField.getPickListValues();
       
        //Schema.PicklistEntry [] values = vendorField.getPickListValues();
        for(Schema.PicklistEntry val : Commpref)
        {
            Commprefvalue.add(new SelectOption(val.getValue(), val.getLabel()));
        }
        return Commprefvalue;        
    }

//Save button
    public PageReference MAndEDevSaveBtn(){
        stdcontroller.save();
        PageReference callNextPage= Page.CSI_Positioning_And_Governence;
        callNextPage.setRedirect(true);
        return callNextPage;
    }

On the VF page.
<apex:selectCheckboxes value="{!Benchmarking_Result__c.Challenges_with_M_E__c}" layout="pageDirection">
          <apex:selectoptions value="{!Commpref}"></apex:selectoptions>
 </apex:selectCheckboxes>

<apex:commandButton value="Save and Continue" action="{!MAndEDevSaveBtn}" />
The error
User-added image
I have a custom object (standardController="Benchmarking__c"), I created a multi select picklist with values London, Tokyo & LA. I would like these values  to appear as checkboxes on the Visualforce page.

<apex:inputField value="{!Benchmarking_Result__c.Select_Cities__c}"/>
 
When the user clicks link on his email it opens up a site/ VF page & on that first page I want the pop to show immediatly without the user clicking a button. The popup works but the problem is you have to click the button first before it shows.

I got the code from here http://www.salesforcegeneral.com/salesforce-modal-dialog-box/
I have a custom object (standardController="Benchmarking__c"), I created a multi select picklist with values London, Tokyo & LA. I would like these values  to appear as checkboxes on the Visualforce page.

<apex:inputField value="{!Benchmarking_Result__c.Select_Cities__c}"/>
 
I want pull only the list of records that match the ones i'm getting through a JSON array list. The json array list string doesn't have the Salesforce record ID.The JSON string looks like below. I use the rcNumber, accountNumber and bankName  as a composite primary key and what's returned on unpaidCode as a condition for updating records.
{
    "bacctList": [{
        "rcNumber": "RC-2848323",
        "accountNumber": "12324434",
        "bankName" :  "NEDBANK",
        "unpaidCode" : ""
    },
    {
        "rcNumber": "RC-002274",
        "accountNumber": "1111111",
        "bankName" :  "FNB",
        "unpaidCode" : "99"
    }]
}
The Logic of the class works perfectly, I just want to bulkify it. Please help!...the fist for loop (line 27) with an inner loop, I think is not best practice.
 
@RestResource(urlMapping='/dosystem/bankaccounts2/*')
global with sharing class BankAccountWebservice2 {
       
    //Decorator class- Retured JSON mapping
    global class BankAccountsReturned{
        public String rcNumber;             
        public String accountNumber;  
        public String bankName;
        public String unpaidCode;
        
        public BankAccountsReturned(String rcNum, String accNum, String bName, String uCode){
            this.rcNumber = rcNum;
            this.accountNumber = accNum;
            this.bankName = bName;
            this.unpaidCode =uCode;
        }          
    } 
    
    @HttpPatch
    global static List<Bank_Account__c > updateDateProcessed(BankAccountsReturned [] bacctList) {
        
        //St
        List<String> rcNumbers = new List<String>{};  
           
        List<Bank_Account__c> BAccList  = new List<Bank_Account__c>{};
        
        for (integer i=0; i< bacctList.size(); i++) {                                                         
             for(Bank_Account__c j : [select id, Account__r.Name, Account__r.RC_Account_No__c,Bank__c,RC_Account_No__c,Unpaid_Code__c  
                                                         FROM Bank_Account__c where 
                                                         RC_Account_No__c =: bacctList[i].rcNumber AND 
                                                         A_c_Number__c =: bacctList[i].accountNumber AND 
                                                         Bank__c =: bacctList[i].bankName ]){

              // If unpaidCode is blank then deactive bank account, DO NOT create case 
              if(bacctList[i].unpaidCode == ''){                      
                  BAccList.add(new Bank_Account__c(Id = j.Id, Debit_Order_A_c__c = false, Unpaid_Code__c = bacctList[i].unpaidCode));
              }
              /* If the error code is populated with 99 the DO NOT deactivate the bank account BUT
               create an active ADHOC record with the current Debit Order amount on the bank account. DO NOT Create Case */
              else if(bacctList[i].unpaidCode == '99'){
                  rcNumbers.add(j.Account__r.RC_Account_No__c);
                  BAccList.add(new Bank_Account__c(Id = j.Id, Debit_Order_A_c__c = true, Unpaid_Code__c = bacctList[i].unpaidCode));                  
              }
              //If unpaid code is any other number beside 99, deactivate and create a case
              else{
                 
                  rcNumbers.add(j.Account__r.RC_Account_No__c); //<--Populates the list with ONLY RC Numbers we need to create cases for
                  BAccList.add(new Bank_Account__c(Id = j.Id, Debit_Order_A_c__c = false, Unpaid_Code__c = bacctList[i].unpaidCode));
              
              }
            }                                  
        }  
        
        update  BAccList;
        
        //Create Adhoc records
        List<Ad_hoc_Debit_Orders__c> adhocRecords = new List<Ad_hoc_Debit_Orders__c>();
        for(Bank_Account__c createActiveDO : [select id, Bank__c,Unpaid_Code__c,
                                            (select Id,Current_DO__c from Bank_Account__c.Debit_Orders__r where Active__c = true Order by CreatedDate Desc LIMIT 1)
                                              from Bank_Account__c where id in: BAccList and Unpaid_Code__c= '99']){
                                              
            Ad_hoc_Debit_Orders__c ad = new Ad_hoc_Debit_Orders__c(); 
            ad.Bank_ID__c = createActiveDO.id;
            ad.Custom__c = 'Adhoc';
            ad.Debit_Order_amount__c = createActiveDO.Debit_Orders__r[0].Current_DO__c;
            ad.Active__c = true;   
            adhocRecords.add(ad);     
        }
        insert adhocRecords;
        
        
        //Get more details about the deactivated bank account inoder to be populated when creating case.
        List<Case> createCase = new List<Case>();
        for(Account oUsr: [SELECT Id, Name, RC_Account_No__c,
                                    (select Id, Name, email, phone from contacts where Primary_contact_Indicator__c = true order by createddate desc Limit 1),
                                    (select Id, Name, Bank__c from Account.Bank_Accounts__r where Debit_Order_A_c__c = true Order by CreatedDate Desc LIMIT 1 )
                                     FROM Account WHERE RC_Account_No__c in: rcNumbers ]){
            Case u = new Case();            
            u.AccountId = oUsr.id;
            u.ContactId = oUsr.Contacts[0].Id;        
            u.Status = 'New';
            u.Origin = 'API Call';
            u.Subject = 'Deactivated Bank Account';
            u.Description = 'Bank Account Deactivated for '+oUsr.Name +' Account with  '+oUsr.RC_Account_No__c+' Number';             
            createCase.add(u);
        }
        insert createCase;
       
       return BAccList;
       }         
    }
I would like to use best practice. Because the json array string doesn't have the salesforce record Id, I want to select only the records is salesforce that = my composite primary key. and store them on a list as it will have the Record ID which will make it easier to do processing & updates.
I'm receiving a JSON string from another system in the format below. These records already exist in Salesforce. I want to only query these records in salesforce, set a boolean field to false in all of them and update.
{ "bacctList" : 
     [{
       "RC_Account_No__c" : "RC-2",
       "A_c_Number__c" : "111",
       "Bank_code__c" : "250655"
      },
      {
       "RC_Account_No__c" : "RC-1",
       "A_c_Number__c" : "222",
       "Bank_code__c" : "198765"
      }]
   }

The below code works fine, the issue is it's not bulkified.
@RestResource(urlMapping='/dosystem/bankaccounts/*')
global with sharing class BankAccountWebservice{
   
 @HttpPatch
    global static BankAccountWrapper doPatch(List<Bank_Account__c> bacctList) {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        BankAccountWrapper response = new BankAccountWrapper();
        
        List<Bank_Account__c> bankAccountsToUpdate= new List<Bank_Account__c>();

        for(integer i=0; i<bacctList.size(); i++){
            List<Bank_Account__c> ac = [SELECT Debit_Order_A_c__c,A_c_Number__c,Bank_code__c,RC_Account_No__c  
            FROM Bank_Account__c 
            WHERE (RC_Account_No__c =: bacctList[i].RC_Account_No__c AND  A_c_Number__c =: bacctList[i].A_c_Number__c AND Bank_code__c =: bacctList[i].Bank_code__c)];
            
            for(integer j=0; j< ac.size(); j++){
                ac[j].Debit_Order_A_c__c = false;       
                bankAccountsToUpdate.add(ac[j]);
             }    
        }
        
        try {
            update bankAccountsToUpdate;

            response.bacctList = bankAccountsToUpdate;
            response.status = 'Success';
            response.message = bacctList.size()+' Records Updated successfully';
        }
        catch(Exception exc) {
            res.StatusCode = 500;
            response.bacctList = null;
            response.status = 'Error';
            response.message = 'Your request failed with the following error: ' + exc.getMessage();
        }
        
        return response;
    }
    
    global class BankAccountWrapper {
        public List<Bank_Account__c> bacctList;
        public String status;
        public String message;
        
        public BankAccountWrapper(){
            bacctList = new List<Bank_Account__c>();
        }
    }   
}

The problem is the FOR loop. I tried using the IN clause in SOQL but the problem is im not getting the ID in the JSON string.
List<Bank_Account__c> bankAccountsToUpdate= new List<Bank_Account__c>();
        integer updatedRecordCount=0;
        
        List<Bank_Account__c> ac= [select Name,Debit_Order_A_c__c,A_c_Number__c,Bank_code__c From Bank_Account__c where Id IN : bacctList];
                    
		for(integer i=0; i<ac.size(); i++){                                    
			ac[i].Debit_Order_A_c__c = false;       
			bankAccountsToUpdate.add(ac[i]);
			updatedRecordCount++;                 
		
		}

PLEASE HELP.

 
Please assist with a compile error in my test class:
User-added image

If I remove the variable 'bacctList'

User-added image
Full Class:
 
/***************************************************************************************************Json String:
 
   { "bacctList" : 
     [{
       "A_c_Number__c" : "323838492",
       "Bank_code__c" : "198765"
      },
      {
       "A_c_Number__c" : "198765",
       "Bank_code__c" : "250655"
      }]
   }
 *    
 ****************************************************************************************************/
@RestResource(urlMapping='/dosystem/bankaccounts/*')
global with sharing class BankAccountWebservice{
   
 @HttpPatch
    global static BankAccountWrapper doPatch(List<Bank_Account__c> bacctList) {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        BankAccountWrapper response = new BankAccountWrapper();
        
        List<Bank_Account__c> bankAccountsToUpdate= new List<Bank_Account__c>();

        for(integer i=0; i<bacctList.size(); i++){
            List<Bank_Account__c> ac = [select Name,Debit_Order_A_c__c,A_c_Number__c,Bank_code__c  from Bank_Account__c where  A_c_Number__c =: bacctList[i].A_c_Number__c AND Bank_code__c =: bacctList[i].Bank_code__c];
            
            for(integer j=0; j< ac.size(); j++){
                ac[j].Debit_Order_A_c__c = false;       
                bankAccountsToUpdate.add(ac[j]);
             }    
        }
        
        try {
            update bankAccountsToUpdate;

            response.bacctList = bankAccountsToUpdate;
            response.status = 'Success';
            response.message = bacctList.size()+' Records Updated successfully';
        }
        catch(Exception exc) {
            res.StatusCode = 500;
            response.bacctList = null;
            response.status = 'Error';
            response.message = 'Your request failed with the following error: ' + exc.getMessage();
        }
        
        return response;
    }
    
    global class BankAccountWrapper {
        public List<Bank_Account__c> bacctList;
        public String status;
        public String message;
        
        public BankAccountWrapper(){
            bacctList = new List<Bank_Account__c>();
        }
    }   
}
Full Test Class
 
@isTest
private class BankAccountWebserviceTest{
    
   static testMethod void testDoGet_WithoutId() {
        
        setupTestData();
        
        Test.startTest();
        // Set up the RestContext object
        System.RestContext.request = new RestRequest();
        System.RestContext.response = new RestResponse();
        RestContext.request.requestURI = 'https://cs87.salesforce.com/services/apexrest/dosystem/bankaccounts/';  
        RestContext.request.httpMethod = 'PATCH';
        
        BankAccountWebservice.BankAccountWrapper results = new BankAccountWebservice.BankAccountWrapper();
        results = BankAccountWrapper.doPatch(bacctList);
        Test.stopTest();
        
        system.assertEquals(results.status, 'Success');
        system.assertEquals(results.message,'2 Records Updated successfully');
        system.assertEquals(System.RestContext.response.StatusCode, 200);
    }
    private static void setupTestData() {
        List<Account> accounts = new List<Account>();
        accounts.add(new Account(Name='Account 1', Phone='(111) 222-3344', Website='www.account1.com'));
        accounts.add(new Account(Name='Account 2', Phone='(222) 333-4455', Website='www.account1.com'));
        insert accounts;
        
        List<Bank_Account__c> baccounts = new List<Bank_Account__c>();
        baccounts.add(new Bank_Account__c(Account__c  = accounts[0].Id, Bank__c = 'FNB', A_c_Number__c='123456789', Bank_A_C_Type__c='Savings',Debit_Order_A_c__c = true));
        baccounts.add(new Bank_Account__c(Account__c  = accounts[1].Id, Bank__c = 'FNB', A_c_Number__c='987654321', Bank_A_C_Type__c='Savings', Debit_Order_A_c__c = true));
        insert baccounts;        
    }
    
      
}


 
Below is my class.
@RestResource(urlMapping='/V1/IndividualKYC/*')
global with sharing class IndividualKYCManager {

  //Create
  @HttpPost
    global static String createIndividualKYC(String a,Boolean termsandconditions,String phone, 
    String idnum, String name,String photo, String email, ID entity, String address1, String address2, String suburb, String nationality, Integer postcode, String summary) {
       
        Individual_KYC__c ikyc= new Individual_KYC__c ();
            
        ikyc.Name=name;
        ikyc.Email__c=email;
        ikyc.ID_Number__c=idnum;
        ikyc.Phone__c=phone;
        ikyc.Terms_and_Conditions__c = termsandconditions;
        ikyc.Address_Line_1__c = address1;
        ikyc.Address_Line_2_Optional__c= address2;
        ikyc.Suburb__c= suburb;
        ikyc.Nationality__c= nationality;
        ikyc.Post_Code__c= postcode;
        ikyc.Profile_Summary__c= summary ;
        
        string before = photo;
        Blob beforeblob = Blob.valueOf(before);
        string paramvalue = EncodingUtil.base64Encode(beforeblob);
        
        ikyc.Photo__c = paramvalue ; 
        insert ikyc;
        String ikycid=ikyc.id;
        return ikycid;
          
    }
    
    global void createAtt(String  ikycid)
    {
    
      String pId=ikycid;
        
     
     string before2 = 'Testing base 64 encode';
     Blob beforeblob = Blob.valueOf(before2);
     string paramvalue = EncodingUtil.base64Encode(beforeblob);
     //System.debug(before2 + ' is now encoded as: ' + paramvalue);
     
         Attachment attachmet = new Attachment (ParentId = pId,
                                           Body = EncodingUtil.base64Decode(paramvalue),
                                           ContentType = 'application/vnd.ms-excel',
                                           Name = 'SendViaMyPhone');
          insert attachmet ;
    
    }
}
I want to insert a record & create 2 attachments in one POST. The challenge is wont allow me to have 2 inserts (ikyc & attachmet) in one method (createIndividualKYC), which is why i've split them. Im looking for a way to insert a record with 2 attachements (pdf. & jpg.) In one POST.
 
I want the radio buttons to look like the image below. below is my code.
I want the  radio buttons to look like this 
Currently they look like this
 
 User-added image

below is my code, please help.
<apex:selectRadio value="{!Object__c.Field__c}"  layout="pageDirection"  >
      <apex:selectOption itemLabel="USA <br/> New york <br/> Chicago" itemValue="USA" itemEscaped="false" />
      <apex:selectOption itemLabel="Japan <br/> Osaka <br/> Tokyo"  itemValue="Japan" itemEscaped="false" />       </apex:selectRadio>
This code displays a multi-select picklist as checkboxes perfectly on a Visualforce page, but when clicking the save button, it shows this error.
Conversion Error setting value 'Its complicated' for '#{Benchmarking_Result__c.Challenges_with_M_E__c}'.

Here is the controller
Public ApexPages.StandardController stdcontroller;

List<SelectOption> Commprefvalue = new List<SelectOption>();
   
    public List<Selectoption> getCommpref()
    {
        Schema.DescribeFieldResult CommprefField = Schema.sObjectType.Benchmarking_Result__c.fields.Challenges_with_M_E__c; 
        Schema.PicklistEntry [] Commpref = CommprefField.getPickListValues();
       
        //Schema.PicklistEntry [] values = vendorField.getPickListValues();
        for(Schema.PicklistEntry val : Commpref)
        {
            Commprefvalue.add(new SelectOption(val.getValue(), val.getLabel()));
        }
        return Commprefvalue;        
    }

//Save button
    public PageReference MAndEDevSaveBtn(){
        stdcontroller.save();
        PageReference callNextPage= Page.CSI_Positioning_And_Governence;
        callNextPage.setRedirect(true);
        return callNextPage;
    }

On the VF page.
<apex:selectCheckboxes value="{!Benchmarking_Result__c.Challenges_with_M_E__c}" layout="pageDirection">
          <apex:selectoptions value="{!Commpref}"></apex:selectoptions>
 </apex:selectCheckboxes>

<apex:commandButton value="Save and Continue" action="{!MAndEDevSaveBtn}" />
The error
User-added image
When the user clicks link on his email it opens up a site/ VF page & on that first page I want the pop to show immediatly without the user clicking a button. The popup works but the problem is you have to click the button first before it shows.

I got the code from here http://www.salesforcegeneral.com/salesforce-modal-dialog-box/

Hi All,

I have a multiselect picklist value in the vf page. Its a read only field. When I output the field the values appears with semicolon

 

Currently I am using the below code to ouput the field value

 <apex:outputText label="Franchises" value="{!Account.Franchises__c}"></apex:outputText>

and this displays the field values like below

Audi; Acura; Ford

My requirement here is i want to display the values without the semicolons. Can i display each value in a different line?

Eg: Audi

      Acura

     Ford

how can i do this?