• Vikram Singh 157
  • NEWBIE
  • 130 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 18
    Questions
  • 18
    Replies
when we click on prospect and click on save it will display only prospect account records and same for customer direct. Can we achive it by statndard controller ?
My code is :
<apex:page controller="Test2Class" >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!showList}" id="accountId" var="a1">
            <apex:column headerValue="Account Name" value="{!a1.Name}"/>
            <apex:column headerValue="Account Type" value="{!a1.Type}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>
Custom controller class:-
public class Test2Class{

 public list<account> showList = new list<account>([select Id, Name, Type from Account where type='Prospect' and 'customer direct']);
    Public list<account> getshowList(){
        
        return showList;
    }
}
 
<apex:page standardController="Contact" recordSetVar="contacts">
   <apex:form >
    <apex:pageBlock title="Contacts List" id="contacts_list">
        
        Filter: 
<apex:selectList value="{! filterId }" size="1">
    <apex:selectOptions value="{!listViewOptions }"/>
    <apex:actionSupport event="onchange" reRender="contacts_list"/>
</apex:selectList>
        <apex:pageBlockTable value="{! contacts }" var="ct">
            <!-- Pagination -->
            <table style="width: 100%"><tr>

                <td>
                Page: <apex:outputText value=" {!PageNumber} of {!CEILING(ResultSize/PageSize)}"/>
    </td>            

    <td align="center">
<apex:commandLink action="{! Previous }" value="« Previous"
     rendered="{!HasPrevious }"/>
<apex:outputText style="color: #ccc;" value="« Previous"
     rendered="{! NOT(HasPrevious) }"/>

&nbsp;&nbsp;  
<apex:commandLink action="{! Next }" value="Next »"
     rendered="{!HasNext }"/>
<apex:outputText style="color: #ccc;" value="Next »"
     rendered="{!NOT(HasNext) }"/>    </td>
    
    <td align="right">
Records per page:
<apex:selectList value="{!PageSize }" size="1">
    <apex:selectOption itemValue="5" itemLabel="5"/>
    <apex:selectOption itemValue="20" itemLabel="20"/>
    <apex:actionSupport event="onchange" reRender="contacts_list"/>
</apex:selectList>    </td>

</tr></table>
            <apex:column value="{! ct.FirstName }"/>
            <apex:column value="{! ct.LastName }"/>
            <apex:column value="{! ct.Email }"/>
            <apex:column value="{! ct.Account.Name }"/>
        </apex:pageBlockTable>
        
    </apex:pageBlock>
        </apex:form>
</apex:page>
trigger Ass_cts on Contact (after insert, after undelete) {

set<id> acid = new set<id>();

if (trigger.isinsert||trigger.isundelete){

for (contact opp : trigger.new){

acid.add(opp.accountid);
}
   list<account> acc = [select id, Number_of_contacts__c from account where id in : acid];
   list<contact> con = [select id from contact where accountid in :acid];
   
   for(account a : acc){
   
   a.Number_of_contacts__c = con.size();
      }
     Update acc;
    }
    }
as we know the reords we are going to insert in test class are dummy records and not gonna to insert in our org , but is it required to test on actual  
records while writing test class.
 I am just practice the use of future method and callout but the below code is'nt working 
 
global class MyFutureClass {  
 @future   
   public static void myMethod() {  
     EmailClass.SendEmailNotification();  
       
   }  
 }  

              global class EmailClass{  
              WebService static void SendEmailNotification() {  
               
       SingleEmailMessage mail = new Messaging.SingleEmailMessage();    
         mail.setToAddresses(new string[] {'vikramsinghvs099@gmail.com'});  
        mail.setSenderDisplayName('SFDC.com ');  
          mail.setSubject('A new Hope'');  
          mail.setHtmlBody('GoT It ?');  
     Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );  
   }  
 }  
Req :Create the field called “Contact Relationship” checkbox on the Contact Object and create the object called “Contact Relationship” which is related list to the Contacts. (Look Up Relationship).
Now logic is when we create contact by checking contact relationship checkbox, then Contact Relationship will be created automatically for that contact.

Trigger :
trigger CreateChild on Contact (after insert) {
        set<id> conid = new set<id>();
        list<Contact_Relationship__c> con1 = new list<Contact_Relationship__c>();
        for (contact c : trigger.new){
        conid.add(c.id);
}
        List<contact> conlist = [select id,name from contact where id in : conid];
        for (contact c : conlist){
        if(c.Contact_Relationship__c == true){
        Contact_Relationship__c cr = new Contact_Relationship__c();
        cr.name = c.lastname;
        cr.contact__c= c.id;
        con1.add(cr);
}
}
        insert con1;
}
This will work fine but unable to add opp by name 1, 2, 3, 4...

trigger CreateRelatedRec on Account (after insert, after update) {
           List<Opportunity> opplist = new List<Opportunity>();
            List<Account> Acc = [Select ID , Name from Account where Id in : trigger.new AND Id NOT  in
             (select accountid from Opportunity)];
             
            for(account a : Acc){
            
 opplist.add(New Opportunity(Name=a.Name +'opportunity',StageName='Prospecting',
 CloseDate=Date.today()+30,AccountId=a.Id));
        
         }
            If(oppList.Size()>0){
                upsert opplist;
            }
                }
trigger CopyBillingAddtoShpAdd on Account (before insert, before update) {
    for( Account ACC : trigger.new){
    if(Check_Billing_as_Shipping__c == True){
               ACC.BillingStreet          = ACC.ShippingStreet;    
               ACC.BillingCity            = ACC.ShippingCity;  
               ACC.BillingZip/Postal Code = ACC.ShippingZip/Postal Code;    
               ACC.BillingCountry         = ACC.ShippingCountry;    
}
}
}
Here Account custom filed id Probhited__c and code is :
trigger ProhibitedOpp1 on Opportunity (before insert) {
   List<Opportunity> opps = [Select Id,Account.Prohibited__c From Opportunity Where Id in : Trigger.new];
    for (Opportunity opp: opps)
    { if (opp.account.Prohibited__c=='Pakistan') {
        opp.adderror('You cannot create an Opportunity from an Account located in a restricted or Pakistan country');
    }
   
    }
trigger preventDelete on account(before delete){
For(account a : trigger.old){

   If(a.Opportunities != Null)
      a.addError('You cannot delete this');
}
}
But it will also not allowing to delete account with no opportunity.
 
trigger leadrecords on lead(before insert){
list<string> leadEmails = new list<string>();
for(Lead lead:Trigger.new){

leadEmails.add(lead.Email);
}
List<Contact> leads = [SELECT Id, Email FROM  Contact WHERE Email IN :leadEmails];
for (Lead newlead : leads){
if (newlead.email == leadEmails){
system.debug('Contsct is already exist');
}

else {
insert lead.Email;
}
}

 
trigger Conrecords on Account (before insert)
 {
 List<String> name1 = new List<String>();
    for(Account a : trigger.new)
 {
    myname.add(a.name);
    } 
List<contact> contact1=[select id,name from contact where name in : name1];
 delete contact1;
}
 Contact C = [SELECT Account.Name FROM contact where FirstName= 'vikky'];    
 C.Account.Name = 'SFDC';
 update C;
 system.debug (C);
system.debug(C.Account.Name);
List<Account>accts = [SELECT Account.Name,(SELECT Contact.FirstName, Contact.LastName FROM Account.Contacts) FROM Account];
Position__c [] c= [Select Name From Position__c Where Status__c INCLUDES ('New Position;Open - Approved')];

The api name already verified .
Error :- 
Select Name From Position__c Where Status__c INCLUDES ('New Position;Open
                                   ^
ERROR at Row:1:Column:36
includes or excludes operator only valid on multipicklist field
Public virtual class  Parent9 {
    public  void M1(){
   system.debug('hello parent');
    }
}
 Public class Child9 extends Parent9(){
        public override void M1(){
        system.debug('hello child'); 
            }
 }
public class Prime {
    Integer i,num;
    public void entnum(Integer n){
        num = n;
        for (i=2;   i<=num; i++){
            if (system.math.mod(num,i) == 0){
                System.debug('Number is not Prime');
                break;
            }
                if(i == num) {
                  system.debug('Number is  Prime');  
               
                } 
            }
        }
       }
as we know the reords we are going to insert in test class are dummy records and not gonna to insert in our org , but is it required to test on actual  
records while writing test class.
 I am just practice the use of future method and callout but the below code is'nt working 
 
global class MyFutureClass {  
 @future   
   public static void myMethod() {  
     EmailClass.SendEmailNotification();  
       
   }  
 }  

              global class EmailClass{  
              WebService static void SendEmailNotification() {  
               
       SingleEmailMessage mail = new Messaging.SingleEmailMessage();    
         mail.setToAddresses(new string[] {'vikramsinghvs099@gmail.com'});  
        mail.setSenderDisplayName('SFDC.com ');  
          mail.setSubject('A new Hope'');  
          mail.setHtmlBody('GoT It ?');  
     Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail } );  
   }  
 }  
Req :Create the field called “Contact Relationship” checkbox on the Contact Object and create the object called “Contact Relationship” which is related list to the Contacts. (Look Up Relationship).
Now logic is when we create contact by checking contact relationship checkbox, then Contact Relationship will be created automatically for that contact.

Trigger :
trigger CreateChild on Contact (after insert) {
        set<id> conid = new set<id>();
        list<Contact_Relationship__c> con1 = new list<Contact_Relationship__c>();
        for (contact c : trigger.new){
        conid.add(c.id);
}
        List<contact> conlist = [select id,name from contact where id in : conid];
        for (contact c : conlist){
        if(c.Contact_Relationship__c == true){
        Contact_Relationship__c cr = new Contact_Relationship__c();
        cr.name = c.lastname;
        cr.contact__c= c.id;
        con1.add(cr);
}
}
        insert con1;
}
This will work fine but unable to add opp by name 1, 2, 3, 4...

trigger CreateRelatedRec on Account (after insert, after update) {
           List<Opportunity> opplist = new List<Opportunity>();
            List<Account> Acc = [Select ID , Name from Account where Id in : trigger.new AND Id NOT  in
             (select accountid from Opportunity)];
             
            for(account a : Acc){
            
 opplist.add(New Opportunity(Name=a.Name +'opportunity',StageName='Prospecting',
 CloseDate=Date.today()+30,AccountId=a.Id));
        
         }
            If(oppList.Size()>0){
                upsert opplist;
            }
                }
trigger CopyBillingAddtoShpAdd on Account (before insert, before update) {
    for( Account ACC : trigger.new){
    if(Check_Billing_as_Shipping__c == True){
               ACC.BillingStreet          = ACC.ShippingStreet;    
               ACC.BillingCity            = ACC.ShippingCity;  
               ACC.BillingZip/Postal Code = ACC.ShippingZip/Postal Code;    
               ACC.BillingCountry         = ACC.ShippingCountry;    
}
}
}
Here Account custom filed id Probhited__c and code is :
trigger ProhibitedOpp1 on Opportunity (before insert) {
   List<Opportunity> opps = [Select Id,Account.Prohibited__c From Opportunity Where Id in : Trigger.new];
    for (Opportunity opp: opps)
    { if (opp.account.Prohibited__c=='Pakistan') {
        opp.adderror('You cannot create an Opportunity from an Account located in a restricted or Pakistan country');
    }
   
    }
trigger preventDelete on account(before delete){
For(account a : trigger.old){

   If(a.Opportunities != Null)
      a.addError('You cannot delete this');
}
}
But it will also not allowing to delete account with no opportunity.
 
trigger leadrecords on lead(before insert){
list<string> leadEmails = new list<string>();
for(Lead lead:Trigger.new){

leadEmails.add(lead.Email);
}
List<Contact> leads = [SELECT Id, Email FROM  Contact WHERE Email IN :leadEmails];
for (Lead newlead : leads){
if (newlead.email == leadEmails){
system.debug('Contsct is already exist');
}

else {
insert lead.Email;
}
}

 
 Contact C = [SELECT Account.Name FROM contact where FirstName= 'vikky'];    
 C.Account.Name = 'SFDC';
 update C;
 system.debug (C);
system.debug(C.Account.Name);
List<Account>accts = [SELECT Account.Name,(SELECT Contact.FirstName, Contact.LastName FROM Account.Contacts) FROM Account];
Position__c [] c= [Select Name From Position__c Where Status__c INCLUDES ('New Position;Open - Approved')];

The api name already verified .
Error :- 
Select Name From Position__c Where Status__c INCLUDES ('New Position;Open
                                   ^
ERROR at Row:1:Column:36
includes or excludes operator only valid on multipicklist field