• Dinesh Multani
  • NEWBIE
  • 214 Points
  • Member since 2014
  • Greytrix

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 23
    Replies
trigger TaskTrigger on Task (before delete) 
{
    if(RecursionControl.TaskrunOnce())
    {
        TaskTriggerHandler.execute(Trigger.old, Trigger.OldMap, Trigger.IsDelete, Trigger.IsBefore);
        //The logic is contained in the execute() method of TaskTriggerHandler Class
    }


Task Trigger Handler Class

public class TaskTriggerHandler 
{
    
    public static void execute(List<Task> oldList, Map<Id, Task> mapOld, Boolean IsDelete, Boolean IsBefore)
    {
        
        /* Activate/Deactivate Trigger by Custom Setting "disableRules__c" */
        disableRules__c theCustomSetting = disableRules__c.getInstance(UserInfo.getUserId());
        
        if(!(String.IsNotBlank(theCustomSetting.Trigger_Objects__c) && theCustomSetting.Trigger_Objects__c.containsIgnoreCase('Task') && theCustomSetting.Disable_Triggers__c))
        {
            for(Task oldObj : oldList)
            {
                oldObj.addError(Label.ActivityDelError);
            }
        }
    }
}

}
商談の詳細画面に配置したカスタムボタンからApexのWebServiceを呼び出していますが、処理に非常に時間がかかるため、その間ローディング画面等にしておきたいと考えます。
BlockUIのプラグインを使うことを想定しています。

意図しているところは、ブロック->Webservice呼び出し->ブロック解除ですが、実際の挙動がWebService処理->ブロック->ブロック解除となってしまいます。(解除部分をSetTimeoutで確認)
Promiseを使用しても結果が変わりません。
意図する順番通りの処理となるような方法はありませんでしょうか?(BlockUIのツールにはこだわりません)
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
{!REQUIRESCRIPT('/resource/' &  LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ',''),10) & '000/jQuery')} // includescript jQuery
{!REQUIRESCRIPT('/resource/' &  LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ',''),10) & '000/jQueryBlockUI')} //includescript jQueryBlockUI

var $ = jQuery.noConflict(); 
var promise = Promise.resolve(); 

function block(){$.blockUI();}
function unblock(){$.unblockUI();}
function exeWS(){
var retStr; 
retStr = sforce.apex.execute("ApexClass", "WebserviceMethod", {oppId:'{!Opportunity.Id}'});
alert(retStr);
}

promise.then(block).then(exeWS).then(unblock);
window.location.reload();
  • January 30, 2018
  • Like
  • 1
Hi,
I am using apex:inputfield to show  picklist values in a VF page. The picklist has various values say A, B, C. But I would like to show only A in my vf page without removing B and C from picklist. Are there any ways to acheive this?

Thanks,
Wahid
Hi,

I am looking at generating a 12 digit code code as autonumber for a text field.
Output : JOHN-2201-0025
{!LEFT( <object>.OwnerId , 4)} + '-' +day(today())+month(today())+ '-' + <autonumber>}

a. Let me know whether this is possible using triggers (before insert, before update>?
 
Hello,
Can someone help me with module Metadata API, unit Build Admin Tools for Automated Configuration Changes?

The error I'm getting is:
Line 12: Method does not exist or incorrect signature; void add(Metadata.CustomMetadataValue) from the type List

Below is my code:
public class MetadataExample {

    public void updateMetadata () {
        Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata();
        customMetadata.fullName = 'MyNamespace__MyMetadataTypeName.MyMetadataRecordName';
        
        Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
        customField.field = 'customField__c';
        customField.value = 'New value';
        
        List <Metadata.CustomMetadata> mdtlist = new List<Metadata.CustomMetadata>();
        mdtlist.add(customField);  // Line 12
    }

}

I feel like I'm missing something very basic but I can't find any documentation specific to what I'm trying to do and the challenge is not similar (to me) to the example. Can someone please explain where I went wrong?
Hello,
Our company is trying to deploy Apex code for the first time from sandbox to production. I read in your docs that you need to have 75% coverage or above to deploy. When I run validation, it seems like a lot of test cases that we didn't write (I'm guessing they are Salesforce tests) are failing, and seem to have lower than 100% coverage. I am guessing this is also pulling our overall coverage down. Is there anyone who could point me in the right direction for how to get these tests cases to pass so that I could deploy?

Here's an example of a test failure in a class that is also not written by us:
Class: AttachmentsToFilesControllerTest
Method: migrationBatchRunStandardUser
Errors: NAMForbiddenException: You don't have permission to access these fields on ContentVersion. Ask your Salesforce admin for help.

Any ideas why so many of these built-in classes have such low coverage and seem to be failing?
I have attached a screenshot of the dev console after I run tests on sandbox:
Built in Salesforce test cases failing
HI Friends, 
I need test class for this apex class, Please do Help, 

public with sharing class LenderLoansController {
    public LenderLoansController() {
    }
    public LenderLoansController(ApexPages.StandardController controller) {

    }
Public String selectedTab {get; set;}
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    
    User U;
    
    public ApexPages.StandardSetController setCon {
        get{
            if(setCon == null){
                size = 25;
                U = [select id,Phone,name,Lender_ID__c from User WHERE ID =:userinfo.getUserId()]; 
                string queryString = 'Select Name, Customer_Name__c, Aadhaar__c, Mobile__c,Order_ID__c, Number_of_Installment__c from Loan__c order by Name';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT id,Name,Customer_Journey_Status__c,Current_Assigned_Lender__c , Number_of_Installment__c,Aadhaar__c, Mobile__c,Customer_Name__c,Order_ID__c from Loan__c Where Current_Assigned_Lender__c =:U.Lender_ID__c AND Customer_Journey_Status__c='Active']));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }
    
    Public List<Loan__c> getLoans(){
        List<Loan__c> accList = new List<Loan__c>();
        for(Loan__c a : (List<Loan__c>)setCon.getRecords())
            accList.add(a);
        return accList;
    }
    
    public pageReference refresh() {
        setCon = null;
        getLoans();
        setCon.setPageNumber(1);
        return null;
    }
}
 
  • January 03, 2018
  • Like
  • 0
We have created one Batchable class at our client org. For now we have no code in our batchable class but just select query. we are facing an Issue that last Apex JOB remains in “Holding” status until we Abort OR new JOB started i.e. As soon as new job started the previous scheduled JOB with “Holding” status get completed and new JOB get stuck in “Holding” . 

Any help will be greatly apprecaited. 
I have a requirement that ananymous user who doesn't requre login to access a page, fills the details, saves to an object (custom, and it has lookup field  to contact) . For this I have done the below steps
  • Added Domain
  • Created new Site
  • Assigned the created VF page in to the list 'Site Visualforce Pages'
  • Activated the site
  • Gave perrmissions (RWA) to the custom object
But when I click on the page I got the following error
Authorization Required

You must first log in or register before accessing this page.
If you have forgotten your password, click Forgot Password to reset it.
We should directly access to the page without authorize, how can we do this?
Thanks,
 
I've made a trigger to automatically create a custom object "Qualification" record attached to the Opp. I recently update this to select the relevant Qualification Record Type based on Opp Record Type.

I'm trying to push the trigger to our production environment but i haven't ever created test classes before, i'm in the process of trying to learn but this has become a rush job to push the change set live now. Anyone able to help me out? Trigger code below:

trigger CreateQualification on Opportunity (after insert, before update) {

    List<Qualification__c> qualtoinsert = new List<Qualification__c>();

    for (Opportunity opp : Trigger.new) {

        // Create qualification record only when the Stage is Updated to "Attendance"
        if (opp.StageName == 'Attendance' && !opp.Qual_trigger__c ) {
            
            if (opp.RecordTypeId == '01220000000Mebg' || opp.RecordTypeId == '0120J000000B69P' || opp.RecordTypeId == '0122000000034yA'){
                
                Qualification__c qual = new Qualification__c();
                
                qual.RecordTypeId = '0127E00000070be';
                
                qual.Opportunity__c   = opp.id;           
                opp.Qual_Trigger__c = True;
                qualtoinsert.add(qual); // For Bulk processing of the Records.
                
            } //End if
            
            else {
                
                Qualification__c qual = new Qualification__c();
                
                qual.RecordTypeId = '0127E00000070bj';
                
                qual.Opportunity__c   = opp.id;           
                opp.Qual_Trigger__c = True;
                qualtoinsert.add(qual); // For Bulk processing of the Records.
                
            } //End else          
        } //End if
    } // End of For

    // Inserting the New Qualification Record.
    if ( !qualtoinsert.isEmpty()) {
        insert qualtoinsert;
    }
}

Many Thanks,
Steve.
 write a trigger on Account, While inserting a account  name value as ‘someName’ ended with ‘text’ ex: ‘renuText’.
 it should through an error On Account Object if name field has 'text' 
  • January 31, 2018
  • Like
  • 0
trigger TaskTrigger on Task (before delete) 
{
    if(RecursionControl.TaskrunOnce())
    {
        TaskTriggerHandler.execute(Trigger.old, Trigger.OldMap, Trigger.IsDelete, Trigger.IsBefore);
        //The logic is contained in the execute() method of TaskTriggerHandler Class
    }


Task Trigger Handler Class

public class TaskTriggerHandler 
{
    
    public static void execute(List<Task> oldList, Map<Id, Task> mapOld, Boolean IsDelete, Boolean IsBefore)
    {
        
        /* Activate/Deactivate Trigger by Custom Setting "disableRules__c" */
        disableRules__c theCustomSetting = disableRules__c.getInstance(UserInfo.getUserId());
        
        if(!(String.IsNotBlank(theCustomSetting.Trigger_Objects__c) && theCustomSetting.Trigger_Objects__c.containsIgnoreCase('Task') && theCustomSetting.Disable_Triggers__c))
        {
            for(Task oldObj : oldList)
            {
                oldObj.addError(Label.ActivityDelError);
            }
        }
    }
}

}
商談の詳細画面に配置したカスタムボタンからApexのWebServiceを呼び出していますが、処理に非常に時間がかかるため、その間ローディング画面等にしておきたいと考えます。
BlockUIのプラグインを使うことを想定しています。

意図しているところは、ブロック->Webservice呼び出し->ブロック解除ですが、実際の挙動がWebService処理->ブロック->ブロック解除となってしまいます。(解除部分をSetTimeoutで確認)
Promiseを使用しても結果が変わりません。
意図する順番通りの処理となるような方法はありませんでしょうか?(BlockUIのツールにはこだわりません)
 
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/30.0/apex.js")}
{!REQUIRESCRIPT('/resource/' &  LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ',''),10) & '000/jQuery')} // includescript jQuery
{!REQUIRESCRIPT('/resource/' &  LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(TEXT(NOW()),':',''),'-',''),' ',''),10) & '000/jQueryBlockUI')} //includescript jQueryBlockUI

var $ = jQuery.noConflict(); 
var promise = Promise.resolve(); 

function block(){$.blockUI();}
function unblock(){$.unblockUI();}
function exeWS(){
var retStr; 
retStr = sforce.apex.execute("ApexClass", "WebserviceMethod", {oppId:'{!Opportunity.Id}'});
alert(retStr);
}

promise.then(block).then(exeWS).then(unblock);
window.location.reload();
  • January 30, 2018
  • Like
  • 1
Hi,
I am using apex:inputfield to show  picklist values in a VF page. The picklist has various values say A, B, C. But I would like to show only A in my vf page without removing B and C from picklist. Are there any ways to acheive this?

Thanks,
Wahid
Hello,
I'm trying to fire a workflow email for when new business opportunity goes from stage 1 to stage 2.
So the forumla should check to make sure the Oppty Type is not Add-On OR Professional Services.  If it's neither of those then it should see if the stage moved from 1 to 2.

I came up with this and it fired no errors, but my tests fail and nothing happens.

AND(NOT(OR( ISPICKVAL(Type, "Add-On"), (ISPICKVAL(Type, "Professional Services")))),( ISPICKVAL(StageName, "2-Align")) ,(PRIORVALUE(StageName)= '1-Prospect'))

Can anyone see where I'm going wrong?
Need tomerge the accounts and findout the duplicatea and eliminate them?
Hi,

I am looking at generating a 12 digit code code as autonumber for a text field.
Output : JOHN-2201-0025
{!LEFT( <object>.OwnerId , 4)} + '-' +day(today())+month(today())+ '-' + <autonumber>}

a. Let me know whether this is possible using triggers (before insert, before update>?
 
Hello,
Can someone help me with module Metadata API, unit Build Admin Tools for Automated Configuration Changes?

The error I'm getting is:
Line 12: Method does not exist or incorrect signature; void add(Metadata.CustomMetadataValue) from the type List

Below is my code:
public class MetadataExample {

    public void updateMetadata () {
        Metadata.CustomMetadata customMetadata = new Metadata.CustomMetadata();
        customMetadata.fullName = 'MyNamespace__MyMetadataTypeName.MyMetadataRecordName';
        
        Metadata.CustomMetadataValue customField = new Metadata.CustomMetadataValue();
        customField.field = 'customField__c';
        customField.value = 'New value';
        
        List <Metadata.CustomMetadata> mdtlist = new List<Metadata.CustomMetadata>();
        mdtlist.add(customField);  // Line 12
    }

}

I feel like I'm missing something very basic but I can't find any documentation specific to what I'm trying to do and the challenge is not similar (to me) to the example. Can someone please explain where I went wrong?
Hello,
Our company is trying to deploy Apex code for the first time from sandbox to production. I read in your docs that you need to have 75% coverage or above to deploy. When I run validation, it seems like a lot of test cases that we didn't write (I'm guessing they are Salesforce tests) are failing, and seem to have lower than 100% coverage. I am guessing this is also pulling our overall coverage down. Is there anyone who could point me in the right direction for how to get these tests cases to pass so that I could deploy?

Here's an example of a test failure in a class that is also not written by us:
Class: AttachmentsToFilesControllerTest
Method: migrationBatchRunStandardUser
Errors: NAMForbiddenException: You don't have permission to access these fields on ContentVersion. Ask your Salesforce admin for help.

Any ideas why so many of these built-in classes have such low coverage and seem to be failing?
I have attached a screenshot of the dev console after I run tests on sandbox:
Built in Salesforce test cases failing
HI Friends, 
I need test class for this apex class, Please do Help, 

public with sharing class LenderLoansController {
    public LenderLoansController() {
    }
    public LenderLoansController(ApexPages.StandardController controller) {

    }
Public String selectedTab {get; set;}
    Public Integer noOfRecords{get; set;}
    Public Integer size{get;set;}
    
    User U;
    
    public ApexPages.StandardSetController setCon {
        get{
            if(setCon == null){
                size = 25;
                U = [select id,Phone,name,Lender_ID__c from User WHERE ID =:userinfo.getUserId()]; 
                string queryString = 'Select Name, Customer_Name__c, Aadhaar__c, Mobile__c,Order_ID__c, Number_of_Installment__c from Loan__c order by Name';
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator([SELECT id,Name,Customer_Journey_Status__c,Current_Assigned_Lender__c , Number_of_Installment__c,Aadhaar__c, Mobile__c,Customer_Name__c,Order_ID__c from Loan__c Where Current_Assigned_Lender__c =:U.Lender_ID__c AND Customer_Journey_Status__c='Active']));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();
            }
            return setCon;
        }set;
    }
    
    Public List<Loan__c> getLoans(){
        List<Loan__c> accList = new List<Loan__c>();
        for(Loan__c a : (List<Loan__c>)setCon.getRecords())
            accList.add(a);
        return accList;
    }
    
    public pageReference refresh() {
        setCon = null;
        getLoans();
        setCon.setPageNumber(1);
        return null;
    }
}
 
  • January 03, 2018
  • Like
  • 0
We have created one Batchable class at our client org. For now we have no code in our batchable class but just select query. we are facing an Issue that last Apex JOB remains in “Holding” status until we Abort OR new JOB started i.e. As soon as new job started the previous scheduled JOB with “Holding” status get completed and new JOB get stuck in “Holding” . 

Any help will be greatly apprecaited.