• Britto Fernandez 2
  • NEWBIE
  • 14 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 25
    Replies
1
2
3
4
5
6
7
8
9
10
11
12
13
trigger Contactdel on Contact(before delete)
{
if(trigger.isbefore && trigger.isdelete)
{

for(Contact t: trigger.old)
{   

    if(UserInfo.getUserId() != t.ownerid){t.addError('Permission Denied, Please Contact the System Administrator');}}
    }
  

}

Have this above apex trigger so the users can delete the contacts that are only owned by them.
However an user is trying to Merge two contacts.
And he is getting an error message. "Permission Denied"
How do we adjust the code so this code bypass for certain users(System administrators).


Thank you!
I have created a custom object Student Master and whenever I am inserting a new record in Student Master, it has to check pan card number in another custom object "Black Listed Candidate" and if it is found then show  a warning message on the page that "PAN card is BlackListed" on Saving the record. This message needs to be shown in VisualForce page and then that page needs to be called in Custom object.
My VFP is getting called but message is not coming. Please help me for this.
I'm trying to create a process automation where a list of tasks is created when a project is created. Our project managers have a set list of tasks for their projects, and we want them to be able to create a project and automatically see the list of tasks they have to do, without putting in all the tasks manually for every project they have. We have about 35 tasks we want to put in, but when I do this on process builder it sends error messages about "too many SOQL queries." I talked to a Salesforce rep and they said I needed to get help from a developer about it, something about reducing the number of SOQL triggers fired. Is this something that can only be done by writing or modifying APEX code triggers (and if so, what specifically needs to be done - I don't know how to write APEX triggers) or is there something I can change in process builder to put in all the tasks we need and stop getting error messages?
how can I attain that if there is no task or specific task in will update a field in account, trigger should be account,
Hi, need help in creating report - 

I have one lookup relationship fields on the Contract object. One for lookup to Account, And now i have lookup to a Account called Custom object (employess)

I want to be able to report on Accounts, Account without Contract for Active employee (Status field on Employee object = Active)

Any idea how i can create this report.

All help appreciated.
  • June 11, 2019
  • Like
  • 0
I've been doing David Liu's excellent Apex Academy courses to try and get introduced to Apex coding. But he uses MavensMate as his editor, which has now been dropped.

Using the built in Salesforce Developer Console, I get tonnes of errors. I've gone through and doubled checked all my code and I am pretty confident it is correct.

So what is causing all of these errors???

Price Wars demo

and here is my code:

trigger LeadingCompetitor on Opportunity (before insert, before update) {
    
    for (Opportunity opp : Trigger.new) {
        // all of our prices in a list in order of competitor
        List<Decimal> competitorPrices = new List<Decimal>();
        competitorPrices.add(opp Competitor_1_Price__c);
        competitorPrices.add(opp Competitor_2_Price__c);
        competitorPrices.add(opp Competitor_3_Price__c);
        
        // add all of our competitors in a list in the same order
        List<String> competitors = List<String>();
        competitors.add(opp Competitor_1__c);
        competitors.add(opp Competitor_2__c);
        competitors.add(opp Competitor_3__c);
        
        //  loop through all the competitors to find the position of the lowest price
        Decimal lowestPrice;
        Integer lowestPricePosition;
        for (Interger i = 0; i < competitorPrices.size(); i++) {
            Decimal currentPrice = competitorPrices get(i);
            if (lowestPrice == null || currentPrice < lowestPrice) {
                lowestPrice = currentPrice;
                lowestPricePosition = i;
            }        
        }
        
        // populate the leading competitor field with the competitor matching the lowest price position
        opp Leading_Competitor__c = competitors.get(lowestPricePosition);
    }

}
Can anyone tell me how to add/include Standard New Contact Create link as button in salesforce lightning component?

i,e. When clicking a button on lightning component it should route to Standard Contact creation page.

Thanks in Advance.
  • May 30, 2019
  • Like
  • 0
Hello,

I have custom obj Order__c with some records and each records having some attachments.Order__c having field Order_No__c
For lightning cmp I have to show Order_No__c and It's related attachments like below table : 
Sr.No      Order No        AttachmentName
1              12xx               MyAttachment.jpg


Now,I need an help to write controller specially Query ?
We are using Shield Platform Encryption...
And we need to encrypt the content of some formula fields.(Formula fields can not be encrypted)
To solve it. It is necessary; Create a new field of some other type (Text / URL), and the functionality migrate it to a Workflow / ProcessBuilder / Trigger.
We cannot use Workflows because the "HYPERLINK" function does not exist there.
We did the test by creating a field type "TEXT" and a field type "URL" That are updated by a process builder.
User-added image

* The first problem is that it returns a concatenation of the url + the friendly text + additional words:   “_HL_ENCODED_www.example.com_HL_friendly Text_HL__blank_HL_Undo”
* For a field of type "TEXT" we cannot click on the hyperlink. (because it is plain text).
User-added image*For the URL field the full address is shown, you cannot put a friendly text. (besides the extra words that the process builder puts.)
User-added image

We need a solution to have a link but with a friendly text, without using formula fields or lighning compones / VFP.
Any ideas?
Is there any way to read data from excel or fetch data from excel and those records need to delete using apex .I know we can use data loader but for big objects dataloader is not possible so i am in need of doing it by fetching data from excel and delete using apex.

Any suggestion please
Hi Experts,
I have a VF page for creation of an address from account.I mean we have Address as a related list on Account and in that related list we have a Crete New button which when clicked will opens up a VF page where user can fill details and Save records.
Every thing is working fine till now except one condition where I stuck badly.
Requirement
We have 2 checkboxes on VF page called as "Primary" and "Mailing". An account can have more than 1 addresses but at one time only 1 address can have Primary checkbox as checked and only one address has Mailing as checked.Suppose an account has 4 addresses in which Address 1 has Primary checkbox checked,Address 2 and 3 doesn't have either of the two checkbox checked,Addreress 4 has Mailing checkbox selected.
Now I have a requirement when already an address exits with both Flags "Current Residence(API Name-Primary__c) and Mailing(API Name-Mailing__c)" checked and then user is trying to create another address and if select "Current Residence" checkbox then "Mailing" checkbox will be selected automatically.I achieved this through the logic written behind Save button.When user tries to create another address and select Current Residence checkbox and clicks on Save button then "Mailing" checkbox is getting saved automatically upon saving of record. But business doesn't need thi solution after hitting Save button.What they need is to check the "Mailing" checkbox automatically once user is trying to create another address and check the "Current Residence" and that account already has one address where both flags were checked automatically


Below is the part of the code from Controlller which I did intially behind Save button
global Address__c addr{get; set;} 
List<Address__c> addrList = [select id, Mailing__c, Primary__c, (select Type__c, Primary__c from Address_Types__r) from Address__c 
                                     where Account__c=:acc.Id and Primary__c = true
                                     order by LastModifiedDate desc limit 1];

if (!addrList.isEmpty()) {
            primaryAddress = addrList[0];
}
 public PageReference Save()
    {   

if(primaryAddress != null && addr.Primary__c==true && primaryAddress.Mailing__c==true){
             
            addr.Mailing__c=true;
        }
}

But due to business requiremet they dont need behind Save button rather they need onclick of the checkbox itself.

Below is the part from my VF page
 
<apex:page id="thePage" standardController="Account" extensions="VFC_NewAddress" standardStylesheets="true" >
<style>
        body .bPageBlock .pbBody .grey .pbSubheader{
            background-color:#FFDADA;
        }
        body .label{
            padding-left: 2px;
            font-size: 91%;
            font-weight: bold;
        } 
        body .btn{
        }  
    </style>

<apex:pageBlockButtons id="btnid">  
                <apex:commandButton action="{!save}" value="Save" id="doSave" styleClass="btn" onclick="return validate();"/>
                <apex:commandButton action="{!cancel}" value="Cancel" onclick="return handleConsole();"/>
</apex:pageBlockButtons>
 <apex:outputPanel styleClass="grey" layout="block" id="panelId">
              
 <apex:pageBlockSection title="Information" columns="1" id="pageBlockSecId">
<apex:pageBlockSectionItem id="item20" >
                        <apex:outputText value="Current Residence" ></apex:outputText>
                        <apex:inputField value="{!addr.Primary__c}" id="primary"/>
                    </apex:pageBlockSectionItem>
                    
                    <apex:pageBlockSectionItem id="item100">
                        <apex:outputText value="Mailing" ></apex:outputText>
                        <apex:inputField value="{!addr.Mailing__c}" id="mailing"/>
                    </apex:pageBlockSectionItem>
                    
                </apex:pageBlockSection> 
</apex:outputPanel>
            
        </apex:pageBlock>
        
    </apex:form>
</apex:page>

Below is the sample screenshot
User-added imageOnce user selects Current Residence checkbox then Primary checkbox will be automatically selected without hitting Save button.Also this needs to be happen only when the account has such an address where both flag are on same address.Obviously because at any time only one address can have Current Residenec as checked or Primary as checked or may have both checked.

So as a business user the requirement should look like below
GIVEN user in Salesforce updated existing address to be the new Current Residence
WHEN user selects the Current Resident flag on existing address
AND account has an address where both Current Residenece and Mailing are checked
THEN the system automatically ticks the Mailing flag when Current Residence flag is selected on new address
    AND system does NOT allow Mailing to be unchecked
    AND if user tries they see message displayed on screen: 
'One active address must always be marked as Mailing.  Kindly select a different address to be Mailing or if customer has withdrawn consent please update their consent page.’

I didnt paste complete VF page and controller only those seems to be relevant as per my question.So I posted only relevant part from my code.

I hope I have provided detailed infor regarding my issue and somebody will definitely help me

Kindly help me

Many thanks in advance

Thanks & Regards,
Maria
I am somewhat new to this to this area of salesforce so please be patient.

I want to create a table using visual force that can be accessed from a button residing Travel__c

I want the following fields in the table that are either directly or indirectly related to that specific Travel__c

Field 1 is from Tour__Interests__r (which is a child of master/detail with Travel__c)  Contact__c which is a (lookup to the contact) First Name and then Last Name

Field 2 would take the same path as above and then pick up a related list to the contact called Recognitions__c and the fields I want from there are Amount, Date, Name
And if there are no Recognitions either that Tour Interest Record can be skipped or the recognition fields can be null

I have tried multiple ways to get the related list fields but cannot get there. I believe I need to build a custom controller as the error seems to be it does not recognize any of the Travel Interests fields.

Help


 
Hi everypone,

Please help me on fixing this error in my test class

@isTest
private class ItemizedReceiptTest {
    static testMethod void testMethodPostive(){
        Product2 prod = new Product2(
            Name = 'Test',
            IsActive = true
        );
       
        insert prod;
       
        Account acc = new Account(Name ='Test');
        insert acc;
       
       
        //Create your product
        Opportunity testOpp = new Opportunity();
        testOpp.Name='Test Opportunity' ;
        testOpp.AccountId=acc.id;
        testOpp.StageName='Order Placed';
        testOpp.CloseDate= Date.newInstance(2019,03,28);
        insert testOpp;
       
        Id pricebookId = Test.getStandardPricebookId();
       
       
        //Create your pricebook entry
        PricebookEntry pbEntry = new PricebookEntry(
            Pricebook2Id = pricebookId,
            Product2Id = prod.Id,
            UnitPrice = 100.00,
            IsActive = true
           
        );
        insert pbEntry;
        //create your opportunity line item.  This assumes you already have an opportunity created, called opp
        OpportunityLineItem oli = new OpportunityLineItem(
            OpportunityId = testOpp.Id,
            Quantity = 5,
            PricebookEntryId = pbEntry.Id,
            TotalPrice = pbEntry.UnitPrice
        );
        insert oli;

        PageReference pageRef = Page.ItemizedReceipt;
        Test.setCurrentPage(pageRef);
        system.debug('Products'+prod);
           system.debug('acc'+acc);
         system.debug('testOpp'+testOpp);
         system.debug('pbEntry'+pbEntry);
         system.debug('oli'+oli);
        ApexPages.StandardController sc = new ApexPages.StandardController(testOpp);
        ItemizedReceipt obj = new ItemizedReceipt(sc);
        obj.total();

 }
   
   
}


class:


public with sharing class ItemizedReceipt {
    public List<OpportunityLineItem> oppLst          { set; get; } //List of Products in a Opportunity
    public Double                    totalPrice_cal  { set; get; } //Variable to calculate Total Price of all the products
    public Double                    totalGST_cal    { set; get; } //Variable to calculate GST of all the products
    public Double                    totalPST_cal    { set; get; } //Variable to calculate PST of all the products
    public Double                    totalAmt_cal    { set; get; } //Variable to calculate Total Amount of all the products
    public DateTime                  getCloseDate    { set; get; } //Variable to get the Created Date
    public String                    dayOfWeek       { set; get; } //Variable to store the Day from the Created Date
    public String                    accName         { set; get; } //Variable to store the Customer Name
    public  ItemizedReceipt(ApexPages.StandardController controller) {
        if ( controller.getId() != null ) {
            oppLst = [SELECT Product2.Name, Opportunity.Id, Opportunity.CloseDate, TotalPrice, GST__c, PST__c,
                             Total_w_Tax__c, Opportunity.Account.Name
                      FROM   OpportunityLineItem
                      WHERE  Opportunity.Id=:controller.getId()
                     ];
            getCloseDate = oppLst[0].Opportunity.CloseDate;
            dayOfWeek = getCloseDate.format('EEEE');
            accName = (string)oppLst[0].Opportunity.Account.Name;
            totalPrice_cal = 0.0;
            totalGST_cal = 0.0;
            totalPST_cal = 0.0;
            totalAmt_cal = 0.0;
            total();
        }
    }  
    //Method calculates all the totals
    public  void total() {
        for ( integer i = 0; i < oppLst.size(); i++ ) {
            totalPrice_cal += oppLst[i].TotalPrice;
            totalGST_cal   += oppLst[i].GST__c;
            totalPST_cal   += oppLst[i].PST__c;
            totalAmt_cal   += oppLst[i].Total_w_Tax__c;
        }
    }
}

Thank You
Hi, I am trying to create a trigger for my client.T his is what I amtrting to do
  • There is a lead path, having deposit field (checkbox), once the check box is clicked and path updated, I want to send an email to the client with "attached forms" asking them to fill it to go further on process. By now this is teh code I was able to create:
  • Working class for EMailManager ---

    public with sharing class EmailManager
    {
        public static void sendMail(String address, String subject, String body)
            {
                Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                String[] toAddresses = new String[] {address};
                    
                mail.setToAddresses(toAddresses);
                mail.setPlainTextBody (body);
                mail.setSubject(Subject);
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail});       
            }
            
    }Problem is: 1. How can I get particular field from the path on the lead object?
  • 2. how to send email to client who paid the deposit and whose field got udated?
  • Please help, I am new to trigggers and really struggling to find the solution.
Thank you.