• Anil Savaliya
  • NEWBIE
  • 248 Points
  • Member since 2013
  • Salesforce Developer
  • WellsFargo & Comapany.

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 2
    Likes Given
  • 10
    Questions
  • 70
    Replies

As per release winter 16 release notes: http://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/salesforce_release_notes.htm
 

REQUIRESCRIPT no longer executes JavaScript on Page Load.

We use the REQUIRESCRIPT function in several custom buttons on our lead page.  When the Winter 16 features were released into our sandbox, our buttons started returning an error Reference $ Undefined.

I reached out to salesforce support, and they told me to use the code in the following article which removed the REQUIRESCRIPT function and instead, creates a custom java function.

https://help.salesforce.com/apex/HTViewSolution?urlname=Receiving-error-sforce-apex-is-null-or-not-an-object-1327108329858&language=en_US

I've been messing with the code above to fit it into my button.  I'm stepping through the code through alerts, it stepped all the way through but at the end I get an Object error.  Any help would be appreciated.

function loadScript(url) 

    var request; 
    if (window.XMLHttpRequest) 
    { 
        request = new XMLHttpRequest(); 
    }     
    else if (window.ActiveXObject) 
    { 
        request = new ActiveXObject("Msxml2.XMLHTTP"); 
        if (!request) 
        { 
            request = new ActiveXObject("Microsoft.XMLHTTP"); 
        } 
    
    } 


    var se = document.createElement('script'); 
    se.type = "text/javascript"; 
    //alert("before Request undefined\n");
    request.open("GET", url, false); 
    request.send(null); 
    se.text = request.responseText; 
    document.getElementsByTagName('head')[0].appendChild(se); 
    //alert("end of loadScript\n");


loadScript("/soap/ajax/30.0/connection.js"); 
loadScript("/soap/ajax/30.0/apex.js"); 
loadScript("/resource/jQuery/jquery-1.8.2.min.js"); 
loadScript("/resource/jQuery/ui/jquery-ui-1.9.1.custom.min.js");
loadScript("/resource/jQuery/postmessage/jquery.ba-postmessage.js");
loadScript("/resource/jQuery/bbq/jquery.ba-bbq.min.js");
loadScript("/resource/buttonjs");

try 

    var j$ = jQuery.noConflict(); 
    var newurl= sforce.apex.execute("RegisterMerchant", "getPricingArticleID",{leadID : "{!Lead.Id}"}); 
    newurl1 = String(newurl); 
    alert('Lead ArticleID '+newurl1); 
    if(newurl1.indexOf('error')>-1 ) 

    alert(newurl); 
    document.location.reload(true); 

else 

    alert('Start of Else Statement')
    var strQuery="Select l.of_Pin_Pads__c,l.Id, l.Article_ID__c, l.Processing_Origin__c, l.Company, l.Strategic__c, l.Gift_Only__c, l.Dealer__r.Name, l.Developer__c, l.DLR_Sales__c, l.Name, l.OwnerId from Lead l where Id= '" +'{!Lead.Id}'+"'"; 
    var accFields = sforce.connection.query(strQuery); 
    var records = accFields.getArray("records"); 

    var owner = records[0].OwnerId; 
    var ContactName = records[0].Name; 

    var leadId = records[0].ID; 
    var Dealer = records[0].Dealer__r.Name; 
    var devID = records[0].Developer__c; 
    var Developer = null; 
    var DealerSalesperson = null; 
    if (devID!=null) 
    alert('Developer Record')
    

    var strQuery3 = "SELECT Name from Account where ID='" +devID+"'"; 
    var devField = sforce.connection.query(strQuery3); 
    var devRecord = devField.getArray("records"); 
    Developer = devRecord[0].Name; 
    


var ds = records[0].DLR_Sales__c; 
//if (ds!= null) 
    alert('DLR sales Record1')
//{ 
var strQuery6 = "Select Name from Contact where id = '" +ds+"'"; 
var dlrSalesField = sforce.connection.query(strQuery6); 
var dlrSalesRecord = dlrSalesField.getArray("records"); 
DealerSalesperson = dlrSalesRecord[0].Name; 
//}
alert('Dlr sales Record2') 

var NumberOfPinpads = 0; 
//if(records[0].of_Pin_Pads__c!=null) 
//{ 
NumberOfPinpads = parseInt(records[0].of_Pin_Pads__c); 
//}
alert('Pin Pads') 
var ArticleId = records[0].Article_ID__c; 
var ProcessingOrigin = records[0].Processing_Origin__c; 
var CompanyName = records[0].Company; 
var StrategicAccount= records[0].Strategic__c; 
var GiftOnly = records[0].Gift_Only__c; 
alert('Other stuff') 


// if diff is null, continue, if user clicked cancel, allow them to chg processing origin 
console.log('leadId '+leadId+'--'+Dealer+'--'+Developer+'--'+ArticleId+'--'+DealerSalesperson); 
// next section stolen from Josh, thanks for doing my typing buddy! 
var $articleId = $('<input>', { name: 'ArticleId', type: 'hidden', value: ArticleId }); 
var $processingOrigin = $('<input>', { name: 'ProcessingOrigin', type: 'hidden', value: ProcessingOrigin }); 
var $companyName = $('<input>', { name: 'CompanyName', type: 'hidden', value: CompanyName }); 
var $strategicAccount = $('<input>', { name: 'StrategicAccount', type: 'hidden', value: StrategicAccount }); 
var $giftOnly = $('<input>', { name: 'GiftOnly', type: 'hidden', value: GiftOnly }); 
var $contactName = $('<input>', { name: 'ContactName', type: 'hidden', value: ContactName }); 
var $dealer = $('<input>', { name: 'Dealer', type: 'hidden', value: Dealer }); 
var $developer = $('<input>', { name: 'Developer', type: 'hidden', value: Developer }); 
var $dealerSalesperson = $('<input>', { name: 'DealerSalesperson', type: 'hidden', value: DealerSalesperson }); 
var $numberOfPinpads = $('<input>', { name: 'NumberOfPinpads', type: 'hidden', value: NumberOfPinpads }); 

//alert($articleId.html()); 
var $form = $('<form>', { 
'action': '{!$Label.pricingUI}Invoke', 
'method': 'post', 
'target':'_blank' 
}); 

$form.append($articleId); 
$form.append($processingOrigin); 
$form.append($companyName); 
$form.append($strategicAccount); 
$form.append($giftOnly); 
$form.append($contactName); 
$form.append($dealer); 
$form.append($developer); 
$form.append($dealerSalesperson); 
$form.append($numberOfPinpads); 

$(document.body).append($form); 

$form.submit(); 
// alert('done by me'); 


catch(er) 

alert(er); 
}
 

Hi,
i have a requirement where, some statndards components needed to be hidden. With winter 16 release this is not working as expected. 
Does anyone have a workaround for this??
I have this trigger that i created but i am unable to figure out how to get the query out of the for loop, my trigger will run but i know it will hit some governer limits. 

trigger AcceptJobAndCreateEmployee on Candidate_Application__c (after update) {
    
    //This will be the list to add the new candidate
    List<Account> accounts = new List<Account>();

    //Query for the Account Record Types
    List<RecordType> rtypes = [Select name, id FROM RecordType WHERE sObjectType = 'Account' AND IsPersonType = True];
   
    Map<String,String> accountRecordTypes = new Map<String,String>();
        for(RecordType rt: rtypes){
            accountRecordTypes.put(rt.Name,rt.id);
        }
        
    

    for(Candidate_Application__c thisApplication: Trigger.new)
    {
        Candidate_Application__c oldApp = Trigger.oldMap.get(thisApplication.id);
        Boolean AppFalse = oldapp.Job_Accepted__c;
        Boolean AppTrue = thisApplication.Job_Accepted__c;
        
       List <Candidate__c> newCandidates = [Select id, name FROM Candidate__C WHERE id =: thisApplication.Candidate__c]; 
        
        if(!AppFalse && AppTrue)
        {            
            if(newCandidates.size() > 0){
                Account converted = new Account();
            
            
                converted.RecordTypeid = accountRecordTypes.get('Person Account');
                converted.LastName = newCandidates.get(0).Name;
                converted.Phone = newCandidates.get(0).Phone__c;
              
                
                accounts.add(converted);
                
            }
            

        }

    }

    insert accounts;
}
Hi

We have an ecommerce site in php that builds some text string which is emailed to a custom email address in salesforce crm. We need to make some changes in salesforce to exsiting customisation, so are looking for a certified salesforce expert. Please see an example of the information we are sending


title:Mrs<eol>
first_name:Example<eol>
last_name:Example<eol>
homeno:0Example<eol>
mobile:<eol>
email:Example@me.com<eol>
dob:1970-08-16<eol>
address1:My Address <eol>
address2:Example<eol>
town:Bury<eol>
county:Greater Manchester<eol>
post_code:EX1 4PL<eol>
reg_no:Example<eol>
make:Hyundai<eol>
model:i30<eol>
specification:Premium<eol>
style:Hatchback<eol>
engine_cc:1600<eol>
fuel_type:Diesel<eol>
transmission:Manual<eol>
financed:No<eol>
vehicle_purchase_date:2014-93-19<eol>
purchase_value:16000.00<eol>
first_registered_date:2013-09-10<eol>
current_mileage:8843<eol>
gap_policy_type:Vehicle Replacement Insurance<eol>
gap_term:5 Years<eol>
gap_claim_limit:£15000<eol>
gap_price:250<eol>
tyre_policy_type:<eol>
tyre_term:<eol>
tyre_claim_limit:<eol>
tyre_price:<eol>
warranties_policy_type:<eol>
warranties_term:<eol>
warranties_claim_limit:<eol>
warranties_price:<eol>
mot_policy_type:<eol>
mot_term:<eol>
mot_claim_limit:<eol>
mot_price:<eol>
smart_policy_type:<eol>
smart_term:<eol>
smart_claim_limit:<eol>
smart_price:<eol>

I believe we are using a email service and a logic to read it.

We are looking to include a number of extra fields and also set up SF to automatically send an email template to the contact on creation of the account.

Long term, we will be working on a number of similar projects so would like to work with a Salesforce approved/credited company.

Please contact us if you would like more information and to provide a quotation.
I am looking for someone to advise on the best way to:

* Call an external URL when certain salesforce objects (household,contact,activity) are insert/update/deleted
* Ease the registration for calling into the salesforce API (such as using remote site settings when installing AppExchange packages)

and implement it.
Hello,

I'm trying to strategize how best to run this series of SOQL queries without triggering the limits. I have a csv of approximately 10,000 records. The goal is to check for each record whether there is a contact.owner.name associated with it. For instance (not complete, of course):

For(integer i:[csv file]){
SELECT Contact.Owner.Name. Contact.Custom_Field__c FROM Contact WHERE Contact.Custom_Field__c = csvFile[i]
}

How would you recommend I grab the data for all 10,000 records?

Thank you so much for your time and consideration of my inquiry.

With gratitude,
Zac
I am looking to find someone that can do some coding for me to rollup counts from Activities.  I.E
shows amount of times the activity shows as No Answer, Answering Machine etc and also updates the lead status aswell.  

Basic functions to allow me to remove some leads from list view after we have attempted them a few times.
 
We have some custom buttons being developed that we only want to be displayed if items in a picklist match a certain criteria. For example, if the product field is a product that starts with the letter A, don't show the the buttons. If the product selected starts with the letter B, show the buttons (we only have two options that products can start with so it's pretty simple).

My initial idea was to use record types, page layouts, and WFR's, but we already use record types and there is potentially alot of intergration from our software engineers who use this object that we don't want to worry about messing that up. So while we work that part out, is there anything programatically we can do to show or hide buttons based on a field on the record? Without using record types?
Hey,

I am trying to creat visualforce page,and it's render as a PDF,But CSS is working only when i write inline style, But It's not working when i write different in class,

For expriment You can take w3 school sample code : 
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_layout_divs  and page render as PDF

Any comment ? Any Idea ? Any suggestion ?
Dear fellows

I've come across to an error in one of my apex classes:

Error:Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ClientInvoiceAfterUpdate: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0Tb000000E6kACEAZ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ClientInvoiceAfterUpdate: execution of AfterUpdate caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing. Even if a field is indexed a filter might still not be selective when: 1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times) Class.AP516_SetTECHAmountDue.updateTechAmountDue: line 29, column 1 Trigger.ClientInvoiceAfterUpdate: line 189, column 1: [] Class.AP511_SetTechTotalAmountDue.updateAmtDueCurrency: line 149, column 1 Trigger.ClientInvoiceAfterUpdate: line 177, column 1: []

The query is really simple and, as sugested by salesforce, I've splitted the filters of the query to see if in any of them, the result is greater than 100k records. The object where this query is running against to, has more than 100k records as well but the filter when applied separately retrieves way less than 100k records.

Your help and guidance are really appreciated

Best Regards,

Roniel Navarro
Hi,
 
    I am not able to see future method logs in production server where as I can see thos elogs on my sandbox account ?
    Can anyone please help me, How can I enable future method logs in production server ?
    Note : However I can see application logs in my production salesforce.   

Thank,
Abhishek
I would like to manually alter/code the menu bar in my customer portal because I would like to add a navbar with dropdowns (which I believe salesforce does not have out of the box).

How can I do this?
Hi I have the following in a visual force template:
&nbsp;<b>Open Date:</b> &nbsp;<apex:outputText value="{0,date,EEEE, MMMMM dd, yyyy 'at' HH:mm:ss z}"><apex:param value="{!relatedto.BMCServiceDesk__openDateTime__c}" /></apex:outputText><br/>

However this is showing the time as GMT and not BST so is one hour behind.  How would I correct this?

Thanks in advance for any input

Sonya
Hi,

We'd like to be able to query some of our Salesforce data from our front-end web app in order to get some information back for the current application user. Specifically we would like to query Salesforce based on a contact role email address in order to determine what Salesforce accoutn they are associated as well as retrieving information from related account opportunities. 

Thanks, Paul
Hello,

First time question here from a Apex Newbie.....

I have a standard object (Case) which will have a currency field, that I want to update from a rollup summary field on a custom object (Work Order) called Price__c.  The Price__c field on the Work Order Custom Object totals all work order work detail lines, and I want the Price__c field to update the currency field on the case record.  

So far I have the following code written, but I am getting an Invalid Ofreign Key error when tring to quick save.  Can anyone help me here......Thank you in advance

trigger DoRollup on SVMXC__Service_Order__c (after insert, after update, after delete, after undelete) {
    Set<Id> setCaseId=new Set<Id>();
    Map<string,decimal> CaseWithTotalWorkOrders=new Map<string,decimal>();
    for(SVMXC__Service_Order__c mst:Trigger.New){
    if(Case.Total_Billable_Work_Orders__c!=null){
     setCaseId.add(mst.SVMXC__Service_Order__c.Price__c);
    }
    }
   

}
I am trying to create this trigger:

trigger completeFirstResponseCaseComment on CaseComment (after insert) {

// Cannot be a portal user
if (UserInfo.getUserType() == 'Standard'){
  DateTime completionDate = System.now();
  List<Id> caseIds = new List<Id>();
  for (CaseComment cc : Trigger.new){
   // Only public comments qualify
   if(cc.IsPublished == true)
    caseIds.add(cc.ParentId);
  }
  if (caseIds.isEmpty() == false){
   List<Case> caseList = [Select c.Id, c.ContactId, c.Contact.Email,
            c.OwnerId, c.Status,
            c.EntitlementId, c.SlaStartDate,
            c.SlaExitDate
            From Case c
            Where c.Id IN :caseIds];
   if (caseList.isEmpty() == false){
    List<Id> updateCases = new List<Id>();
    for (Case caseObj:caseList) {
     // consider an outbound email to the contact on the case a valid first response
     if ((caseObj.Status == 'In Progress')&&
         (caseObj.EntitlementId != null)&&
         (caseObj.SlaStartDate <= completionDate)&&
         (caseObj.SlaStartDate != null)&&
         (caseObj.SlaExitDate == null))
      updateCases.add(caseObj.Id);
    }
    if(updateCases.isEmpty() == false)
     milestoneUtils.completeMilestone(updateCases, 'First Response', completionDate);
   }
  }
}
}

Then I try to create a milestoneutils class :

public class milestoneUtils {
   
    public static void completeMilestone(List<Id> caseIds, String milestoneName, DateTime complDate) {
     
    List<CaseMilestone> cmsToUpdate = [select Id, completionDate
                       from CaseMilestone cm
                       where caseId in :caseIds and cm.MilestoneType.Name=:milestoneName and completionDate = null limit 1];
    if (cmsToUpdate.isEmpty() == false){
      for (CaseMilestone cm : cmsToUpdate){
        cm.completionDate = complDate;
      }
      update cmsToUpdate;
    } // end if
  }
 
  // test methods
  static testMethod void testCompleteMilestoneCase(){
   
    Contact oContact = [select id from Contact limit 1];
    String contactId;
    if (oContact != null)
      contactId = oContact.Id;
   
    Entitlement entl = [select id from Entitlement limit 1];
    String entlId;
    if (entl != null)
      entlId = entl.Id;
   
    List<Case> cases = new List<Case>{};
    if (entlId != null){
      Case c = new Case(Subject = 'Test Case with Entitlement ', EntitlementId = entlId, ContactId = contactId);
      cases.add(c);
    }
   
    // Insert the Account records that cause the trigger to execute.
    if (cases.isEmpty()==false){
      insert cases;
      List<Id> caseIds = new List<Id>();
      for (Case cL : cases){
        caseIds.add(cL.Id);
      }
      milestoneUtils.completeMilestone(caseIds, 'First Response', System.now());
        }
    }
 
    static testMethod void testCompleteMilestoneViaCase(){
     
        // Perform data preparation
        Entitlement entl = [select id from Entitlement limit 1];
        String entlId;
        if (entl != null)
            entlId = entl.Id;
        List<Case> cases = new List<Case>{};
        for(Integer i = 0; i < 1; i++){
            Case c = new Case(Subject = 'Test Case ' + i);
            cases.add(c);
            if (entlId != null){
                c = new Case(Subject = 'Test Case with Entitlement ' + i, EntitlementId = entlId);
                cases.add(c);
            }
        }
       
        // Insert the Account records that cause the trigger to execute.
        insert cases;

        List<CaseComment> ccs = new List<CaseComment>{};
        for(Case c : cases){
            CaseComment cc = new CaseComment(CommentBody='TestPublic', IsPublished=true, ParentId=c.Id);
            ccs.add(cc);
            cc = new CaseComment(CommentBody='TestPrivate', IsPublished=false, ParentId=c.Id);
            ccs.add(cc);
        }
        if (ccs.isEmpty()==false)
            insert ccs;
   
    // Now create emailmessage objects for them.
   
        List<EmailMessage> emails = new List<EmailMessage>();
        for(Case c : cases){
            emails.add(new EmailMessage(parentId = c.id));
        }
        if(emails.isEmpty()==false)
            database.insert(emails);
       
        for(Case c : cases){
            Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
            String[] toAddr = new String[] {'mramsey@salesforce.com'};
            mail.setToAddresses(toAddr);
            mail.setSaveAsActivity(false);
            mail.setTargetObjectId(c.ContactId);
            mail.setWhatId(c.Id);
            mail.setHtmlBody('TestHTMLBody');
            mail.setPlainTextBody('TestTextBody');
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        }
   
    for(Case c : cases){
      c.Status = 'Closed';
    }
    update cases;
   
        // Query the database for the newly inserted records.
        List<Case> insertedCases = [SELECT Subject,
                                           Description,
                                          (SELECT IsPublished, CommentBody From CaseComments),
                                          (SELECT TextBody, Subject, Incoming From EmailMessages)
                                           FROM Case
                                           WHERE Id IN :cases];
    }
}

But still not luck, I get this error:
: Compile Error: Didn't understand relationship 'EmailMessages' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 103 column 36
Hello: I have a simplest test class to delete a single record, code below. I have checked the select statement via 'query editor' in developer console; it returns a valid id. I just can't figure out why my delete statement does not work!  My class passes the test alright, but when I go and check the line item under the parent opportunity, I can see the line item is there unaffected. Please advise! Thanks very much



@istest
public class del1
{
static testmethod void unittest() {
 
List<opportunitylineitem> ol = [select id from opportunitylineitem where id =: '00km0000001WVUSAA4'] ;
delete ol;

}
}
I am trying to get the URL of an image which I have uploaded on my rich text field of a custom object. Any ideas or pointers.