• sakhi
  • 99 Points
  • Member since 2010

  • Chatter
  • 3
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
  • 42
Hi All,
Please help me to write a test class for the below apex trigger.
Thanks in advance.
here is the code 

trigger PreventFileConDoc on ContentDocument (before delete) {
   // for(ContentDocumentLink conl : trigger.old){
   //     conl.adderror('ContentDocumentLink Cannot be deleted');
   // }
      Id profileId = userinfo.getProfileId();
    String profileName = [Select Id,name from Profile where Id =: profileId].Name;
   if(Trigger.isBefore && Trigger.isDelete){
        Map<Id, ContentDocument> mapContentDocument = new Map<Id, ContentDocument>([Select Id from ContentDocument where Id in: trigger.oldMap.keyset()]);
        for(ContentDocument cd : Trigger.Old){
             if (profileName != 'System Administrator') {
                cd.adderror('ContentDocument Cannot be deleted');
                system.debug('testing inside loop'+cd);


Thank you,
public class MyAccount {
    public String name {set;get;}
    public String phone {set;get;}
    public String rating {set;get;}
    public void create(){
        Account acc=new Account();
  10)       insert acc;

Hi All,


I am new to salesforce. I have a requirement to send some data from visual force page to external Jsp securely.

We have tried encryption using crypto class with following test code ..


public class ProceedForpin{
// Use generateAesKey to generate the private key     
Blob cryptoKey = Crypto.generateAesKey(256);
// Generate the data to be encrypted.  
//Blob data = Blob.valueOf(testit);    
 Blob data = Blob.valueOf('test data to encrypt');
// Encrypt the data and have Salesforce.com generate the initialization vector   
 Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data);    

//method invoked from command button in my vsp.

    public PageReference redirect() {
   string  res= EncodingUtil.base64Encode(data);
    PageReference Iform = new PageReference('https://sites.google.com/site/testeformstest/'+'?ABC='+res); 
    return Iform ;



above code is passing encrypted value of test data in URL as highlighted.

We need to pass it to another page (jsp) without making them visible in url string as it is secure data.


I think we need to pass it using hidden parameters but there I am facing issues for maintaining session between pages .

Or I think We need to use http post method, But, in this I think it is more used when web services are in picture which we do not require here.


May be I am wrong ,Please help me in correct direction and approach..


Any help with examples is much appreciated.


Thanks in advance ...

  • May 17, 2011
  • Like
  • 0
Hi , I have a requirement to design and implement login,forget password and reset password functionality of salesforce. I have 3 standalone visual force pages for the same using same controller. I am able to implement login and forget password sucessfully but facing problem in reset password due to unexpected error bugging me . From forget password page I get system generated password via email. Using that password when user tries to login from login page ,user is redirected to my reset password page. There password changes as When I login from login page from newly changed password It goes fine , But My problem is In reset password page always when i hit save error pops up saying Error:Old password is invalid. Please find my code below and help me where I went wrong . /***********changepassword method to be called on click of save button of reset password page************/ global PageReference changePassword(){ return Site.changePassword(newpassword, verifypassword, Oldpassword); } /************** method to be called on click of submit from the forgot password page**************/ global Boolean forgotPassword(){ return Site.forgotPassword(useridlabel); } global PageReference login() { String startUrl = System.currentPageReference().getParameters().get('​startURL'); if (startUrl == null){ startUrl = '/home/home.jsp'; } system.debug('*****username and Password****'+ username+'****'+password); system.debug('****starturl is ***' + startUrl); system.debug('Site.login' + Site.login(username, password, startUrl)); return Site.login(username, password, startUrl); } Please help me out on this.....
  • December 21, 2010
  • Like
  • 0
Hello, I have a multo section task component. I added a checkbox to mark thhe tasks as completed when checkbox is clicked. Could you tell me where my error is and how to make the component working:

<aura:component controller="TaskController" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="recordId" type="Id" />    
    <aura:attribute name="tasks" type="Task[]"/>
    <aura:handler name="init" action="{!c.doInit}" value="{!this}"/>    
    <aura:attribute name="mycolumns" type="List"/>
    <aura:attribute name="doSelect" type="List"/>
    <lightning:card iconName="standard:task" title="Aufgaben">
        <div class="slds-card__body slds-card__body_inner">
             <div style="padding-left: 62%; margin-top: -2rem;">
            <lightning:button label="Aufgaben Anzeigen" onclick="{! c.openTask}"/>
  <div style= "font-size: 15px; font-weight: bold; margin-left:15px; margin-top:10px;">

            <aura:if isTrue="{!not(empty(v.tasks))}">
                <lightning:datatable data="{!v.tasks }" 
                         columns="{!v.mycolumns }" 
                         onrowselection="{! c.doSelect}" 
                <aura:set attribute="else">
                    <div Style="text-align : center"> Keine Aufgaben</div>



    doInit: function(component, event, helper) {
       component.set('v.mycolumns', [
            {label: 'Thema', fieldName: 'SubjectName', type: 'url',
            typeAttributes: {label: { fieldName: 'Subject' }, target: '_blank'}},
                {label: 'Status', fieldName: 'Status', type: 'picklist', fixedWidth: 160 },
        var action = component.get("c.loadTasks");
            action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                var records =response.getReturnValue();
                    record.SubjectName = '/'+record.Id;
                    record.ActivityDate= record.ActivityDate;
                component.set("v.tasks", records);
    openTask: function(component, event, helper) {
          doSelect : function(component, event, helper) {
        var selectedRows = event.getParam('selectedRows'); 
        var ids = [];
        for ( var i = 0; i < selectedRows.length; i++ ) {

        var action = cmp.get("c.loadTasks");
            recordId : ids,

Apex Conroller:

public with sharing class TaskController {
//ÜBERFÄLLIG - Abfrage Tasks, wo das Activity Date abgelaufen und der Status "Not Completed" ist//
    public static List<Task> loadTasks(List<Id> recordId){
    string userId = UserInfo.getUserId();
    List<Task>  taskObj=[select id, Subject, ActivityDate, Status from task where id IN:recordId];
    for(Task tsk : taskObj){
    if(taskObj.size() > 0)
    update taskObj;
    return[SELECT Subject, ActivityDate, Status  FROM Task WHERE ActivityDate< TODAY AND OwnerId=:userId AND Status !='Completed'];
Hello, I build a trigger on ContentVersion that should block deletation of FILES when they have "Geschäftsbrief" in "Dokumentenklasse" - picklist. Sadly the error does not occure when I delete a file with this field :(
Please correct my code:
trigger ContentVersionTrigger on ContentVersion (before delete) {
    set<Id> contentId = new set<Id>();
        for(ContentVersion con : Trigger.old){
                List<Attachment> at=[select name,body,contentType from Attachment where parentid in: contentId];
 for(ContentVersion con : Trigger.old){
 if(con.Dokumentenklasse__c =='Geschäftsbrief'){
                       con.addError('You cant delete the file');
We have a standard plan in Salesforce for enterprise edition so Can we upgrade to Premier Success plans and is that included into our licenses or do we need to pay any extra cost.
Please let me know.
Thank you
may i know why picklist field name in opportunity is not display in field update workflow action
Hi Folks,

Please help me out below trigger

After creating opportunity then on Contract  for Product Group is not getting populated  when contract has been created in salesforce.

Product_Group__c picklist values are below 
Chrome - CFM License
Google Cloud Identity
ISV - AODocs
In my report, I have Average response time for last 24 hours and last 7 days. Is there any way to trigger subscription for report only if Avg(last 24 hours) > Avg(Last 7 days) ?
Hello forum,
I want to know when to use Apex:ActionFunction .
we call  the controller method from javascript function using ActionFunction . I read this line in many blogs but why i call  controller method from javascript function, when actually i need it .
can any one explain me thank you in advance.
Hi everyone , I have written a trigger so for for submitting a record for approval.i need to set the trigger to approval automatically please help me out.

trigger contactcreated on Contact (after insert) {
    for(contact c : trigger.new){
        if(c.isprimary__c == True){
            // create the new approval request to submit
            Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
            req.setComments('Submitted for approval. Please approve.');
            // submit the approval request for processing
            Approval.ProcessResult result = Approval.process(req);
            // display if the reqeust was successful
            System.debug('Submitted for approval successfully: '+result.isSuccess());
trigger Contactcreatedapprocess on Contact (after insert) {
     user u1=[select id from user where alias='anshu'];
    for(contact c:Trigger.new){
        //step1:create a approval req to submit
       Approval.ProcessSubmitRequest req=new Approval.ProcessSubmitRequest();
        req.setComments('submitted for approval please submit');
       //submit the request for approval
      Approval.ProcessResult result=Approval.process(req);

Thanks in Advance


I am trying to create account record in Rest Explorer but getting "Method not allowed" error. Anyone faced this issue earlier?

Mahesh Kumar Raikal..

Hi All,

I am trying to run this code:
public class PassBy {

    public void mainValue() {
        String url = 'www.one.com';
        System.debug('Before Value Call : '+ url );
        System.debug('After Value Call : '+ url );
    private void passByValue(String NewUrl)(){
        NewUrl = 'www.two.com';
        System.debug('Inside change'+NewUrl);


PassBy p = new PassBy();


Getting below error:
Method does not exist or incorrect signature: void mainValue() from the type PassBy
I want to practise writing apex class, please can anyone provide a link where i can get different scenarios for writing apex classes

Hello Guys, 

Under the user object, we have a field named "PrimaryTerritory__c". We need to populate this field with Territory Name/Names assigned to user. Scenario is the following. 

Parent Objects: "User", "Territory2"
Child Object:  "UserTerritory2Association"

"UserTerritory2Association" has 2 lookup fields, one to User, second to Territory. Actually this object is playing "Junction" object role but for lookup relationship. Whenewer territory is assigned to user, "UserTerritory2Association" is created automatically and stores the information about this particular assoctiation between User and Territory2. (This is standard SF feature and no Process or Flow supported)

I need to take Territory2.Name field from Territory2 Object and store to User object using "UserTerritory2Association" object. For our business scenario, we need Batch or Trigger.  I have a Batch template which actually does not work because of not proper setup of Lists sets maps and for loops. I need some help on proper setup these. Please recommend if you had something similar?  

global class Alcon_PrimaryUserTerritoryFillout implements Database.Batchable <sObject> {
     global Database.QueryLocator start(Database.BatchableContext bc) {
        return Database.getQueryLocator([select id, User.PrimaryTerritory__c, RoleInTerritory2, Territory2.Name from UserTerritory2Association where User.Primary_Territory_vod__c = null AND RoleInTerritory2 ='1 - Primary']);
    global void execute(Database.BatchableContext bc, List<UserTerritory2Association> scope){
      for(UserTerritory2Association UserTerAssoc: scope){
             UserTerAssoc.User.Primary_Territory_vod__c = UserTerAssoc.Territory2.Name; 
        update scope;
     global void finish(Database.BatchableContext bc){


Field 'A' & 'B' are the fields of object 'ABC'.
I have an issue that on the change of field 'A', field 'B' changes. Whereas on change of field 'B', field 'A' changes. The execution is going in a loop. How to resolve the issue using flow builder?
Hi Developers,

I have created a batch and there is many method besides of start, execute and finish. 
Now I want to check CPU time used for each method in the batch class. I mean I want to see how much CPU time consumes a every  method in batch.

Thanks & Regards
Jitendra Singh
Hi Guys,

I have a map, map<id, List<customObject>>.
How to get a specifc custom field of the custom object from the map?
Hello, my client wants to bypass the hierarchy's roles in the global salesforce search (an agent can just see informations of opportunities and accounts created by his manager). Do you have any idea how to do it? Thank you in advance.
I have not done this in ongoing project, hence i m looking for some advice.

IF a client already using contact object and has 10-20-50 K records with validation rule, trigger, process builder , flow , workflow etc build on contact objects 

then decides to use person account and enables it 

QUESTION : DO we have to re build ( validation rule, trigger, process builder , flow , workflow etc ) on person account / account with person record type and re configure all automation ( validation rule, trigger, process builder , flow , workflow etc) and objects looking up to contact Objects in ERD ?

I m getting the data migration part . but needs some advice on Metadata part .  any advice/ document would be appreciated
I'm a web developer wekomic.com (https://wekomic.com/) and i'm curious about trying SalesForce. The thing is, i dont know quite where to start. Can i go and star coding.. should i study the whole salesforce software first? Maybe you could shed some light.
Thank you!