• Gyanendra Singh 8
  • NEWBIE
  • 10 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 9
    Replies
Hi,

I have created a custom console component and the component is a visualforce page (as we can have either visualforce page or canvas app). When we click on the custom console component button it pops out the visualforce page (which is the normal behaviour). My problem is, I don't want this visualforce page to pop out. How can we disable it? When I click on the button nothing should happen. Please help

Below lines taken from Salesforce Apex Code Developer's guide:
'if you update or delete a record in its before trigger, or delete a record in its after trigger, you will receive a runtime
error.This includes both direct and indirect operations. For example, if you update account A, and the before update trigger
of account A inserts contact B, and the after insert trigger of contact B queries for account A and updates it using the DML
update statement or database method, then you are indirectly updating account A in its before trigger, and you will receive
a runtime error'


But I can update the Contact description in the before update trigger. Below is the code:

trigger triggerAllContextVariableCheck on Contact (before update, after update, before insert, after insert) {
    if(Trigger.isBefore){
     if(Trigger.isUpdate){
         for(Contact c: trigger.new){
             c.Description='Before Update'; 
         }}}
}

What I am missing? Above code is updating the Contact record in it's before trigger but the statement in the book says something else.

Please explain.

Ok we all know that 'Apex triggers are optimized to operate in bulk, which, by definition, requires developers to write logic that supports bulk operations' (Copied from salesforce) .

Now let's take a scenario, say I have a custom Object named MyCustomOb_c and I have written an after insert trigger on it which does something like field update etc. Now my question is what are the scenarios when the trigger would be invoked for bulk record processing ? I can think of one. If inserting say 20 records through data loader in the MyCustomOb_c.

What else?
If my organization has lets say 70 users and out of 70 let's assume 40 independent users inserts 40 records in this custom object (1 record per user) so does all the 40 records would be processed in one single trigger invocation? Or in other words the Size of the Trigger.New would be 40? If not then what else? I mean how it would be decided how many records would go in one single trigger invocation? Does the time interval in which these 40 records are inserted would matter?

Hope I am clear. I am just trying to figure out the scenarios and trying to figure out how many records at one go would go into the trigger and how it is decided?

Thanks in advance.

Below is a simple visualforce page which is self understood and the controller class:
VFPage----------

<apex:page controller="TestController1">
<apex:form >
<apex:pageBlock title="My Content" mode="edit">
<apex:pageBlockSection title="My Content Section" columns="2">
<apex:inputText value="{!acc}"/>            
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller Class------------------

public class TestController1 {
public String S1;
public String acc {
get;
set{
S1='Hello'; }
 } }

Now I want to know this. When I comment out the line  S1='Hello'  then my getter works and returns whatever text I enter in the inputText field. But when I don't comment out S1='Hello'  or basically if I write any other statement/expression APART from the expression which sets some value to the Property acc (like acc='Wassup'. And in this case the getter returns Wassup or whatever I set the value of acc) the getter method does not return anything. Why is this behaviour?
This is purely for learning purpose.

Thank you
Below is the code taken from Visualforce Developer's guide:

VF Page-----------
<apex:page controller="myController" tabStyle="Account">
<apex:form>
<apex:pageBlock title="Congratulations {!$User.FirstName}">
You belong to Account Name: <apex:inputField value="{!account.name}"/>
<apex:commandButton action="{!save}" value="save"/>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller class-----------------

public class MyController {
private final Account account;
public MyController() {
account = [SELECT Id, Name, Site FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Account getAccount() {
return account;
}
public PageReference save() {
update account;
return null;
}
}

My question is how is the Update happening here When the save button is clicked?
What I understand is, account points to the account record whose id is specified in the URL and then if I enter some account name on <apex:inputField value="{!account.name}"/> how is the account being getting updated as the account still continues to point to the Account record whose Id is in URL but then how does it takes up the account name from inputField?

 

Below lines taken from Salesforce Apex Code Developer's guide:
'if you update or delete a record in its before trigger, or delete a record in its after trigger, you will receive a runtime
error.This includes both direct and indirect operations. For example, if you update account A, and the before update trigger
of account A inserts contact B, and the after insert trigger of contact B queries for account A and updates it using the DML
update statement or database method, then you are indirectly updating account A in its before trigger, and you will receive
a runtime error'


But I can update the Contact description in the before update trigger. Below is the code:

trigger triggerAllContextVariableCheck on Contact (before update, after update, before insert, after insert) {
    if(Trigger.isBefore){
     if(Trigger.isUpdate){
         for(Contact c: trigger.new){
             c.Description='Before Update'; 
         }}}
}

What I am missing? Above code is updating the Contact record in it's before trigger but the statement in the book says something else.

Please explain.

Ok we all know that 'Apex triggers are optimized to operate in bulk, which, by definition, requires developers to write logic that supports bulk operations' (Copied from salesforce) .

Now let's take a scenario, say I have a custom Object named MyCustomOb_c and I have written an after insert trigger on it which does something like field update etc. Now my question is what are the scenarios when the trigger would be invoked for bulk record processing ? I can think of one. If inserting say 20 records through data loader in the MyCustomOb_c.

What else?
If my organization has lets say 70 users and out of 70 let's assume 40 independent users inserts 40 records in this custom object (1 record per user) so does all the 40 records would be processed in one single trigger invocation? Or in other words the Size of the Trigger.New would be 40? If not then what else? I mean how it would be decided how many records would go in one single trigger invocation? Does the time interval in which these 40 records are inserted would matter?

Hope I am clear. I am just trying to figure out the scenarios and trying to figure out how many records at one go would go into the trigger and how it is decided?

Thanks in advance.

Below is the code taken from Visualforce Developer's guide:

VF Page-----------
<apex:page controller="myController" tabStyle="Account">
<apex:form>
<apex:pageBlock title="Congratulations {!$User.FirstName}">
You belong to Account Name: <apex:inputField value="{!account.name}"/>
<apex:commandButton action="{!save}" value="save"/>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller class-----------------

public class MyController {
private final Account account;
public MyController() {
account = [SELECT Id, Name, Site FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Account getAccount() {
return account;
}
public PageReference save() {
update account;
return null;
}
}

My question is how is the Update happening here When the save button is clicked?
What I understand is, account points to the account record whose id is specified in the URL and then if I enter some account name on <apex:inputField value="{!account.name}"/> how is the account being getting updated as the account still continues to point to the Account record whose Id is in URL but then how does it takes up the account name from inputField?