• srikanth kambampati 6
  • NEWBIE
  • 20 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 1
    Replies
Hi, i wrote one trigger on account object, when even an account is created automatically create a contact for that account. And my trigger is 
trigger acc_con on Account (after insert) {
    List<Contact> cons = new List<Contact>();
    for(Account a:trigger.new) {
        Contact c =new Contact();
        c.lastName = a.Name;
        c.Phone = a.phone;
        c.AccountId = a.id;
        cons.add(c);
    }
    insert cons;
}
Given I have an Opportunity and there are no open Mandatory sales tasks associated to it When I try and change the opportunity stage
then this shall be allowed by the system. Given I have an Opportunity and there are open Mandatory sales tasks associated to it
When I try and change the opportunity stagetThen the system shall throw a validation error.

trigger Opportunity_Task on Opportunity (before update) {
    List<Task> ts =new List<Task> ();
    List<Opportunity> op =new List<Opportunity>();
    Map<Id,Opportunity> oldMap = trigger.oldMap;
    Map<Id,Opportunity> newMap = trigger.newMap;
    List<id> optyid = new List<id>();
    for(id opid:oldMap.keySet()) {
        Opportunity op =new Opportunity();
        if(oldMap.get(opid).tasks == null && op.stageName=='Closed Won') {
            op.addError('You can create a new task for that Opportunity');
            task t = new task();
            t.WhatId=opid;
            t.Description='kjdkfhsdkf';
            t.Status='open';
            ts.add(t);
        }
        else{
            if(oldMap.get(opid).tasks!=null && op.StageName=='Closed Won')
            op.addError('You cannot modify the opportunity status');
            
        }
    }
    
}
This is my program,
public class Currency_Layer {
    public String result      {set;get;}
    
    public void getCurrency() {
        Http p =new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('callout:Currency_Layer');
        request.setMethod('GET');
        HttpResponse response = p.send(request);
        result = response.getBody();
}
}

and My VF page is
<apex:page controller="Currency_Layer">
    <apex:form >
        <apex:commandButton value="Currency" action="{!getCurrency}"/>
        {!result}
     </apex:form>
</apex:page>

then , how write the test class for above code. please help me,
Hi, i wrote one trigger on account object, when even an account is created automatically create a contact for that account. And my trigger is 
trigger acc_con on Account (after insert) {
    List<Contact> cons = new List<Contact>();
    for(Account a:trigger.new) {
        Contact c =new Contact();
        c.lastName = a.Name;
        c.Phone = a.phone;
        c.AccountId = a.id;
        cons.add(c);
    }
    insert cons;
}