• Ariel Gorfinkel
  • NEWBIE
  • 74 Points
  • Member since 2015
  • Salesforce Developer
  • Novidea Software

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 23
    Replies
trigger NoteOnContentversion on ContentVersion (before insert, before update) {
	for (ContentVersion c : Trigger.new)  {
        
            for (ContentDocumentLink link : [
                SELECT LinkedEntityId 
                FROM ContentDocumentLink
                WHERE ContentDocumentId = :c.ContentDocumentId
            ]){
                Id parentId = link.LinkedEntityId;
                System.debug('link.LinkedEntityId '+ link);
                
                Boolean isOrderRegel = parentId.getSObjectType() == Orderregel__c.SObjectType;
                
                if (isOrderRegel && Approval.isLocked(parentId)){
                  c.addError('Approval pending. You do not have the permission to edit this note, Please contact your administrator.');
                }
            }
        
    }
}
 
@IsTest
private class NoteOnContentversion {
	
    @IsTest static void refuse_shouldAddError_whenOrderregelIsLocked() {
        // arrange
        Account a = new Account(
        	Name = '123', 
            Account_Status_DS__c = 'Strategic'
        );
        insert a;
        
        Orderregel__c orderregel = new Orderregel__c(
            Account__c = a.Id,
            Orderbegindatum__c = Date.today()
        );
        
        insert orderregel;
        Approval.lock(orderregel);
        
        ContentVersion n = new ContentVersion();
       
        insert n;
        
        ContentDocumentLink cl  = new ContentDocumentLink();
        
        insert cl;
               
        // act
        DmlException caughtException;
        try {
            insert cl;
        	insert n;
        } catch(DmlException e) {
            caughtException = e;
        }
        
        // assert
        System.assertNotEquals(null, caughtException);
    }   
}

 
Hi Team,
 
We have one requirement like we have 5 conditions. Any one condition is met then check box should be update. For that i have written one trigger on opportunity using before event
 
The problem is: In scorecard object when matching any criteria then in the opportunity "Deal” should be true. Which is working fine my question is after matching any criteria in scorecard object in the opportunity need to updated deal = check when refreshing the opty page. Here we are updating the field every time which is not correct
Can anyone please help me on this?
Thanks
 
Hi,

I was recently asked to create three large formula fields in a custom object we call Loan App.

They would calculate a high value, medium value and low value based on several different variables and would only one of the fields would be populated at any given time.  All the formulas work fine but i have now been asked if i can get the value returned to show in a separate field for reporting. The combined character value is about 9k so there is no way i am able to use a formula field to return a value. 

I have read that triggers can be used to update fields but have only found examples where they are reading one value from another field and not multiples.

If i was going to write it in a formula i would do this:
IF(AND(Payment_Terms__c >=1,Loancalclow__C<> null) , loancalclow__C,
IF(AND(Payment_Terms__c >=1,Loancalclmed__C<> null) , loancalcmed__C,
IF(AND(Payment_Terms__c >=1,Loancalclhigh__C<> null) , loancalchigh__C,
0),0),0)

Can anyone help?

Thanks in advance
trigger NoteOnContentversion on ContentVersion (before insert, before update) {
	for (ContentVersion c : Trigger.new)  {
        
            for (ContentDocumentLink link : [
                SELECT LinkedEntityId 
                FROM ContentDocumentLink
                WHERE ContentDocumentId = :c.ContentDocumentId
            ]){
                Id parentId = link.LinkedEntityId;
                System.debug('link.LinkedEntityId '+ link);
                
                Boolean isOrderRegel = parentId.getSObjectType() == Orderregel__c.SObjectType;
                
                if (isOrderRegel && Approval.isLocked(parentId)){
                  c.addError('Approval pending. You do not have the permission to edit this note, Please contact your administrator.');
                }
            }
        
    }
}
 
@IsTest
private class NoteOnContentversion {
	
    @IsTest static void refuse_shouldAddError_whenOrderregelIsLocked() {
        // arrange
        Account a = new Account(
        	Name = '123', 
            Account_Status_DS__c = 'Strategic'
        );
        insert a;
        
        Orderregel__c orderregel = new Orderregel__c(
            Account__c = a.Id,
            Orderbegindatum__c = Date.today()
        );
        
        insert orderregel;
        Approval.lock(orderregel);
        
        ContentVersion n = new ContentVersion();
       
        insert n;
        
        ContentDocumentLink cl  = new ContentDocumentLink();
        
        insert cl;
               
        // act
        DmlException caughtException;
        try {
            insert cl;
        	insert n;
        } catch(DmlException e) {
            caughtException = e;
        }
        
        // assert
        System.assertNotEquals(null, caughtException);
    }   
}

 
Hello,

We have an issue where if we are logged into two different sandboxes within the same browser, when you log into the second sandbox as soon as you navigate or refresh in the previous browser tabs that were logged into the first sandbox they will switch to the second sandbox?
Hopefully that makes sense, so basically you can only be logged into one sandbox within the browser.

This is the same if using IE or Chrome.

However, we have two orgs and I have noticed that one of the orgs does NOT behave like this. So the question is how is this working differently, is there a setting that can be configured for this beahviour within the org?

Many thanks

 
Hi Guys,

Have exposed account object's 3 fields to a custom object with the help of lookup relationship of account with the custom object. I just want to ensure any changes for these 3 fields in the Account object should not overwrite the values initial values in custom object when the record created for the first time.

How can we achieve this?
I have a visualforce page and I want to show all the lead record and also its count on this VF page.

For the records I have used pagination and offset to retrieve the records and shown on the page.

But the problem is that I cannot show the total no of leads on this VF page as the records are 5000+.  It thorws an error as
TOO may rows 5001.
Hi All,

I am trying to Programmatically delete Sharing Rules with Apex. I am  getting the following exception cannot delete owner or rule share rows. Below is my code:

public static void RestrictShare(List<Account> slist){
      List<ID> shareIdsToDelete = new List<ID>();
      
      for (Approval_Stage__c stage:slist) {
      if (stage.Share__c == false) {

            shareIdsToDelete.add(stage.id);
      }
    }
    if (!shareIdsToDelete.isEmpty()){
      delete [select id from AccountShare where AccountShare.Id IN :shareIdsToDelete];
      }
  }

I am calling it in a after update trigger
I'm trying to set up an email-to-lead email service where the information for the lead is in the content of the email iteself.
The leads always come from the same email to my Outlook email.  The email contains the information for the lead in its content.  I have set up an apex class, and an email service within Salesforce, and have activated the email service.  I set up a rule within outlook to automatically redirect emails to the salesforce email given in the email service. 
No new leads are bein created at all, however.  I can't figure out why.  Are there logs of some kind I could check?  In the email service I have Email Error Routing enabled, and have it set so that it sends errors to my email, but I haven't received any error emails from salesforce (although I have been having issues with receiving emails from salesforce ip's, so they might actually be getting sent).  Here is my Apex class:

global class NmsEmailToLead implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,

                                                       Messaging.InboundEnvelope env){


    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
     

    String[] emailBody = email.plainTextBody.split('\n', 0);

    String firstName = emailBody[1].substring(10);
    
    String lastName = emailBody[2].substring(10);

    String address = emailBody[3].substring(8);

    String state = emailBody[4].substring(5);

    String zipcode = emailBody[5].substring(7);

    String city = emailBody[6].substring(4);

    String leadEmail = emailBody[7].substring(12);

    String phone = emailBody[8].substring(8);

    String paymentsBehind = emailBody[11].substring(15);

    String loanAmount = emailBody[13].substring(11);

    String estimatedHomeValue = emailBody[14].substring(21);

    String creditLevel = emailBody[17].substring(12);

    String interestRate = emailBody[20].substring(14);


    Lead[] newLead = new Lead[0];

     try {
        Map<String, Schema.SObjectType> sObjectMap = Schema.getGlobalDescribe() ;
        Schema.SObjectType s = sObjectMap.get('Lead') ;
        Schema.DescribeSObjectResult resSchema = s.getDescribe() ;
        Map<String,Schema.RecordTypeInfo> recordTypeInfo = resSchema.getRecordTypeInfosByName();
        Id rtId = recordTypeInfo.get('Housing Counseling').getRecordTypeId();

       newLead.add(new Lead(RecordTypeId = rtId,
       FirstName=firstName,LastName=lastName,Phone = phone,Email = leadEmail,
       Street = address,State = state,City = city,PostalCode = zipcode,
       Payments_Behind__c = decimal.valueof(paymentsBehind),Total_Amount__c = decimal.valueof(loanAmount),
       Estimated_Home_Value__c = decimal.valueof(estimatedHomeValue),
       Credit_Level__c = creditLevel,Interest_Rate__c = decimal.valueof(interestRate)));

       insert newLead;       
    }
     
   catch (QueryException e) {
        
   }
    

   result.success = true;

   return result;

  }

}

Any help with understanding what I am doing wrong here would be greatly appreciated, thanks!

I have requirement, which is as follows..

When a user selects a particular Agent Id , all the details of that particular Agent Id should get populated on the visual force page.... I am not able to capture the selected picklist value and pass it to the Apex Controller ... Please help me..

Please guide as to where am I going wrong...

 

Class

 

public class AgentandOrderController{
Agent__c Agent;
string searchText;
List<Agent__c> result;
Integer selected;
Integer AgentId;

public String getAgent() {
        return null;
    }

 public List<Agent__c> getresult() {
      return result;
   }

public Integer getAgentId() {
return selected;
}

public void  setAgentId(Integer val) {
selected=val;
 }
 
public List<SelectOption> getItems() {
     List<SelectOption> options = new List<SelectOption>();
     options.add(new selectOption('001', '001'));
     options.add(new selectOption('002', '002'));
     options.add(new selectOption('003', '003'));
     options.add(new selectOption('004', '004'));
    
     return options;
}

public PageReference search() {
result=[select Agent_Address__c from Agent__c where Name=: ApexPages.currentPage().getParameters().get('options')];
System.debug('options : '+options);
return null;
}

}

 

 

 

Page

 

<apex:page controller="AgentandOrderController" >
 <apex:form >
<b>Agent Information</b>
  <apex:pageblock >
   <apex:pageBlockSection id="section1">
    <apex:pageBlockSectionItem >
     <apex:panelGrid columns="2">
     <apex:actionRegion >     
     <apex:outputLabel value="Agent Id" for="agentId"/>
      <apex:selectList value="{!agentId}" multiselect="false" size="1" onchange="search()" >
      <apex:selectOptions value="{!items}" />
      </apex:selectList>
     </apex:actionRegion>        
</apex:panelGrid>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageblock>

<b>Order Information</b>
<apex:pageBlock >
<apex:pageBlockSection id="section2">
<apex:pageBlockSectionItem >
<apex:panelGrid columns="2">
</apex:panelGrid>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

Thank You

  • April 05, 2012
  • Like
  • 0